diff options
| author | Ulrich Drepper <drepper@redhat.com> | 2005-07-20 07:43:27 +0000 |
|---|---|---|
| committer | Ulrich Drepper <drepper@redhat.com> | 2005-07-20 07:43:27 +0000 |
| commit | df6f89692fd7e802f38f944ed73942354a9911f8 (patch) | |
| tree | 12debd445b11886fcf433fc6f85e9abe615670cc | |
| parent | 10ffcd52f0578b13b48bdf84e73759353b29b673 (diff) | |
| download | glibc-df6f89692fd7e802f38f944ed73942354a9911f8.tar.xz glibc-df6f89692fd7e802f38f944ed73942354a9911f8.zip | |
* wcsmbs/bits/wchar2.h: Add definitions for wcrtomb, mbsrtowcs,
wcsrtombs, mbsnrtowcs, and wcsnrtombs.
* debug/Makefile (routines): Add wcrtomb_chk, mbsrtowcs_chk,
wcsrtombs_chk, mbsnrtowcs_chk, and wcsnrtombs_chk.
* debug/Versions: Add __wcrtomb_chk, __mbsrtowcs_chk,
__wcsrtombs_chk, __mbsnrtowcs_chk, and __wcsnrtombs_chk.
* debug/tst-chk1.c: Add tests for new functions.
* debug/mbsnrtowcs_chk.c: New file.
* debug/mbsrtowcs_chk.c: New file.
* debug/wcrtomb_chk.c: New file.
* debug/wcsnrtombs_chk.c: New file.
* debug/wcsrtombs_chk.c: New file.
* include/stdio.h: Add declaration for __fxprintf.
37 files changed, 581 insertions, 508 deletions
@@ -1,8 +1,23 @@ +2005-07-20 Ulrich Drepper <drepper@redhat.com> + + * wcsmbs/bits/wchar2.h: Add definitions for wcrtomb, mbsrtowcs, + wcsrtombs, mbsnrtowcs, and wcsnrtombs. + * debug/Makefile (routines): Add wcrtomb_chk, mbsrtowcs_chk, + wcsrtombs_chk, mbsnrtowcs_chk, and wcsnrtombs_chk. + * debug/Versions: Add __wcrtomb_chk, __mbsrtowcs_chk, + __wcsrtombs_chk, __mbsnrtowcs_chk, and __wcsnrtombs_chk. + * debug/tst-chk1.c: Add tests for new functions. + * debug/mbsnrtowcs_chk.c: New file. + * debug/mbsrtowcs_chk.c: New file. + * debug/wcrtomb_chk.c: New file. + * debug/wcsnrtombs_chk.c: New file. + * debug/wcsrtombs_chk.c: New file. + 2005-07-19 Ulrich Drepper <drepper@redhat.com> * stdio-common/Makefile (aux): Add fxprintf. * stdio-common/fxprintf.c: New file. - * include/stdio.h: Add declaration for stdio.h. + * include/stdio.h: Add declaration for __fxprintf. * argp/argp-fmtstream.c: Use __fxprintf instead of inline stream orientation test and two separate function calls. * argp/argp-help.c: Likewise. diff --git a/argp/argp-fmtstream.c b/argp/argp-fmtstream.c index 215160bdcd..efa8388a84 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,2001,2002,2003 Free Software Foundation, Inc. + Copyright (C) 1997-1999,2001,2002,2003,2005 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Miles Bader <miles@gnu.ai.mit.edu>. @@ -102,11 +102,11 @@ __argp_fmtstream_free (argp_fmtstream_t fs) if (fs->p > fs->buf) { #ifdef USE_IN_LIBIO - if (_IO_fwide (fs->stream, 0) > 0) - __fwprintf (fs->stream, L"%.*s", (int) (fs->p - fs->buf), fs->buf); - else + __fxprintf (fs->stream, "%.*s", L"%.*s", + (int) (fs->p - fs->buf), fs->buf); +#else + fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); #endif - fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); } free (fs->buf); free (fs); @@ -291,17 +291,15 @@ __argp_fmtstream_update (argp_fmtstream_t fs) else /* Output the first line so we can use the space. */ { -#ifdef USE_IN_LIBIO - if (_IO_fwide (fs->stream, 0) > 0) - __fwprintf (fs->stream, L"%.*s\n", - (int) (nl - fs->buf), fs->buf); - else +#ifdef _LIBC + __fxprintf (fs->stream, "%.*s\n", L"%.*s\n", + (int) (nl - fs->buf), fs->buf); +#else + if (nl > fs->buf) + fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream); + putc_unlocked ('\n', fs->stream); #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; } @@ -360,15 +358,13 @@ __argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount) /* Flush FS's buffer. */ __argp_fmtstream_update (fs); -#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 +#ifdef _LIBC + __fxprintf (fs->stream, "%.*s", L"%.*s", + (int) (fs->p - fs->buf), fs->buf); + wrote = fs->p - fs->buf; +#else + wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); #endif - wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); if (wrote == fs->p - fs->buf) { fs->p = fs->buf; diff --git a/argp/argp-help.c b/argp/argp-help.c index 67018709d3..c5a9e84f7e 100644 --- a/argp/argp-help.c +++ b/argp/argp-help.c @@ -1,5 +1,5 @@ /* Hierarchial argument parsing help output - Copyright (C) 1995-2003, 2004 Free Software Foundation, Inc. + Copyright (C) 1995-2003, 2004, 2005 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Miles Bader <miles@gnu.ai.mit.edu>. @@ -1763,33 +1763,26 @@ __argp_error (const struct argp_state *state, const char *fmt, ...) va_start (ap, fmt); -#ifdef USE_IN_LIBIO - if (_IO_fwide (stream, 0) > 0) - { - char *buf; +#ifdef _LIBC + char *buf; - if (__asprintf (&buf, fmt, ap) < 0) - buf = NULL; + if (__asprintf (&buf, fmt, ap) < 0) + buf = NULL; - __fwprintf (stream, L"%s: %s\n", - state ? state->name : __argp_short_program_name (), - buf); + __fxprintf (stream, "%s: %s\n", L"%s: %s\n", + state ? state->name : __argp_short_program_name (), buf); - free (buf); - } - else -#endif - { - fputs_unlocked (state - ? state->name : __argp_short_program_name (), - stream); - putc_unlocked (':', stream); - putc_unlocked (' ', stream); + free (buf); +#else + fputs_unlocked (state ? state->name : __argp_short_program_name (), + stream); + putc_unlocked (':', stream); + putc_unlocked (' ', stream); - vfprintf (stream, fmt, ap); + vfprintf (stream, fmt, ap); - putc_unlocked ('\n', stream); - } + putc_unlocked ('\n', stream); +#endif __argp_state_help (state, stream, ARGP_HELP_STD_ERR); @@ -1827,41 +1820,34 @@ __argp_failure (const struct argp_state *state, int status, int errnum, __flockfile (stream); #endif -#ifdef USE_IN_LIBIO - if (_IO_fwide (stream, 0) > 0) - __fwprintf (stream, L"%s", - state ? state->name : __argp_short_program_name ()); - else +#ifdef _LIBC + __fxprintf (stream, "%s", L"%s", + state ? state->name : __argp_short_program_name ()); +#else + fputs_unlocked (state ? state->name : __argp_short_program_name (), + stream); #endif - fputs_unlocked (state - ? state->name : __argp_short_program_name (), - stream); if (fmt) { va_list ap; va_start (ap, fmt); -#ifdef USE_IN_LIBIO - if (_IO_fwide (stream, 0) > 0) - { - char *buf; +#ifdef _LIBC + char *buf; - if (__asprintf (&buf, fmt, ap) < 0) - buf = NULL; + if (__asprintf (&buf, fmt, ap) < 0) + buf = NULL; - __fwprintf (stream, L": %s", buf); + __fxprintf (stream, ": %s", L": %s", buf); - free (buf); - } - else -#endif - { - putc_unlocked (':', stream); - putc_unlocked (' ', stream); + free (buf); +#else + putc_unlocked (':', stream); + putc_unlocked (' ', stream); - vfprintf (stream, fmt, ap); - } + vfprintf (stream, fmt, ap); +#endif va_end (ap); } @@ -1870,21 +1856,18 @@ __argp_failure (const struct argp_state *state, int status, int errnum, { char buf[200]; -#ifdef USE_IN_LIBIO - if (_IO_fwide (stream, 0) > 0) - __fwprintf (stream, L": %s", - __strerror_r (errnum, buf, sizeof (buf))); - else -#endif - { - putc_unlocked (':', stream); - putc_unlocked (' ', stream); -#if defined _LIBC || defined HAVE_STRERROR_R - fputs (__strerror_r (errnum, buf, sizeof (buf)), stream); +#ifdef _LIBC + __fxprintf (stream, ": %s", L": %s", + __strerror_r (errnum, buf, sizeof (buf))); #else - fputs (strerror (errnum), stream); + putc_unlocked (':', stream); + putc_unlocked (' ', stream); +# ifdef HAVE_STRERROR_R + fputs (__strerror_r (errnum, buf, sizeof (buf)), stream); +# else + fputs (strerror (errnum), stream); +# endif #endif - } } #ifdef USE_IN_LIBIO diff --git a/assert/assert-perr.c b/assert/assert-perr.c index 3017c9fd9c..b5890d226a 100644 --- a/assert/assert-perr.c +++ b/assert/assert-perr.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1994-1998,2001,2002 Free Software Foundation, Inc. +/* Copyright (C) 1994-1998,2001,2002,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 @@ -61,13 +61,7 @@ __assert_perror_fail (int errnum, __strerror_r (errnum, errbuf, sizeof errbuf)) >= 0) { /* Print the message. */ -#ifdef USE_IN_LIBIO - if (_IO_fwide (stderr, 0) > 0) - (void) __fwprintf (stderr, L"%s", buf); - else -#endif - (void) fputs (buf, stderr); - + (void) __fxprintf (NULL, "%s", L"%s", buf); (void) fflush (stderr); /* We have to free the buffer since the appplication might catch the diff --git a/assert/assert.c b/assert/assert.c index 20c86eba52..7b7f255717 100644 --- a/assert/assert.c +++ b/assert/assert.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1991,1994-1996,1998,2001,2002 Free Software Foundation, Inc. +/* Copyright (C) 1991,1994-1996,1998,2001,2002,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 @@ -60,13 +61,7 @@ __assert_fail (const char *assertion, const char *file, unsigned int line, assertion) >= 0) { /* Print the message. */ -#ifdef USE_IN_LIBIO - if (_IO_fwide (stderr, 0) > 0) - (void) __fwprintf (stderr, L"%s", buf); - else -#endif - (void) fputs (buf, stderr); - + (void) __fxprintf (NULL, "%s", L"%s", buf); (void) fflush (stderr); /* We have to free the buffer since the application might catch the diff --git a/debug/Makefile b/debug/Makefile index e3fccc192e..009c05c9d9 100644 --- a/debug/Makefile +++ b/debug/Makefile @@ -38,7 +38,8 @@ routines = backtrace backtracesyms backtracesymsfd noophooks \ swprintf_chk vswprintf_chk wprintf_chk fwprintf_chk \ vwprintf_chk vfwprintf_chk fgetws_chk fgetws_u_chk \ confstr_chk getgroups_chk ttyname_r_chk getlogin_r_chk \ - gethostname_chk getdomainname_chk \ + gethostname_chk getdomainname_chk wcrtomb_chk mbsnrtowcs_chk \ + wcsnrtombs_chk mbsrtowcs_chk wcsrtombs_chk \ stack_chk_fail \ $(static-only-routines) static-only-routines := warning-nop stack_chk_fail_local diff --git a/debug/Versions b/debug/Versions index f33fbed6ef..2f4183bceb 100644 --- a/debug/Versions +++ b/debug/Versions @@ -30,7 +30,8 @@ libc { __swprintf_chk; __vswprintf_chk; __wprintf_chk; __fwprintf_chk; __vwprintf_chk; __vfwprintf_chk; __fgetws_chk; __fgetws_unlocked_chk; __confstr_chk; __getgroups_chk; __ttyname_r_chk; __getlogin_r_chk; - __gethostname_chk; __getdomainname_chk; + __gethostname_chk; __getdomainname_chk; __wcrtomb_chk; __mbsnrtowcs_chk; + __wcsnrtombs_chk; __mbsrtowcs_chk; __wcsrtombs_chk; __stack_chk_fail; } diff --git a/debug/mbsnrtowcs_chk.c b/debug/mbsnrtowcs_chk.c new file mode 100644 index 0000000000..2041eac87f --- /dev/null +++ b/debug/mbsnrtowcs_chk.c @@ -0,0 +1,31 @@ +/* Copyright (C) 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 + 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 <locale.h> +#include <wchar.h> + + +size_t +__mbsnrtowcs_chk (wchar_t *dst, __const char **src, size_t nmc, size_t len, + mbstate_t *ps, size_t dstlen) +{ + if (__builtin_expect (dstlen < len * sizeof (wchar_t), 0)) + __chk_fail (); + + return __mbsnrtowcs (dst, src, nmc, len, ps); +} diff --git a/debug/mbsrtowcs_chk.c b/debug/mbsrtowcs_chk.c new file mode 100644 index 0000000000..fd4b3bf76b --- /dev/null +++ b/debug/mbsrtowcs_chk.c @@ -0,0 +1,31 @@ +/* Copyright (C) 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 + 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 <locale.h> +#include <wchar.h> + + +size_t +__mbsrtowcs_chk (wchar_t *dst, __const char **src, size_t len, + mbstate_t *ps, size_t dstlen) +{ + if (__builtin_expect (dstlen < len * sizeof (wchar_t), 0)) + __chk_fail (); + + return __mbsrtowcs (dst, src, len, ps); +} diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c index 47938bbf36..62b0fa6f40 100644 --- a/debug/tst-chk1.c +++ b/debug/tst-chk1.c @@ -76,6 +76,7 @@ char buf[10]; wchar_t wbuf[10]; volatile size_t l0; volatile char *p; +volatile wchar_t *wp; const char *str1 = "JIHGFEDCBA"; const char *str2 = "F"; const char *str3 = "%s%n%s%n"; @@ -502,7 +503,7 @@ do_test (void) CHK_FAIL_END CHK_FAIL_START - p = wmempcpy (wbuf + 6, L"abcde", l0 + 5); + wp = wmempcpy (wbuf + 6, L"abcde", l0 + 5); CHK_FAIL_END CHK_FAIL_START @@ -514,7 +515,7 @@ do_test (void) CHK_FAIL_END CHK_FAIL_START - p = w |
