tools/nolibc/stdio: add stdin/stdout/stderr and fget*/fput* functions
authorWilly Tarreau <w@1wt.eu>
Mon, 7 Feb 2022 16:23:31 +0000 (17:23 +0100)
committerPaul E. McKenney <paulmck@kernel.org>
Thu, 24 Feb 2022 17:56:45 +0000 (09:56 -0800)
commitf8c7a4c175e6736c4cc99c9b9780c7baf306acca
tree4231ea5df481edb6ba376cc42aa046068e58b699
parent77e4b8b60fd27ea864db1424f5349db7f543e75c
tools/nolibc/stdio: add stdin/stdout/stderr and fget*/fput* functions

The standard puts() function always emits the trailing LF which makes it
unconvenient for small string concatenation. fputs() ought to be used
instead but it requires a FILE*.

This adds 3 dummy FILE* values (stdin, stdout, stderr) which are in fact
pointers to struct FILE of one byte. We reserve 3 pointer values for them,
-3, -2 and -1, so that they are ordered, easing the tests and mapping to
integer.

>From this, fgetc(), fputc(), fgets() and fputs() were implemented, and
the previous putchar() and getchar() now remap to these. The standard
getc() and putc() macros were also implemented as pointing to these
ones.

There is absolutely no buffering, fgetc() and fgets() read one byte at
a time, fputc() writes one byte at a time, and only fputs() which knows
the string's length writes all of it at once.

Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
tools/include/nolibc/stdio.h