From 51028f34ceeb7c4c91abc2ac2b818afeaa671b91 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Fri, 17 Aug 2001 04:49:12 +0000 Subject: Update. * libio/tst-ungetwc2.c (main): Define str const. * include/wchar.h: Add prototypes for __fwprintf and __vfwprintf. * libio/fwprintf.c: Also define __fwprintf. * stdio-common/vfprintf.c [COMPILE_WPRINTF]: Also define __vfwprintf. * argp/argp-fmtstream.c: Handle wide oriented stderr stream. * assert/assert-perr.c: Likewise. * assert/assert.c: Likewise. * gmon/gmon.c: Likewise. * inet/rcmd.c: Likewise. * malloc/obstack.c: Likewise. * misc/err.c: Likewise. * misc/error.c: Likewise. * misc/getpass.c: Likewise. * posix/getopt.c: Likewise. * resolv/res_hconf.c: Likewise. * stdio-common/perror.c: Likewise. * stdio-common/psignal.c: Likewise. * stdlib/fmtmsg.c: Likewise. * sunrpc/auth_unix.c: Likewise. * sunrpc/clnt_perr.c: Likewise. * sunrpc/clnt_tcp.c: Likewise. * sunrpc/clnt_udp.c: Likewise. * sunrpc/clnt_unix.c: Likewise. * sunrpc/svc_simple.c: Likewise. * sunrpc/svc_tcp.c: Likewise. * sunrpc/svc_udp.c: Likewise. * sunrpc/svc_unix.c: Likewise. * sunrpc/xdr.c: Likewise. * sunrpc/xdr_array.c: Likewise. * sunrpc/xdr_rec.c: Likewise. * sunrpc/xdr_ref.c: Likewise. * sysdeps/generic/wordexp.c: Likewise. * misc/err.c: Handle wide oriented stderr stream. --- argp/argp-fmtstream.c | 60 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 11 deletions(-) (limited to 'argp/argp-fmtstream.c') diff --git a/argp/argp-fmtstream.c b/argp/argp-fmtstream.c index 9c029c265a..fca89a382d 100644 --- a/argp/argp-fmtstream.c +++ b/argp/argp-fmtstream.c @@ -1,5 +1,5 @@ /* Word-wrapping and line-truncating streams - Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc. + Copyright (C) 1997, 1998, 1999, 2001 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Miles Bader . @@ -41,6 +41,7 @@ #endif #if defined _LIBC && defined USE_IN_LIBIO +# include # include # define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a) #endif @@ -58,8 +59,10 @@ argp_fmtstream_t __argp_make_fmtstream (FILE *stream, size_t lmargin, size_t rmargin, ssize_t wmargin) { - argp_fmtstream_t fs = malloc (sizeof (struct argp_fmtstream)); - if (fs) + argp_fmtstream_t fs; + + fs = (struct argp_fmtstream *) malloc (sizeof (struct argp_fmtstream)); + if (fs != NULL) { fs->stream = stream; @@ -69,7 +72,7 @@ __argp_make_fmtstream (FILE *stream, fs->point_col = 0; fs->point_offs = 0; - fs->buf = malloc (INIT_BUF_SIZE); + fs->buf = (char *) malloc (INIT_BUF_SIZE); if (! fs->buf) { free (fs); @@ -94,7 +97,14 @@ __argp_fmtstream_free (argp_fmtstream_t fs) { __argp_fmtstream_update (fs); if (fs->p > fs->buf) - fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); + { +#ifdef USE_IN_LIBIO + if (_IO_fwide (fs->stream, 0) > 0) + fwprintf (fs->stream, L"%.*s", (int) (fs->p - fs->buf), fs->buf); + else +#endif + fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); + } free (fs->buf); free (fs); } @@ -134,7 +144,14 @@ __argp_fmtstream_update (argp_fmtstream_t fs) /* No buffer space for spaces. Must flush. */ size_t i; for (i = 0; i < pad; i++) - putc_unlocked (' ', fs->stream); + { +#ifdef USE_IN_LIBIO + if (_IO_fwide (fs->stream, 0) > 0) + putwc_unlocked (L' ', fs->stream); + else +#endif + putc_unlocked (' ', fs->stream); + } } fs->point_col = pad; } @@ -267,9 +284,17 @@ __argp_fmtstream_update (argp_fmtstream_t fs) else /* Output the first line so we can use the space. */ { - if (nl > fs->buf) - fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream); - putc_unlocked ('\n', fs->stream); +#ifdef USE_IN_LIBIO + if (_IO_fwide (fs->stream, 0) > 0) + fwprintf (fs->stream, L"%.*s\n", + (int) (nl - fs->buf), fs->buf); + else +#endif + { + if (nl > fs->buf) + fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream); + putc_unlocked ('\n', fs->stream); + } len += buf - fs->buf; nl = buf = fs->buf; } @@ -286,7 +311,12 @@ __argp_fmtstream_update (argp_fmtstream_t fs) *nl++ = ' '; else for (i = 0; i < fs->wmargin; ++i) - putc_unlocked (' ', fs->stream); +#ifdef USE_IN_LIBIO + if (_IO_fwide (fs->stream, 0) > 0) + putwc_unlocked (L' ', fs->stream); + else +#endif + putc_unlocked (' ', fs->stream); /* Copy the tail of the original buffer into the current buffer position. */ @@ -323,7 +353,15 @@ __argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount) /* Flush FS's buffer. */ __argp_fmtstream_update (fs); - wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); +#ifdef USE_IN_LIBIO + if (_IO_fwide (fs->stream, 0) > 0) + { + __fwprintf (fs->stream, L"%.*s", (int) (fs->p - fs->buf), fs->buf); + wrote = fs->p - fs->buf; + } + else +#endif + wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); if (wrote == fs->p - fs->buf) { fs->p = fs->buf; -- cgit 1.4.1