From 082e680bd54e999f2bb4eb77141958938b1e9ee9 Mon Sep 17 00:00:00 2001 From: Manuel Novoa III Date: Wed, 11 Feb 2004 23:48:50 +0000 Subject: New stdio core. Should be more maintainable. Fixes a couple of bugs. Codepaths streamlined. Improved performance for nonthreaded apps when linked with a thread-enabled libc. Minor iconv bug and some locale/thread related startup issues fixed. These showed up in getting a gcj-compiled java helloworld app running. Removed some old extension functions... _stdio_fdout and _stdio_fsfopen. --- libc/stdio/old_vfprintf.c | 54 +++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 21 deletions(-) (limited to 'libc/stdio/old_vfprintf.c') diff --git a/libc/stdio/old_vfprintf.c b/libc/stdio/old_vfprintf.c index 5afbefb07..1b7af96f9 100644 --- a/libc/stdio/old_vfprintf.c +++ b/libc/stdio/old_vfprintf.c @@ -129,21 +129,22 @@ #define _ISOC99_SOURCE /* for ULLONG primarily... */ #define _GNU_SOURCE /* for strnlen */ -#define _STDIO_UTILITY -#include +#include "_stdio.h" +/* #include */ #include #include #include #include #include #include +#include #define __PRINTF_INFO_NO_BITFIELD #include -#ifdef __STDIO_THREADSAFE +#ifdef __UCLIBC_HAS_THREADS__ #include -#endif /* __STDIO_THREADSAFE */ +#endif /* __UCLIBC_HAS_THREADS__ */ /* #undef __UCLIBC_HAS_FLOATS__ */ /* #undef WANT_FLOAT_ERROR */ @@ -151,7 +152,7 @@ /* #define __isdigit(c) (((unsigned int)(c - '0')) < 10) */ -#ifdef __STDIO_PRINTF_M_SUPPORT +#ifdef __UCLIBC_HAS_PRINTF_M_SPEC__ #define WANT_GNU_ERRNO 1 #else #define WANT_GNU_ERRNO 0 @@ -165,7 +166,7 @@ #define PUTC(C,F) putc_unlocked((C),(F)) #define OUTNSTR _outnstr -#define _outnstr(stream, string, len) _stdio_fwrite(string, len, stream) +#define _outnstr(stream, string, len) __stdio_fwrite(string, len, stream) #else /* __STDIO_BUFFERS */ @@ -180,24 +181,22 @@ static void _outnstr(FILE *stream, const unsigned char *s, size_t n) { __FILE_vsnprintf *f = (__FILE_vsnprintf *) stream; - if (f->f.filedes != -2) { - _stdio_fwrite(s, n, &f->f); - } else { - if (f->bufend > f->bufpos) { - size_t r = f->bufend - f->bufpos; - if (r > n) { - r = n; - } - memcpy(f->bufpos, s, r); - f->bufpos += r; + if (!__STDIO_STREAM_IS_FAKE_VSNPRINTF_NB(&f->f)) { + __stdio_fwrite(s, n, &f->f); + } else if (f->bufend > f->bufpos) { + size_t r = f->bufend - f->bufpos; + if (r > n) { + r = n; } + memcpy(f->bufpos, s, r); + f->bufpos += r; } } #endif static void putc_unlocked_sprintf(int c, __FILE_vsnprintf *f) { - if (f->f.filedes != -2) { + if (!__STDIO_STREAM_IS_FAKE_VSNPRINTF_NB(&f->f)) { putc_unlocked(c, &f->f); } else if (f->bufpos < f->bufend) { *f->bufpos++ = c; @@ -241,7 +240,9 @@ static void _fp_out_narrow(FILE *fp, intptr_t type, intptr_t len, intptr_t buf) } len = buflen; } - OUTNSTR(fp, (const char *) buf, len); + if (len) { + OUTNSTR(fp, (const char *) buf, len); + } } #endif @@ -359,11 +360,18 @@ int vfprintf(FILE * __restrict op, register const char * __restrict fmt, int radix, dpoint /*, upcase*/; char tmp[65]; /* TODO - determing needed size from headers */ char flag[sizeof(spec)]; + __STDIO_AUTO_THREADLOCK_VAR; - __STDIO_THREADLOCK(op); + __STDIO_AUTO_THREADLOCK(op); + + __STDIO_STREAM_VALIDATE(op); cnt = 0; + if (__STDIO_STREAM_IS_NARROW_WRITING(op) + || !__STDIO_STREAM_TRANS_TO_WRITE(op, __FLAG_NARROW) + ) { + while (*fmt) { if (*fmt == '%') { fmt0 = fmt; /* save our position in case of bad format */ @@ -691,9 +699,13 @@ int vfprintf(FILE * __restrict op, register const char * __restrict fmt, ++fmt; } - i = (__FERROR(op)) ? -1 : cnt; + } + + i = (__FERROR_UNLOCKED(op)) ? -1 : cnt; + + __STDIO_STREAM_VALIDATE(op); - __STDIO_THREADUNLOCK(op); + __STDIO_AUTO_THREADUNLOCK(op); return i; } -- cgit v1.2.3