Skip to content

Commit

Permalink
* wcsmbs/bits/wchar2.h: Add definitions for wcrtomb, mbsrtowcs,
Browse files Browse the repository at this point in the history
	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.
  • Loading branch information
Ulrich Drepper committed Jul 20, 2005
1 parent 10ffcd5 commit df6f896
Show file tree
Hide file tree
Showing 37 changed files with 581 additions and 508 deletions.
17 changes: 16 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
42 changes: 19 additions & 23 deletions argp/argp-fmtstream.c
Original file line number Diff line number Diff line change
@@ -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>.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
103 changes: 43 additions & 60 deletions argp/argp-help.c
Original file line number Diff line number Diff line change
@@ -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>.
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
10 changes: 2 additions & 8 deletions assert/assert-perr.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions assert/assert.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion debug/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion debug/Versions
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
31 changes: 31 additions & 0 deletions debug/mbsnrtowcs_chk.c
Original file line number Diff line number Diff line change
@@ -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);
}
31 changes: 31 additions & 0 deletions debug/mbsrtowcs_chk.c
Original file line number Diff line number Diff line change
@@ -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);
}
Loading

0 comments on commit df6f896

Please sign in to comment.