• Willy Tarreau's avatar
    tools/nolibc/stdio: add stdin/stdout/stderr and fget*/fput* functions · 99b037cb
    Willy Tarreau authored
    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: default avatarWilly Tarreau <w@1wt.eu>
    Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
    99b037cb
stdio.h 2.29 KB