mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #18186 from maribu/sys/fmt
sys/fmt: fix output on native
This commit is contained in:
commit
593b5d376d
@ -508,22 +508,16 @@ uint32_t scn_u32_hex(const char *str, size_t n)
|
||||
|
||||
void print(const char *s, size_t n)
|
||||
{
|
||||
if (IS_USED(MODULE_STDIO_NATIVE)) {
|
||||
/* native gets special treatment as native's stdio code is ...
|
||||
* special */
|
||||
printf("%.*s", (int)n, s);
|
||||
return;
|
||||
}
|
||||
|
||||
while (n > 0) {
|
||||
ssize_t written;
|
||||
if (IS_USED(MODULE_STDIO_NATIVE)) {
|
||||
/* for native fwrite is not wrapped and would use the system's
|
||||
* write directly, resulting in corrupted output. Instead, use the
|
||||
* stdio_write wrapper directly here to force all output from
|
||||
* puts() / printf() and fmt to be handled the same. */
|
||||
extern ssize_t stdio_write(const void* buffer, size_t len);
|
||||
written = stdio_write(s, n);
|
||||
}
|
||||
else {
|
||||
/* For all but native: Use fwrite rather than the cheaper unbuffered
|
||||
* write() to avoid corrupted output when mixing stdio and fmt
|
||||
* for C libs that use buffered output */
|
||||
written = fwrite(s, 1, n, stdout);
|
||||
}
|
||||
written = fwrite(s, 1, n, stdout);
|
||||
if (written < 0) {
|
||||
break;
|
||||
}
|
||||
|
@ -176,10 +176,9 @@ void ipv6_addrs_print(const ipv6_addr_t *addrs, size_t num,
|
||||
ipv6_addr_to_str(buf, &addrs[num], sizeof(buf));
|
||||
if (IS_USED(MODULE_FMT)) {
|
||||
print_str(buf);
|
||||
print_str(separator);
|
||||
}
|
||||
else {
|
||||
printf("%s%s", buf, separator);
|
||||
printf("%s", buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,11 @@ int main(void)
|
||||
print_str("\n");
|
||||
print_float(1.2345, 5);
|
||||
print_str("\n");
|
||||
printf("%s", "Test ");
|
||||
/* test mixing of printf() and fmt's print() works fine */
|
||||
printf("%s", "Test");
|
||||
/* test fmt's print indeed only honors the length parameter and doesn't
|
||||
* print until the terminated zero byte */
|
||||
print(" not ", 1);
|
||||
print_str("successful.");
|
||||
puts("");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user