Commit Graph

1 Commits

Author SHA1 Message Date
Corinna Vinschen 61ccd3f94f v{fs}printf/v{fs}wprintf: create external output helpers
So far, the printf family of functions has two output helper functions
called __sprint_r and __sfputs_r.  Both are called from all variants of
vfprintf as well as vfwprintf.  There are also analogue helper functions
 for the string-creating functions vsprintf/vswprintf called __ssprint_r
and __ssputs_r.

However, the helpers are built once when building vfprintf/vsprintf with
the INTEGER_ONLY flag, and then they are part of the vfiprintf.c and
vsiprintf.c files.

The problem is this:

Even if a process only calls vfwprintf or the non-INTEGER_ONLY vfprintf
it will always have to include the INTEGER_ONLY vfiprintf. Otherwise the
helper functions are undefined.  Analogue for the string-creating
functions.

That's a useless waste of space by including one (or two) big, unused
function, if newlib is linked in statically.

Create new files to define the printf output helpers separately and
split them into byte-oriented and wide-char-oriented functions.  This
allows to link only the required functions.

Also, simplify the string output helpers and fix a potential (but
unlikely) buffer overflow in __ssprint_r.

Fixes: 8a0efa53e4 ("import newlib-2000-02-17 snapshot")
Fixes: 6121968b19 ("* libc/include/stdio.h (__VALIST): Guard against multiple definition.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-17 13:10:20 +01:00