|
@@ -1198,7 +1198,7 @@ int register_printf_function(int spec, printf_function handler,
|
|
|
|
|
|
#endif
|
|
|
|
|
|
-#if defined(L_vfprintf) || defined(L_vfwprintf)
|
|
|
+#if defined(L__vfprintf_internal) || defined(L__vfwprintf_internal)
|
|
|
|
|
|
|
|
|
* precision and width settings in *printf (wide) format strings.
|
|
@@ -1207,14 +1207,15 @@ int register_printf_function(int spec, printf_function handler,
|
|
|
|
|
|
static size_t _charpad(FILE * __restrict stream, int padchar, size_t numpad);
|
|
|
|
|
|
-#ifdef L_vfprintf
|
|
|
+#ifdef L__vfprintf_internal
|
|
|
|
|
|
-#define VFPRINTF vfprintf
|
|
|
+#define VFPRINTF_internal _vfprintf_internal
|
|
|
#define FMT_TYPE char
|
|
|
#define OUTNSTR _outnstr
|
|
|
#define STRLEN strlen
|
|
|
#define _PPFS_init _ppfs_init
|
|
|
-#define OUTPUT(F,S) fputs_unlocked(S,F)
|
|
|
+
|
|
|
+#define OUTPUT(F,S) __stdio_fwrite((const unsigned char *)(S),strlen(S),(F))
|
|
|
|
|
|
#define _outnstr(stream, string, len) ((len > 0) ? __stdio_fwrite(string, len, stream) : 0)
|
|
|
#define FP_OUT _fp_out_narrow
|
|
@@ -1239,14 +1240,16 @@ static size_t _fp_out_narrow(FILE *fp, intptr_t type, intptr_t len, intptr_t buf
|
|
|
|
|
|
#endif
|
|
|
|
|
|
-#else
|
|
|
+#else
|
|
|
|
|
|
-#define VFPRINTF vfwprintf
|
|
|
+#define VFPRINTF_internal _vfwprintf_internal
|
|
|
#define FMT_TYPE wchar_t
|
|
|
#define OUTNSTR _outnwcs
|
|
|
#define STRLEN wcslen
|
|
|
#define _PPFS_init _ppwfs_init
|
|
|
+
|
|
|
#define OUTPUT(F,S) fputws(S,F)
|
|
|
+
|
|
|
#define _outnwcs(stream, wstring, len) _wstdio_fwrite(wstring, len, stream)
|
|
|
#define FP_OUT _fp_out_wide
|
|
|
|
|
@@ -1417,7 +1420,8 @@ static int _ppwfs_init(register ppfs_t *ppfs, const wchar_t *fmt0)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-#endif
|
|
|
+#endif
|
|
|
+
|
|
|
|
|
|
static size_t _charpad(FILE * __restrict stream, int padchar, size_t numpad)
|
|
|
{
|
|
@@ -1439,12 +1443,12 @@ static int _do_one_spec(FILE * __restrict stream,
|
|
|
register ppfs_t *ppfs, int *count)
|
|
|
{
|
|
|
static const char spec_base[] = SPEC_BASE;
|
|
|
-#ifdef L_vfprintf
|
|
|
+#ifdef L__vfprintf_internal
|
|
|
static const char prefix[] = "+\0-\0 \0000x\0000X";
|
|
|
|
|
|
-#else
|
|
|
+#else
|
|
|
static const wchar_t prefix[] = L"+\0-\0 \0000x\0000X";
|
|
|
-#endif
|
|
|
+#endif
|
|
|
enum {
|
|
|
PREFIX_PLUS = 0,
|
|
|
PREFIX_MINUS = 2,
|
|
@@ -1465,7 +1469,7 @@ static int _do_one_spec(FILE * __restrict stream,
|
|
|
mbstate_t mbstate;
|
|
|
#endif
|
|
|
size_t slen;
|
|
|
-#ifdef L_vfprintf
|
|
|
+#ifdef L__vfprintf_internal
|
|
|
#define SLEN slen
|
|
|
#else
|
|
|
size_t SLEN;
|
|
@@ -1532,7 +1536,7 @@ static int _do_one_spec(FILE * __restrict stream,
|
|
|
alphacase = __UIM_LOWER;
|
|
|
|
|
|
#ifdef __UCLIBC_MJN3_ONLY__
|
|
|
-#ifdef L_vfprintf
|
|
|
+#ifdef L__vfprintf_internal
|
|
|
#warning CONSIDER: Should we ignore these flags if stub locale? What about custom specs?
|
|
|
#endif
|
|
|
#endif
|
|
@@ -1560,7 +1564,7 @@ static int _do_one_spec(FILE * __restrict stream,
|
|
|
padchar = ppfs->info.pad;
|
|
|
}
|
|
|
#ifdef __UCLIBC_MJN3_ONLY__
|
|
|
-#ifdef L_vfprintf
|
|
|
+#ifdef L__vfprintf_internal
|
|
|
#warning CONSIDER: If using outdigits and/or grouping, how should we interpret precision?
|
|
|
#endif
|
|
|
#endif
|
|
@@ -1580,7 +1584,7 @@ static int _do_one_spec(FILE * __restrict stream,
|
|
|
}
|
|
|
}
|
|
|
slen = (char *)(buf + sizeof(buf) - 1) - s;
|
|
|
-#ifdef L_vfwprintf
|
|
|
+#ifdef L__vfwprintf_internal
|
|
|
{
|
|
|
const char *q = s;
|
|
|
mbstate.__mask = 0;
|
|
@@ -1605,13 +1609,13 @@ static int _do_one_spec(FILE * __restrict stream,
|
|
|
}
|
|
|
if (ppfs->conv_num == CONV_p) {
|
|
|
s = "(nil)";
|
|
|
-#ifdef L_vfwprintf
|
|
|
+#ifdef L__vfwprintf_internal
|
|
|
SLEN =
|
|
|
#endif
|
|
|
slen = 5;
|
|
|
numfill = 0;
|
|
|
} else if (numfill == 0) {
|
|
|
-#ifdef L_vfwprintf
|
|
|
+#ifdef L__vfwprintf_internal
|
|
|
SLEN =
|
|
|
#endif
|
|
|
slen = 0;
|
|
@@ -1637,7 +1641,7 @@ static int _do_one_spec(FILE * __restrict stream,
|
|
|
return -1;
|
|
|
#endif
|
|
|
} else if (ppfs->conv_num <= CONV_S) {
|
|
|
-#ifdef L_vfprintf
|
|
|
+#ifdef L__vfprintf_internal
|
|
|
|
|
|
#ifdef __UCLIBC_HAS_WCHAR__
|
|
|
mbstate.__mask = 0;
|
|
@@ -1692,7 +1696,7 @@ static int _do_one_spec(FILE * __restrict stream,
|
|
|
slen = 1;
|
|
|
}
|
|
|
|
|
|
-#else
|
|
|
+#else
|
|
|
|
|
|
if (ppfs->conv_num == CONV_S) {
|
|
|
ws = *((wchar_t **) (*argptr));
|
|
@@ -1713,7 +1717,7 @@ static int _do_one_spec(FILE * __restrict stream,
|
|
|
|
|
|
if (ppfs->conv_num == CONV_s) {
|
|
|
#ifdef __UCLIBC_MJN3_ONLY__
|
|
|
-#warning TODO: Fix %s for vfwprintf... output upto illegal sequence?
|
|
|
+#warning TODO: Fix %s for _vfwprintf_internal... output upto illegal sequence?
|
|
|
#endif
|
|
|
s = *((char **) (*argptr));
|
|
|
if (s) {
|
|
@@ -1746,7 +1750,7 @@ static int _do_one_spec(FILE * __restrict stream,
|
|
|
goto CHAR_CASE;
|
|
|
}
|
|
|
|
|
|
-#endif
|
|
|
+#endif
|
|
|
|
|
|
#ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
|
|
|
} else if (ppfs->conv_num == CONV_m) {
|
|
@@ -1778,7 +1782,7 @@ static int _do_one_spec(FILE * __restrict stream,
|
|
|
}
|
|
|
|
|
|
#ifdef __UCLIBC_MJN3_ONLY__
|
|
|
-#ifdef L_vfprintf
|
|
|
+#ifdef L__vfprintf_internal
|
|
|
#warning CONSIDER: If using outdigits and/or grouping, how should we pad?
|
|
|
#endif
|
|
|
#endif
|
|
@@ -1805,11 +1809,12 @@ static int _do_one_spec(FILE * __restrict stream,
|
|
|
numpad = 0;
|
|
|
}
|
|
|
OUTPUT(stream, prefix + prefix_num);
|
|
|
+
|
|
|
if (_charpad(stream, '0', numfill) != numfill) {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-#ifdef L_vfprintf
|
|
|
+#ifdef L__vfprintf_internal
|
|
|
|
|
|
#ifdef __UCLIBC_HAS_WCHAR__
|
|
|
if (!ws) {
|
|
@@ -1836,7 +1841,7 @@ static int _do_one_spec(FILE * __restrict stream,
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
-#else
|
|
|
+#else
|
|
|
|
|
|
if (!ws) {
|
|
|
assert(s);
|
|
@@ -1849,7 +1854,7 @@ static int _do_one_spec(FILE * __restrict stream,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-#endif
|
|
|
+#endif
|
|
|
if (_charpad(stream, ' ', numpad) != numpad) {
|
|
|
return -1;
|
|
|
}
|
|
@@ -1860,35 +1865,21 @@ static int _do_one_spec(FILE * __restrict stream,
|
|
|
|
|
|
libc_hidden_proto(fprintf)
|
|
|
|
|
|
-libc_hidden_proto(VFPRINTF)
|
|
|
-int VFPRINTF (FILE * __restrict stream,
|
|
|
+int VFPRINTF_internal (FILE * __restrict stream,
|
|
|
register const FMT_TYPE * __restrict format,
|
|
|
va_list arg)
|
|
|
{
|
|
|
ppfs_t ppfs;
|
|
|
int count, r;
|
|
|
register const FMT_TYPE *s;
|
|
|
- __STDIO_AUTO_THREADLOCK_VAR;
|
|
|
-
|
|
|
- __STDIO_AUTO_THREADLOCK(stream);
|
|
|
|
|
|
count = 0;
|
|
|
s = format;
|
|
|
|
|
|
- if
|
|
|
-#ifdef L_vfprintf
|
|
|
- (!__STDIO_STREAM_IS_NARROW_WRITING(stream)
|
|
|
- && __STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_NARROW))
|
|
|
-#else
|
|
|
- (!__STDIO_STREAM_IS_WIDE_WRITING(stream)
|
|
|
- && __STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_WIDE))
|
|
|
-#endif
|
|
|
- {
|
|
|
- count = -1;
|
|
|
- } else if (_PPFS_init(&ppfs, format) < 0) {
|
|
|
+ if (_PPFS_init(&ppfs, format) < 0) {
|
|
|
OUTNSTR(stream, (const unsigned char *) ppfs.fmtpos,
|
|
|
STRLEN((const FMT_TYPE *)(ppfs.fmtpos)));
|
|
|
-#if defined(L_vfprintf) && !defined(NDEBUG)
|
|
|
+#if defined(L__vfprintf_internal) && !defined(NDEBUG)
|
|
|
fprintf(stderr,"\nIMbS: \"%s\"\n\n", format);
|
|
|
#endif
|
|
|
count = -1;
|
|
@@ -1930,14 +1921,66 @@ int VFPRINTF (FILE * __restrict stream,
|
|
|
va_end(ppfs.arg);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
+ return count;
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+#if defined(L_vfprintf) || defined(L_vfwprintf)
|
|
|
+
|
|
|
+
|
|
|
+ * Factoring out vfprintf internals allows:
|
|
|
+ * (1) vdprintf and vsnprintf don't need to setup fake locking,
|
|
|
+ * (2) __STDIO_STREAM_TRANS_TO_WRITE is not used in vfprintf internals,
|
|
|
+ * and thus fseek etc is not pulled in by vdprintf and vsnprintf.
|
|
|
+ *
|
|
|
+ * In order to not pull in fseek through fputs, OUTPUT() macro
|
|
|
+ * is using __stdio_fwrite (TODO: do the same for wide functions).
|
|
|
+ */
|
|
|
+#ifdef L_vfprintf
|
|
|
+#define VFPRINTF vfprintf
|
|
|
+#define VFPRINTF_internal _vfprintf_internal
|
|
|
+#define FMT_TYPE char
|
|
|
+#else
|
|
|
+#define VFPRINTF vfwprintf
|
|
|
+#define VFPRINTF_internal _vfwprintf_internal
|
|
|
+#define FMT_TYPE wchar_t
|
|
|
+#endif
|
|
|
+
|
|
|
+libc_hidden_proto(VFPRINTF)
|
|
|
+int VFPRINTF (FILE * __restrict stream,
|
|
|
+ register const FMT_TYPE * __restrict format,
|
|
|
+ va_list arg)
|
|
|
+{
|
|
|
+ int count;
|
|
|
+ __STDIO_AUTO_THREADLOCK_VAR;
|
|
|
+
|
|
|
+ __STDIO_AUTO_THREADLOCK(stream);
|
|
|
+
|
|
|
+ if
|
|
|
+#ifdef L_vfprintf
|
|
|
+ (!__STDIO_STREAM_IS_NARROW_WRITING(stream)
|
|
|
+ && __STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_NARROW))
|
|
|
+#else
|
|
|
+ (!__STDIO_STREAM_IS_WIDE_WRITING(stream)
|
|
|
+ && __STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_WIDE))
|
|
|
+#endif
|
|
|
+ {
|
|
|
+ count = -1;
|
|
|
+ } else {
|
|
|
+ count = VFPRINTF_internal(stream, format, arg);
|
|
|
+ }
|
|
|
+
|
|
|
__STDIO_AUTO_THREADUNLOCK(stream);
|
|
|
|
|
|
return count;
|
|
|
}
|
|
|
libc_hidden_def(VFPRINTF)
|
|
|
-#endif
|
|
|
+#endif
|
|
|
+
|
|
|
|