Skip to content

Commit

Permalink
sys/fmt: print(): use fflush(); stdio_write() vs. fwrite()
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Feb 7, 2023
1 parent f341ad6 commit 0a0d3b6
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions sys/fmt/fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "kernel_defines.h"
#include "fmt.h"
#include "stdio_base.h"

static const char _hex_chars[16] = "0123456789ABCDEF";

Expand Down Expand Up @@ -506,25 +507,22 @@ uint32_t scn_u32_hex(const char *str, size_t n)
return res;
}

/* native gets special treatment as native's stdio code is ...
* special */
#if IS_USED(MODULE_STDIO_NATIVE) || !defined(RIOT_VERSION)
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;
}
printf("%.*s", (int)n, s);
}
#else
void print(const char *s, size_t n)
{
/* flush the libc's output buffer so output is not intermangled. */
fflush(stdout);

while (n > 0) {
ssize_t written;
written = fwrite(s, 1, n, stdout);
if (written < 0) {
break;
}
n -= written;
s += written;
}
stdio_write(s, n);
}
#endif

void print_u32_dec(uint32_t val)
{
Expand Down

0 comments on commit 0a0d3b6

Please sign in to comment.