summaryrefslogtreecommitdiff
path: root/libc/stdio/old_vfprintf.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2004-02-11 23:48:50 +0000
committerManuel Novoa III <mjn3@codepoet.org>2004-02-11 23:48:50 +0000
commit082e680bd54e999f2bb4eb77141958938b1e9ee9 (patch)
tree203c45b85ca608e1550d8ffc459456fc9cf0b30b /libc/stdio/old_vfprintf.c
parent17c21765b4a97c6f0b74ba8466073e5a3f97cdee (diff)
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.
Diffstat (limited to 'libc/stdio/old_vfprintf.c')
-rw-r--r--libc/stdio/old_vfprintf.c54
1 files changed, 33 insertions, 21 deletions
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 <stdio.h>
+#include "_stdio.h"
+/* #include <stdio.h> */
#include <stdarg.h>
#include <limits.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
+#include <bits/uClibc_uintmaxtostr.h>
#define __PRINTF_INFO_NO_BITFIELD
#include <printf.h>
-#ifdef __STDIO_THREADSAFE
+#ifdef __UCLIBC_HAS_THREADS__
#include <pthread.h>
-#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;
}