diff options
author | Elliott Hughes <enh@google.com> | 2017-11-07 22:52:29 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2017-11-07 22:52:29 -0800 |
commit | 93a1f8b1f5278a9245ab020ea7fc4ddc3b1d7c97 (patch) | |
tree | 16080b44df38c5bd8f9f06c47ccb02ce8fc1b2c3 /libc/stdio/vfprintf.cpp | |
parent | 3404bb11a36ee99a0fb2bcd7cfff3cbe0fe5da49 (diff) |
More printf de-duplication.
Just trivial use of macros.
The %s/%ls case in __find_arguments was backwards in the wide copy of
the code, but not problematically so because all pointers are the same
size anyway.
Bug: http://b/67371539
Test: ran tests
Change-Id: I8d34915d75ae5425c56c59510a16c328fc481d20
Diffstat (limited to 'libc/stdio/vfprintf.cpp')
-rw-r--r-- | libc/stdio/vfprintf.cpp | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/libc/stdio/vfprintf.cpp b/libc/stdio/vfprintf.cpp index 366b196e8..fe2e338e7 100644 --- a/libc/stdio/vfprintf.cpp +++ b/libc/stdio/vfprintf.cpp @@ -32,6 +32,7 @@ */ #define CHAR_TYPE char +#define FUNCTION_NAME __vfprintf #include <sys/mman.h> #include <sys/types.h> @@ -108,8 +109,7 @@ static int __sprint(FILE* fp, struct __suio* uio) { * temporary buffer. We only work on write-only files; this avoids * worries about ungetc buffers and so forth. */ -static int __sbprintf(FILE* fp, const char* fmt, va_list ap) { - int ret; +static int __sbprintf(FILE* fp, const CHAR_TYPE* fmt, va_list ap) { FILE fake; struct __sfileext fakeext; unsigned char buf[BUFSIZ]; @@ -127,7 +127,7 @@ static int __sbprintf(FILE* fp, const char* fmt, va_list ap) { fake._lbfsize = 0; /* not actually used, but Just In Case */ /* do the work, then copy any error status */ - ret = __vfprintf(&fake, fmt, ap); + int ret = FUNCTION_NAME(&fake, fmt, ap); if (ret >= 0 && __sflush(&fake)) ret = EOF; if (fake._flags & __SERR) fp->_flags |= __SERR; return (ret); @@ -250,17 +250,16 @@ static int exponent(CharT* p0, int exp, int fmtch) { #define CHARINT 0x0800 /* 8 bit integer */ #define MAXINT 0x1000 /* largest integer size (intmax_t) */ -int __vfprintf(FILE* fp, const char* fmt0, __va_list ap) { +int FUNCTION_NAME(FILE* fp, const CHAR_TYPE* fmt0, __va_list ap) { int ch; /* character from fmt */ int n, n2; /* handy integers (short term usage) */ - char* cp; /* handy char pointer (short term usage) */ + CHAR_TYPE* cp; /* handy char pointer (short term usage) */ struct __siov* iovp; /* for PRINT macro */ + CHAR_TYPE sign; /* sign prefix (' ', '+', '-', or \0) */ int flags; /* flags as above */ int ret; /* return value accumulator */ int width; /* width from format (%8d), or 0 */ int prec; /* precision from format; <0 for N/A */ - char sign; /* sign prefix (' ', '+', '-', or \0) */ - mbstate_t ps; /* * We can decompose the printed representation of floating * point numbers into several parts, some of which may be empty: @@ -287,7 +286,7 @@ int __vfprintf(FILE* fp, const char* fmt0, __va_list ap) { int expsize; /* character count for expstr */ int lead; /* sig figs before decimal or group sep */ int ndig; /* actual number of digits returned by dtoa */ - char expstr[MAXEXPDIG + 2]; /* buffer for exponent string: e+ZZZ */ + CHAR_TYPE expstr[MAXEXPDIG + 2]; /* buffer for exponent string: e+ZZZ */ char* dtoaresult = NULL; uintmax_t _umax; /* integer arguments %[diouxX] */ @@ -299,14 +298,14 @@ int __vfprintf(FILE* fp, const char* fmt0, __va_list ap) { #define NIOV 8 struct __suio uio; /* output information: summary */ struct __siov iov[NIOV]; /* ... and individual io vectors */ - char buf[BUF]; /* buffer with space for digits of uintmax_t */ - char ox[2]; /* space for 0x; ox[1] is either x, X, or \0 */ + CHAR_TYPE buf[BUF]; /* buffer with space for digits of uintmax_t */ + CHAR_TYPE ox[2]; /* space for 0x; ox[1] is either x, X, or \0 */ union arg* argtable; /* args, built due to positional arg */ union arg statargtable[STATIC_ARG_TBL_SIZE]; size_t argtablesiz; int nextarg; /* 1-based argument index */ va_list orgap; /* original argument pointer */ - char* convbuf; /* buffer for wide to multi-byte conversion */ + CHAR_TYPE* convbuf; /* buffer for wide/multibyte conversion */ /* * Choose PADSIZE to trade efficiency vs. size. If larger printf @@ -466,7 +465,6 @@ int __vfprintf(FILE* fp, const char* fmt0, __va_list ap) { ret = 0; convbuf = NULL; - memset(&ps, 0, sizeof(ps)); /* * Scan the format for conversions (`%' character). */ @@ -1275,10 +1273,7 @@ static int __find_arguments(const CHAR_TYPE* fmt0, va_list ap, union arg** argta flags |= LONGINT; /*FALLTHROUGH*/ case 's': - if (flags & LONGINT) - ADDTYPE(TP_WCHAR); - else - ADDTYPE(TP_CHAR); + ADDTYPE((flags & LONGINT) ? TP_WCHAR : TP_CHAR); break; case 'U': flags |= LONGINT; |