diff options
Diffstat (limited to 'stdio-common')
-rw-r--r-- | stdio-common/Makefile | 2 | ||||
-rw-r--r-- | stdio-common/fxprintf.c | 54 | ||||
-rw-r--r-- | stdio-common/perror.c | 7 | ||||
-rw-r--r-- | stdio-common/psignal.c | 21 |
4 files changed, 61 insertions, 23 deletions
diff --git a/stdio-common/Makefile b/stdio-common/Makefile index 2e797e4dfe..d860d75dee 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -40,7 +40,7 @@ install-others = $(inst_includedir)/bits/stdio_lim.h include ../Makeconfig -aux := errlist siglist printf-parsemb printf-parsewc +aux := errlist siglist printf-parsemb printf-parsewc fxprintf distribute := _itoa.h _itowa.h _i18n_number.h \ printf-parse.h stdio_lim.h.in tst-unbputc.sh tst-printf.sh diff --git a/stdio-common/fxprintf.c b/stdio-common/fxprintf.c new file mode 100644 index 0000000000..298e5f22b0 --- /dev/null +++ b/stdio-common/fxprintf.c @@ -0,0 +1,54 @@ +/* Copyright (C) 2005 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@gnu.org>. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <assert.h> +#include <ctype.h> +#include <stdarg.h> +#include <stdio.h> +#include <wchar.h> + + +int +__fxprintf (FILE *fp, const char *fmt, ...) +{ + if (fp == NULL) + fp = stderr; + + va_list ap; + va_start (ap, fmt); + + int res; + if (_IO_fwide (fp, 0) > 0) + { + size_t len = strlen (fmt) + 1, i; + wchar_t wfmt[len]; + for (i = 0; i < len; ++i) + { + assert (isascii (fmt[i])); + wfmt[i] = fmt[i]; + } + res = __vfwprintf (fp, wfmt, ap); + } + else + res = _IO_vfprintf (fp, fmt, ap); + + va_end (ap); + + return res; +} diff --git a/stdio-common/perror.c b/stdio-common/perror.c index f0751375b5..3ee61520f4 100644 --- a/stdio-common/perror.c +++ b/stdio-common/perror.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-1993,1997,1998,2000-2004 Free Software Foundation, Inc. +/* Copyright (C) 1991-1993,1997,1998,2000-2005 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -37,10 +37,7 @@ perror_internal (FILE *fp, const char *s, int errnum) errstring = __strerror_r (errnum, buf, sizeof buf); - if (_IO_fwide (fp, 0) > 0) - (void) __fwprintf (fp, L"%s%s%s\n", s, colon, errstring); - else - (void) fprintf (fp, "%s%s%s\n", s, colon, errstring); + (void) __fxprintf (fp, "%s%s%s\n", s, colon, errstring); } diff --git a/stdio-common/psignal.c b/stdio-common/psignal.c index 2e6588c692..be95095350 100644 --- a/stdio-common/psignal.c +++ b/stdio-common/psignal.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1992, 1995, 1996, 1997, 2001, 2002, 2004 +/* Copyright (C) 1991, 1992, 1995, 1996, 1997, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -47,29 +47,16 @@ psignal (int sig, const char *s) colon = ": "; if (sig >= 0 && sig < NSIG && (desc = INTUSE(_sys_siglist)[sig]) != NULL) - { - if (_IO_fwide (stderr, 0) > 0) - (void) __fwprintf (stderr, L"%s%s%s\n", s, colon, _(desc)); - else - (void) fprintf (stderr, "%s%s%s\n", s, colon, _(desc)); - } + (void) __fxprintf (NULL, "%s%s%s\n", s, colon, _(desc)); else { char *buf; if (__asprintf (&buf, _("%s%sUnknown signal %d\n"), s, colon, sig) < 0) - { - if (_IO_fwide (stderr, 0) > 0) - (void) __fwprintf (stderr, L"%s%s%s\n", s, colon, _("Unknown signal")); - else - (void) fprintf (stderr, "%s%s%s\n", s, colon, _("Unknown signal")); - } + (void) __fxprintf (NULL, "%s%s%s\n", s, colon, _("Unknown signal")); else { - if (_IO_fwide (stderr, 0) > 0) - (void) __fwprintf (stderr, L"%s", buf); - else - (void) fputs (buf, stderr); + (void) __fxprintf (NULL, "%s", buf); free (buf); } |