1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/fmt: fix print() for native

This commit is contained in:
Marian Buschsieweke 2022-06-09 15:14:22 +02:00
parent 8e1f908760
commit 4f9e35254a
No known key found for this signature in database
GPG Key ID: CB8E3238CE715A94

View File

@ -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;
}