summaryrefslogtreecommitdiff
path: root/wcsmbs
diff options
context:
space:
mode:
Diffstat (limited to 'wcsmbs')
-rw-r--r--wcsmbs/Makefile14
-rw-r--r--wcsmbs/bits/wchar-ldbl.h62
-rw-r--r--wcsmbs/bits/wchar2.h388
-rw-r--r--wcsmbs/btowc.c30
-rw-r--r--wcsmbs/mbrtowc.c19
-rw-r--r--wcsmbs/mbsnrtowcs.c21
-rw-r--r--wcsmbs/mbsrtowcs_l.c30
-rw-r--r--wcsmbs/tst-mbrtowc2.c67
-rw-r--r--wcsmbs/tst-mbsrtowcs.c4
-rw-r--r--wcsmbs/tst-wchar-h.c9
-rw-r--r--wcsmbs/wchar.h52
-rw-r--r--wcsmbs/wcrtomb.c21
-rw-r--r--wcsmbs/wcscoll.c3
-rw-r--r--wcsmbs/wcsmbsload.c10
-rw-r--r--wcsmbs/wcsncpy.c5
-rw-r--r--wcsmbs/wcsnrtombs.c28
-rw-r--r--wcsmbs/wcsrtombs.c28
-rw-r--r--wcsmbs/wcstol.c23
-rw-r--r--wcsmbs/wcstol_l.c30
-rw-r--r--wcsmbs/wcstoll.c25
-rw-r--r--wcsmbs/wcstoll_l.c30
-rw-r--r--wcsmbs/wcstoul.c23
-rw-r--r--wcsmbs/wcstoul_l.c30
-rw-r--r--wcsmbs/wcstoull.c25
-rw-r--r--wcsmbs/wcstoull_l.c31
-rw-r--r--wcsmbs/wctob.c20
26 files changed, 935 insertions, 93 deletions
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
index 47a489a63c..7a289a8dc7 100644
--- a/wcsmbs/Makefile
+++ b/wcsmbs/Makefile
@@ -1,4 +1,5 @@
-# Copyright (C) 1995-2000, 2002, 2003, 2004 Free Software Foundation, Inc.
+# Copyright (C) 1995-2000,2002,2003,2004,2005,2006
+# 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
@@ -21,7 +22,7 @@
#
subdir := wcsmbs
-headers := wchar.h
+headers := wchar.h bits/wchar.h bits/wchar2.h bits/wchar-ldbl.h
distribute := wcwidth.h wcsmbsload.h
routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
@@ -40,14 +41,14 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
wcsmbsload mbsrtowcs_l
tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \
- tst-wcrtomb tst-wcpncpy tst-mbsrtowcs
+ tst-wcrtomb tst-wcpncpy tst-mbsrtowcs tst-wchar-h tst-mbrtowc2
include ../Rules
CFLAGS-wcwidth.c = -I../wctype
CFLAGS-wcswidth.c = -I../wctype
-strtox-CFLAGS = -I../include -I../stdlib
+strtox-CFLAGS = -I../include
CFLAGS-wcstol.c = $(strtox-CFLAGS)
CFLAGS-wcstoul.c = $(strtox-CFLAGS)
CFLAGS-wcstoll.c = $(strtox-CFLAGS)
@@ -62,7 +63,12 @@ CFLAGS-wcstoull_l.c = $(strtox-CFLAGS)
CFLAGS-wcstod_l.c = $(strtox-CFLAGS)
CFLAGS-wcstold_l.c = $(strtox-CFLAGS)
CFLAGS-wcstof_l.c = $(strtox-CFLAGS)
+CFLAGS-tst-wchar-h.c = -D_FORTIFY_SOURCE=2
+
+# We need to find the default version of strtold_l in stdlib.
+CPPFLAGS-wcstold_l.c = -I../stdlib
tst-btowc-ENV = LOCPATH=$(common-objpfx)localedata
tst-mbrtowc-ENV = LOCPATH=$(common-objpfx)localedata
tst-wcrtomb-ENV = LOCPATH=$(common-objpfx)localedata
+tst-mbrtowc2-ENV = LOCPATH=$(common-objpfx)localedata
diff --git a/wcsmbs/bits/wchar-ldbl.h b/wcsmbs/bits/wchar-ldbl.h
new file mode 100644
index 0000000000..5e4894567c
--- /dev/null
+++ b/wcsmbs/bits/wchar-ldbl.h
@@ -0,0 +1,62 @@
+/* -mlong-double-64 compatibility mode for <wchar.h> functions.
+ Copyright (C) 2006 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. */
+
+#ifndef _WCHAR_H
+# error "Never include <bits/wchar-ldbl.h> directly; use <wchar.h> instead."
+#endif
+
+#if defined __USE_ISOC99 || defined __USE_UNIX98
+__BEGIN_NAMESPACE_C99
+__LDBL_REDIR_DECL (fwprintf);
+__LDBL_REDIR_DECL (wprintf);
+__LDBL_REDIR_DECL (swprintf);
+__LDBL_REDIR_DECL (vfwprintf);
+__LDBL_REDIR_DECL (vwprintf);
+__LDBL_REDIR_DECL (vswprintf);
+__LDBL_REDIR_DECL (fwscanf);
+__LDBL_REDIR_DECL (wscanf);
+__LDBL_REDIR_DECL (swscanf);
+__END_NAMESPACE_C99
+#endif
+
+#ifdef __USE_ISOC99
+__BEGIN_NAMESPACE_C99
+__LDBL_REDIR1_DECL (wcstold, wcstod);
+__LDBL_REDIR_DECL (vfwscanf);
+__LDBL_REDIR_DECL (vwscanf);
+__LDBL_REDIR_DECL (vswscanf);
+__END_NAMESPACE_C99
+#endif
+
+#ifdef __USE_GNU
+__LDBL_REDIR1_DECL (wcstold_l, wcstod_l);
+#endif
+
+__LDBL_REDIR1_DECL (__wcstold_internal, __wcstod_internal);
+
+#if __USE_FORTIFY_LEVEL > 0 && !defined __cplusplus
+__LDBL_REDIR_DECL (__swprintf_chk)
+__LDBL_REDIR_DECL (__vswprintf_chk)
+# if __USE_FORTIFY_LEVEL > 1
+__LDBL_REDIR_DECL (__fwprintf_chk)
+__LDBL_REDIR_DECL (__wprintf_chk)
+__LDBL_REDIR_DECL (__vfwprintf_chk)
+__LDBL_REDIR_DECL (__vwprintf_chk)
+# endif
+#endif
diff --git a/wcsmbs/bits/wchar2.h b/wcsmbs/bits/wchar2.h
new file mode 100644
index 0000000000..00216ec059
--- /dev/null
+++ b/wcsmbs/bits/wchar2.h
@@ -0,0 +1,388 @@
+/* Checking macros for wchar functions.
+ Copyright (C) 2005, 2006 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. */
+
+#ifndef _WCHAR_H
+# error "Never include <bits/wchar.h> directly; use <wchar.h> instead."
+#endif
+
+
+extern wchar_t *__wmemcpy_chk (wchar_t *__restrict __s1,
+ __const wchar_t *__restrict __s2, size_t __n,
+ size_t __ns1) __THROW;
+extern wchar_t *__REDIRECT_NTH (__wmemcpy_alias,
+ (wchar_t *__restrict __s1,
+ __const wchar_t *__restrict __s2, size_t __n),
+ wmemcpy);
+
+extern __always_inline wchar_t *
+__NTH (wmemcpy (wchar_t *__restrict __s1, __const wchar_t *__restrict __s2,
+ size_t __n))
+{
+ if (__bos0 (__s1) != (size_t) -1)
+ return __wmemcpy_chk (__s1, __s2, __n, __bos0 (__s1) / sizeof (wchar_t));
+ return __wmemcpy_alias (__s1, __s2, __n);
+}
+
+
+extern wchar_t *__wmemmove_chk (wchar_t *__s1, __const wchar_t *__s2,
+ size_t __n, size_t __ns1) __THROW;
+extern wchar_t *__REDIRECT_NTH (__wmemmove_alias, (wchar_t *__s1,
+ __const wchar_t *__s2,
+ size_t __n), wmemmove);
+
+extern __always_inline wchar_t *
+__NTH (wmemmove (wchar_t *__restrict __s1, __const wchar_t *__restrict __s2,
+ size_t __n))
+{
+ if (__bos0 (__s1) != (size_t) -1)
+ return __wmemmove_chk (__s1, __s2, __n, __bos0 (__s1) / sizeof (wchar_t));
+ return __wmemmove_alias (__s1, __s2, __n);
+}
+
+
+#ifdef __USE_GNU
+extern wchar_t *__wmempcpy_chk (wchar_t *__restrict __s1,
+ __const wchar_t *__restrict __s2, size_t __n,
+ size_t __ns1) __THROW;
+extern wchar_t *__REDIRECT_NTH (__wmempcpy_alias,
+ (wchar_t *__restrict __s1,
+ __const wchar_t *__restrict __s2,
+ size_t __n), wmempcpy);
+
+extern __always_inline wchar_t *
+__NTH (wmempcpy (wchar_t *__restrict __s1, __const wchar_t *__restrict __s2,
+ size_t __n))
+{
+ if (__bos0 (__s1) != (size_t) -1)
+ return __wmempcpy_chk (__s1, __s2, __n, __bos0 (__s1) / sizeof (wchar_t));
+ return __wmempcpy_alias (__s1, __s2, __n);
+}
+#endif
+
+
+extern wchar_t *__wmemset_chk (wchar_t *__s, wchar_t __c, size_t __n,
+ size_t __ns) __THROW;
+extern wchar_t *__REDIRECT_NTH (__wmemset_alias, (wchar_t *__s, wchar_t __c,
+ size_t __n), wmemset);
+
+extern __always_inline wchar_t *
+__NTH (wmemset (wchar_t *__restrict __s, wchar_t __c, size_t __n))
+{
+ if (__bos0 (__s) != (size_t) -1)
+ return __wmemset_chk (__s, __c, __n, __bos0 (__s) / sizeof (wchar_t));
+ return __wmemset_alias (__s, __c, __n);
+}
+
+
+extern wchar_t *__wcscpy_chk (wchar_t *__restrict __dest,
+ __const wchar_t *__restrict __src,
+ size_t __n) __THROW;
+extern wchar_t *__REDIRECT_NTH (__wcscpy_alias,
+ (wchar_t *__restrict __dest,
+ __const wchar_t *__restrict __src), wcscpy);
+
+extern __always_inline wchar_t *
+__NTH (wcscpy (wchar_t *__dest, __const wchar_t *__src))
+{
+ if (__bos (__dest) != (size_t) -1)
+ return __wcscpy_chk (__dest, __src, __bos (__dest) / sizeof (wchar_t));
+ return __wcscpy_alias (__dest, __src);
+}
+
+
+extern wchar_t *__wcpcpy_chk (wchar_t *__dest, __const wchar_t *__src,
+ size_t __destlen) __THROW;
+extern wchar_t *__REDIRECT_NTH (__wcpcpy_alias, (wchar_t *__dest,
+ __const wchar_t *__src),
+ wcpcpy);
+
+extern __always_inline wchar_t *
+__NTH (wcpcpy (wchar_t *__dest, __const wchar_t *__src))
+{
+ if (__bos (__dest) != (size_t) -1)
+ return __wcpcpy_chk (__dest, __src, __bos (__dest) / sizeof (wchar_t));
+ return __wcpcpy_alias (__dest, __src);
+}
+
+
+extern wchar_t *__wcsncpy_chk (wchar_t *__restrict __dest,
+ __const wchar_t *__restrict __src, size_t __n,
+ size_t __destlen) __THROW;
+extern wchar_t *__REDIRECT_NTH (__wcsncpy_alias,
+ (wchar_t *__restrict __dest,
+ __const wchar_t *__restrict __src,
+ size_t __n), wcsncpy);
+
+extern __always_inline wchar_t *
+__NTH (wcsncpy (wchar_t *__dest, __const wchar_t *__src, size_t __n))
+{
+ if (__bos (__dest) != (size_t) -1
+ && (!__builtin_constant_p (__n) || __bos (__dest) >= __n))
+ return __wcsncpy_chk (__dest, __src, __n,
+ __bos (__dest) / sizeof (wchar_t));
+ return __wcsncpy_alias (__dest, __src, __n);
+}
+
+
+extern wchar_t *__wcpncpy_chk (wchar_t *__restrict __dest,
+ __const wchar_t *__restrict __src, size_t __n,
+ size_t __destlen) __THROW;
+extern wchar_t *__REDIRECT_NTH (__wcpncpy_alias,
+ (wchar_t *__restrict __dest,
+ __const wchar_t *__restrict __src,
+ size_t __n), wcpncpy);
+
+extern __always_inline wchar_t *
+__NTH (wcpncpy (wchar_t *__dest, __const wchar_t *__src, size_t __n))
+{
+ if (__bos (__dest) != (size_t) -1
+ && (!__builtin_constant_p (__n) || __bos (__dest) >= __n))
+ return __wcpncpy_chk (__dest, __src, __n,
+ __bos (__dest) / sizeof (wchar_t));
+ return __wcpncpy_alias (__dest, __src, __n);
+}
+
+
+extern wchar_t *__wcscat_chk (wchar_t *__restrict __dest,
+ __const wchar_t *__restrict __src,
+ size_t __destlen) __THROW;
+extern wchar_t *__REDIRECT_NTH (__wcscat_alias,
+ (wchar_t *__restrict __dest,
+ __const wchar_t *__restrict __src), wcscat);
+
+extern __always_inline wchar_t *
+__NTH (wcscat (wchar_t *__dest, __const wchar_t *__src))
+{
+ if (__bos (__dest) != (size_t) -1)
+ return __wcscat_chk (__dest, __src, __bos (__dest) / sizeof (wchar_t));
+ return __wcscat_alias (__dest, __src);
+}
+
+
+extern wchar_t *__wcsncat_chk (wchar_t *__restrict __dest,
+ __const wchar_t *__restrict __src,
+ size_t __n, size_t __destlen) __THROW;
+extern wchar_t *__REDIRECT_NTH (__wcsncat_alias,
+ (wchar_t *__restrict __dest,
+ __const wchar_t *__restrict __src,
+ size_t __n), wcsncat);
+
+extern __always_inline wchar_t *
+__NTH (wcsncat (wchar_t *__dest, __const wchar_t *__src, size_t __n))
+{
+ if (__bos (__dest) != (size_t) -1)
+ return __wcsncat_chk (__dest, __src, __n,
+ __bos (__dest) / sizeof (wchar_t));
+ return __wcsncat_alias (__dest, __src, __n);
+}
+
+
+extern int __swprintf_chk (wchar_t *__restrict __s, size_t __n,
+ int __flag, size_t __s_len,
+ __const wchar_t *__restrict __format, ...)
+ __THROW /* __attribute__ ((__format__ (__wprintf__, 5, 6))) */;
+
+/* XXX We might want to have support in gcc for swprintf. */
+#define swprintf(s, n, ...) \
+ (__bos (s) != (size_t) -1 || __USE_FORTIFY_LEVEL > 1 \
+ ? __swprintf_chk (s, n, __USE_FORTIFY_LEVEL - 1, __bos (s), __VA_ARGS__) \
+ : swprintf (s, n, __VA_ARGS__))
+
+
+extern int __vswprintf_chk (wchar_t *__restrict __s, size_t __n,
+ int __flag, size_t __s_len,
+ __const wchar_t *__restrict __format,
+ __gnuc_va_list __arg)
+ __THROW /* __attribute__ ((__format__ (__wprintf__, 5, 0))) */;
+
+#define vswprintf(s, n, fmt, ap) \
+ (__bos (s) != (size_t) -1 || __USE_FORTIFY_LEVEL > 1 \
+ ? __vswprintf_chk (s, n, __USE_FORTIFY_LEVEL - 1, __bos (s), fmt, ap) \
+ : vswprintf (s, n, fmt, ap))
+
+
+#if __USE_FORTIFY_LEVEL > 1
+
+extern int __fwprintf_chk (__FILE *__restrict __stream, int __flag,
+ __const wchar_t *__restrict __format, ...);
+extern int __wprintf_chk (int __flag, __const wchar_t *__restrict __format,
+ ...);
+extern int __vfwprintf_chk (__FILE *__restrict __stream, int __flag,
+ __const wchar_t *__restrict __format,
+ __gnuc_va_list __ap);
+extern int __vwprintf_chk (int __flag, __const wchar_t *__restrict __format,
+ __gnuc_va_list __ap);
+
+# define wprintf(...) \
+ __wprintf_chk (__USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
+# define fwprintf(stream, ...) \
+ __fwprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
+# define vwprintf(format, ap) \
+ __vwprintf_chk (__USE_FORTIFY_LEVEL - 1, format, ap)
+# define vfwprintf(stream, format, ap) \
+ __vfwprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, format, ap)
+
+#endif
+
+extern wchar_t *__fgetws_chk (wchar_t *__restrict __s, size_t __size, int __n,
+ __FILE *__restrict __stream) __wur;
+extern wchar_t *__REDIRECT (__fgetws_alias,
+ (wchar_t *__restrict __s, int __n,
+ __FILE *__restrict __stream), fgetws) __wur;
+
+extern __always_inline __wur wchar_t *
+fgetws (wchar_t *__restrict __s, int __n, __FILE *__restrict __stream)
+{
+ if (__bos (__s) != (size_t) -1
+ && (!__builtin_constant_p (__n) || (size_t) __n > __bos (__s)))
+ return __fgetws_chk (__s, __bos (__s), __n, __stream);
+ return __fgetws_alias (__s, __n, __stream);
+}
+
+#ifdef __USE_GNU
+extern wchar_t *__fgetws_unlocked_chk (wchar_t *__restrict __s, size_t __size,
+ int __n, __FILE *__restrict __stream)
+ __wur;
+extern wchar_t *__REDIRECT (__fgetws_unlocked_alias,
+ (wchar_t *__restrict __s, int __n,
+ __FILE *__restrict __stream), fgetws_unlocked)
+ __wur;
+
+extern __always_inline __wur wchar_t *
+fgetws_unlocked (wchar_t *__restrict __s, int __n, __FILE *__restrict __stream)
+{
+ if (__bos (__s) != (size_t) -1
+ && (!__builtin_constant_p (__n) || (size_t) __n > __bos (__s)))
+ return __fgetws_unlocked_chk (__s, __bos (__s), __n, __stream);
+ return __fgetws_unlocked_alias (__s, __n, __stream);
+}
+#endif
+
+
+extern size_t __wcrtomb_chk (char *__s, wchar_t __wchar, mbstate_t *__p,
+ size_t __buflen) __THROW __wur;
+extern size_t __REDIRECT_NTH (__wcrtomb_alias,
+ (char *__restrict __s, wchar_t __wchar,
+ mbstate_t *__restrict __ps), wcrtomb) __wur;
+
+extern __always_inline __wur size_t
+__NTH (wcrtomb (char *__s, wchar_t __wchar, mbstate_t *__ps))
+{
+ /* We would have to include <limits.h> to get a definition of MB_LEN_MAX.
+ But this would only disturb the namespace. So we define our own
+ version here. */
+#define __WCHAR_MB_LEN_MAX 16
+#if defined MB_LEN_MAX && MB_LEN_MAX != __WCHAR_MB_LEN_MAX
+# error "Assumed value of MB_LEN_MAX wrong"
+#endif
+ if (__bos (__s) != (size_t) -1 && __WCHAR_MB_LEN_MAX > __bos (__s))
+ return __wcrtomb_chk (__s, __wchar, __ps, __bos (__s));
+ return __wcrtomb_alias (__s, __wchar, __ps);
+}
+
+
+extern size_t __mbsrtowcs_chk (wchar_t *__restrict __dst,
+ __const char **__restrict __src,
+ size_t __len, mbstate_t *__restrict __ps,
+ size_t __dstlen) __THROW;
+extern size_t __REDIRECT_NTH (__mbsrtowcs_alias,
+ (wchar_t *__restrict __dst,
+ __const char **__restrict __src,
+ size_t __len, mbstate_t *__restrict __ps),
+ mbsrtowcs);
+
+extern __always_inline size_t
+__NTH (mbsrtowcs (wchar_t *__restrict __dst, __const char **__restrict __src,
+ size_t __len, mbstate_t *__restrict __ps))
+{
+ if (__bos (__dst) != (size_t) -1
+ && (!__builtin_constant_p (__len)
+ || __len > __bos (__dst) / sizeof (wchar_t)))
+ return __mbsrtowcs_chk (__dst, __src, __len, __ps,
+ __bos (__dst) / sizeof (wchar_t));
+ return __mbsrtowcs_alias (__dst, __src, __len, __ps);
+}
+
+
+extern size_t __wcsrtombs_chk (char *__restrict __dst,
+ __const wchar_t **__restrict __src,
+ size_t __len, mbstate_t *__restrict __ps,
+ size_t __dstlen) __THROW;
+extern size_t __REDIRECT_NTH (__wcsrtombs_alias,
+ (char *__restrict __dst,
+ __const wchar_t **__restrict __src,
+ size_t __len, mbstate_t *__restrict __ps),
+ wcsrtombs);
+
+extern __always_inline size_t
+__NTH (wcsrtombs (char *__restrict __dst, __const wchar_t **__restrict __src,
+ size_t __len, mbstate_t *__restrict __ps))
+{
+ if (__bos (__dst) != (size_t) -1
+ && (!__builtin_constant_p (__len) || __len > __bos (__dst)))
+ return __wcsrtombs_chk (__dst, __src, __len, __ps, __bos (__dst));
+ return __wcsrtombs_alias (__dst, __src, __len, __ps);
+}
+
+
+#ifdef __USE_GNU
+extern size_t __mbsnrtowcs_chk (wchar_t *__restrict __dst,
+ __const char **__restrict __src, size_t __nmc,
+ size_t __len, mbstate_t *__restrict __ps,
+ size_t __dstlen) __THROW;
+extern size_t __REDIRECT_NTH (__mbsnrtowcs_alias,
+ (wchar_t *__restrict __dst,
+ __const char **__restrict __src, size_t __nmc,
+ size_t __len, mbstate_t *__restrict __ps),
+ mbsnrtowcs);
+
+extern __always_inline size_t
+__NTH (mbsnrtowcs (wchar_t *__restrict __dst, __const char **__restrict __src,
+ size_t __nmc, size_t __len, mbstate_t *__restrict __ps))
+{
+ if (__bos (__dst) != (size_t) -1
+ && (!__builtin_constant_p (__len)
+ || __len > __bos (__dst) / sizeof (wchar_t)))
+ return __mbsnrtowcs_chk (__dst, __src, __nmc, __len, __ps,
+ __bos (__dst) / sizeof (wchar_t));
+ return __mbsnrtowcs_alias (__dst, __src, __nmc, __len, __ps);
+}
+
+
+extern size_t __wcsnrtombs_chk (char *__restrict __dst,
+ __const wchar_t **__restrict __src,
+ size_t __nwc, size_t __len,
+ mbstate_t *__restrict __ps, size_t __dstlen)
+ __THROW;
+extern size_t __REDIRECT_NTH (__wcsnrtombs_alias,
+ (char *__restrict __dst,
+ __const wchar_t **__restrict __src,
+ size_t __nwc, size_t __len,
+ mbstate_t *__restrict __ps), wcsnrtombs);
+
+extern __always_inline size_t
+__NTH (wcsnrtombs (char *__restrict __dst, __const wchar_t **__restrict __src,
+ size_t __nwc, size_t __len, mbstate_t *__restrict __ps))
+{
+ if (__bos (__dst) != (size_t) -1
+ && (!__builtin_constant_p (__len) || __len > __bos (__dst)))
+ return __wcsnrtombs_chk (__dst, __src, __nwc, __len, __ps, __bos (__dst));
+ return __wcsnrtombs_alias (__dst, __src, __nwc, __len, __ps);
+}
+#endif
diff --git a/wcsmbs/btowc.c b/wcsmbs/btowc.c
index 1ba0221403..6517d4f635 100644
--- a/wcsmbs/btowc.c
+++ b/wcsmbs/btowc.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996,1997,1998,1999,2000,2002 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2000,2002,2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.org>, 1996.
@@ -17,6 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <ctype.h>
#include <dlfcn.h>
#include <gconv.h>
#include <stdio.h>
@@ -25,6 +26,8 @@
#include <wcsmbsload.h>
#include <limits.h>
+#include <sysdep.h>
+
wint_t
__btowc (c)
@@ -37,15 +40,24 @@ __btowc (c)
if (c < SCHAR_MIN || c > UCHAR_MAX || c == EOF)
return WEOF;
+ /* We know that only ASCII compatible encodings are used for the
+ locale and that the wide character encoding is ISO 10646. */
+ if (isascii (c))
+ return (wint_t) c;
+
/* Get the conversion functions. */
fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE));
+ __gconv_btowc_fct btowc_fct = fcts->towc->__btowc_fct;
if (__builtin_expect (fcts->towc_nsteps == 1, 1)
- && __builtin_expect (fcts->towc->__btowc_fct != NULL, 1))
+ && __builtin_expect (btowc_fct != NULL, 1))
{
/* Use the shortcut function. */
- return DL_CALL_FCT (fcts->towc->__btowc_fct,
- (fcts->towc, (unsigned char) c));
+#ifdef PTR_DEMANGLE
+ if (fcts->towc->__shlib_handle != NULL)
+ PTR_DEMANGLE (btowc_fct);
+#endif
+ return DL_CALL_FCT (btowc_fct, (fcts->towc, (unsigned char) c));
}
else
{
@@ -72,9 +84,13 @@ __btowc (c)
/* Create the input string. */
inbuf[0] = c;
- status = DL_CALL_FCT (fcts->towc->__fct,
- (fcts->towc, &data, &inptr, inptr + 1,
- NULL, &dummy, 0, 1));
+ __gconv_fct fct = fcts->towc->__fct;
+#ifdef PTR_DEMANGLE
+ if (fcts->towc->__shlib_handle != NULL)
+ PTR_DEMANGLE (fct);
+#endif
+ status = DL_CALL_FCT (fct, (fcts->towc, &data, &inptr, inptr + 1,
+ NULL, &dummy, 0, 1));
if (status != __GCONV_OK && status != __GCONV_FULL_OUTPUT
&& status != __GCONV_EMPTY_INPUT)
diff --git a/wcsmbs/mbrtowc.c b/wcsmbs/mbrtowc.c
index 6932b047ae..b534571736 100644
--- a/wcsmbs/mbrtowc.c
+++ b/wcsmbs/mbrtowc.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2004
+/* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2004, 2005
Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.org>, 1996.
@@ -18,13 +18,14 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <assert.h>
#include <dlfcn.h>
#include <errno.h>
#include <gconv.h>
#include <wchar.h>
#include <wcsmbsload.h>
-#include <assert.h>
+#include <sysdep.h>
#ifndef EILSEQ
# define EILSEQ EINVAL
@@ -42,7 +43,7 @@ __mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
size_t result;
size_t dummy;
const unsigned char *inbuf, *endbuf;
- char *outbuf = (char *) (pwc ?: buf);
+ unsigned char *outbuf = (unsigned char *) (pwc ?: buf);
const struct gconv_fcts *fcts;
/* Set information for this step. */
@@ -56,7 +57,7 @@ __mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
initial state. */
if (s == NULL)
{
- outbuf = (char *) buf;
+ outbuf = (unsigned char *) buf;
s = "";
n = 1;
}
@@ -73,9 +74,13 @@ __mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
endbuf = inbuf + n;
if (__builtin_expect (endbuf < inbuf, 0))
endbuf = (const unsigned char *) ~(uintptr_t) 0;
- status = DL_CALL_FCT (fcts->towc->__fct,
- (fcts->towc, &data, &inbuf, endbuf,
- NULL, &dummy, 0, 1));
+ __gconv_fct fct = fcts->towc->__fct;
+#ifdef PTR_DEMANGLE
+ if (fcts->towc->__shlib_handle != NULL)
+ PTR_DEMANGLE (fct);
+#endif
+ status = DL_CALL_FCT (fct, (fcts->towc, &data, &inbuf, endbuf,
+ NULL, &dummy, 0, 1));
/* There must not be any problems with the conversion but illegal input
characters. The output buffer must be large enough, otherwise the
diff --git a/wcsmbs/mbsnrtowcs.c b/wcsmbs/mbsnrtowcs.c
index 9ac06fe6c2..8d0b9d3609 100644
--- a/wcsmbs/mbsnrtowcs.c
+++ b/wcsmbs/mbsnrtowcs.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996,1997,1998,1999,2000,2002 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2000, 2002, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.org>, 1996.
@@ -17,6 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <assert.h>
#include <dlfcn.h>
#include <errno.h>
#include <gconv.h>
@@ -24,7 +25,7 @@
#include <wchar.h>
#include <wcsmbsload.h>
-#include <assert.h>
+#include <sysdep.h>
#ifndef EILSEQ
# define EILSEQ EINVAL
@@ -62,19 +63,24 @@ __mbsnrtowcs (dst, src, nmc, len, ps)
if (nmc == 0)
return 0;
- srcend = *src + __strnlen (*src, nmc - 1) + 1;
+ srcend = (const unsigned char *) *src + __strnlen (*src, nmc - 1) + 1;
/* Get the conversion functions. */
fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE));
/* Get the structure with the function pointers. */
towc = fcts->towc;
+ __gconv_fct fct = towc->__fct;
+#ifdef PTR_DEMANGLE
+ if (towc->__shlib_handle != NULL)
+ PTR_DEMANGLE (fct);
+#endif
/* We have to handle DST == NULL special. */
if (dst == NULL)
{
wchar_t buf[64]; /* Just an arbitrary size. */
- const unsigned char *inbuf = *src;
+ const unsigned char *inbuf = (const unsigned char *) *src;
result = 0;
data.__outbufend = (unsigned char *) buf + sizeof (buf);
@@ -82,9 +88,8 @@ __mbsnrtowcs (dst, src, nmc, len, ps)
{
data.__outbuf = (unsigned char *) buf;
- status = DL_CALL_FCT (towc->__fct,
- (towc, &data, &inbuf, srcend, NULL,
- &dummy, 0, 1));
+ status = DL_CALL_FCT (fct, (towc, &data, &inbuf, srcend, NULL,
+ &dummy, 0, 1));
result += (wchar_t *) data.__outbuf - buf;
}
@@ -103,7 +108,7 @@ __mbsnrtowcs (dst, src, nmc, len, ps)
data.__outbuf = (unsigned char *) dst;
data.__outbufend = data.__outbuf + len * sizeof (wchar_t);
- status = DL_CALL_FCT (towc->__fct,
+ status = DL_CALL_FCT (fct,
(towc, &data, (const unsigned char **) src, srcend,
NULL, &dummy, 0, 1));
diff --git a/wcsmbs/mbsrtowcs_l.c b/wcsmbs/mbsrtowcs_l.c
index 8da3095566..264c410c92 100644
--- a/wcsmbs/mbsrtowcs_l.c
+++ b/wcsmbs/mbsrtowcs_l.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.org>, 2002.
@@ -17,6 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <assert.h>
#include <ctype.h>
#include <string.h>
#include "wcsmbsload.h"
@@ -28,7 +29,7 @@
#include <wchar.h>
#include <wcsmbsload.h>
-#include <assert.h>
+#include <sysdep.h>
#ifndef EILSEQ
# define EILSEQ EINVAL
@@ -63,6 +64,11 @@ __mbsrtowcs_l (dst, src, len, ps, l)
/* Get the structure with the function pointers. */
towc = fcts->towc;
+ __gconv_fct fct = towc->__fct;
+#ifdef PTR_DEMANGLE
+ if (towc->__shlib_handle != NULL)
+ PTR_DEMANGLE (fct);
+#endif
/* We have to handle DST == NULL special. */
if (dst == NULL)
@@ -70,20 +76,19 @@ __mbsrtowcs_l (dst, src, len, ps, l)
mbstate_t temp_state;
wchar_t buf[64]; /* Just an arbitrary size. */
const unsigned char *inbuf = (const unsigned char *) *src;
- const unsigned char *srcend = inbuf + strlen (inbuf) + 1;
+ const unsigned char *srcend = inbuf + strlen (*src) + 1;
temp_state = *data.__statep;
data.__statep = &temp_state;
result = 0;
- data.__outbufend = (char *) buf + sizeof (buf);
+ data.__outbufend = (unsigned char *) buf + sizeof (buf);
do
{
- data.__outbuf = (char *) buf;
+ data.__outbuf = (unsigned char *) buf;
- status = DL_CALL_FCT (towc->__fct,
- (towc, &data, &inbuf, srcend, NULL,
- &non_reversible, 0, 1));
+ status = DL_CALL_FCT (fct, (towc, &data, &inbuf, srcend, NULL,
+ &non_reversible, 0, 1));
result += (wchar_t *) data.__outbuf - buf;
}
@@ -114,11 +119,10 @@ __mbsrtowcs_l (dst, src, len, ps, l)
{
/* Pessimistic guess as to how much input we can use. In the
worst case we need one input byte for one output wchar_t. */
- srcend = srcp + __strnlen (srcp, len) + 1;
+ srcend = srcp + __strnlen ((const char *) srcp, len) + 1;
- status = DL_CALL_FCT (towc->__fct,
- (towc, &data, &srcp, srcend, NULL,
- &non_reversible, 0, 1));
+ status = DL_CALL_FCT (fct, (towc, &data, &srcp, srcend, NULL,
+ &non_reversible, 0, 1));
if ((status != __GCONV_EMPTY_INPUT
&& status != __GCONV_INCOMPLETE_INPUT)
/* Not all input read. */
@@ -131,7 +135,7 @@ __mbsrtowcs_l (dst, src, len, ps, l)
}
/* Make the end if the input known to the caller. */
- *src = srcp;
+ *src = (const char *) srcp;
result = (wchar_t *) data.__outbuf - dst;
diff --git a/wcsmbs/tst-mbrtowc2.c b/wcsmbs/tst-mbrtowc2.c
new file mode 100644
index 0000000000..67d8e29a0f
--- /dev/null
+++ b/wcsmbs/tst-mbrtowc2.c
@@ -0,0 +1,67 @@
+/* Derived from the test case in http://sourceware.org/bugzilla/show_bug.cgi?id=714 */
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+#include <wchar.h>
+
+
+static struct
+{
+ const char *chp;
+ size_t nchp;
+ const char *loc;
+} tests[] =
+{
+ { (const char[]) { 0x8F, 0xA2, 0xAF }, 3, "ja_JP.EUC-JP" },
+ { (const char[]) { 0xD1, 0xA5 }, 2, "ja_JP.EUC-JP" },
+ { (const char[]) { 0x8E, 0xA5 }, 2, "ja_JP.EUC-JP" },
+ { (const char[]) { 0x8E, 0xA2, 0xA1, 0xA1 }, 4, "zh_TW.EUC-TW" },
+ { (const char[]) { 0xA1, 0xA1 }, 2, "zh_TW.EUC-TW" },
+ { (const char[]) { 0xE3, 0x80, 0x80 }, 3, "de_DE.UTF-8" },
+ { (const char[]) { 0xC3, 0xA4 }, 2, "de_DE.UTF-8" }
+};
+#define ntests (sizeof (tests) / sizeof (tests[0]))
+
+
+static int t (const char *ch, size_t nch, const char *loc);
+
+static int
+do_test (void)
+{
+ int r = 0;
+ for (int i = 0; i < ntests; ++i)
+ r |= t (tests[i].chp, tests[i].nchp, tests[i].loc);
+ return r;
+}
+
+static int
+t (const char *ch, size_t nch, const char *loc)
+{
+ int i;
+ wchar_t wch;
+ wchar_t wch2;
+ mbstate_t mbs;
+ int n = 0;
+
+ setlocale (LC_ALL, loc);
+
+ memset (&mbs, '\0', sizeof (mbstate_t));
+ for (i = 0; i < nch; i++)
+ {
+ n = mbrtowc (&wch, ch + i, 1, &mbs);
+ if (n >= 0)
+ break;
+ }
+ printf ("n = %d, count = %d, wch = %08lX\n", n, i, (unsigned long int) wch);
+
+ memset (&mbs, '\0', sizeof (mbstate_t));
+ n = mbrtowc (&wch2, ch, nch, &mbs);
+ printf ("n = %d, wch = %08lX\n", n, (unsigned long int) wch2);
+
+ int ret = n != nch || i + 1 != nch || n != nch || wch != wch2;
+ puts (ret ? "FAIL\n" : "OK\n");
+ return ret;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/wcsmbs/tst-mbsrtowcs.c b/wcsmbs/tst-mbsrtowcs.c
index eb6c8e21b1..cca5a80a39 100644
--- a/wcsmbs/tst-mbsrtowcs.c
+++ b/wcsmbs/tst-mbsrtowcs.c
@@ -1,5 +1,5 @@
/* Test NUL handling of mbsrtowcs.
- Copyright (C) 2004 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
@@ -32,7 +32,7 @@ main (void)
mbstate_t state;
memset (&state, '\0', sizeof (state));
- const char *in = buf;
+ const char *in = (const char *) buf;
size_t n = mbsrtowcs (out, &in, sizeof (out) / sizeof (wchar_t), &state);
int result = 0;
diff --git a/wcsmbs/tst-wchar-h.c b/wcsmbs/tst-wchar-h.c
new file mode 100644
index 0000000000..4cf2dd0690
--- /dev/null
+++ b/wcsmbs/tst-wchar-h.c
@@ -0,0 +1,9 @@
+#include <stdlib.h>
+#include <wchar.h>
+
+int
+main (void)
+{
+ mbstate_t x;
+ return sizeof (x) - sizeof (mbstate_t);
+}
diff --git a/wcsmbs/wchar.h b/wcsmbs/wchar.h
index 1fe7e94d92..f54abfaa96 100644
--- a/wcsmbs/wchar.h
+++ b/wcsmbs/wchar.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995-2002, 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1995-2004,2005,2006 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
@@ -320,6 +320,24 @@ __END_NAMESPACE_C99
#ifdef __USE_EXTERN_INLINES
/* Define inline function as optimization. */
+
+# ifndef __cplusplus
+/* We can use the BTOWC and WCTOB optimizations since we know that all
+ locales must use ASCII encoding for the values in the ASCII range
+ and because the wchar_t encoding is always ISO 10646. */
+extern wint_t __btowc_alias (int __c) __asm ("btowc");
+extern __inline wint_t
+__NTH (btowc (int __c))
+{ return (__builtin_constant_p (__c) && __c >= '\0' && __c <= '\x7f'
+ ? (wint_t) __c : __btowc_alias (__c)); }
+
+extern int __wctob_alias (wint_t __c) __asm ("wctob");
+extern __inline int
+__NTH (wctob (wint_t __wc))
+{ return (__builtin_constant_p (__wc) && __wc >= L'\0' && __wc <= L'\x7f'
+ ? (int) __wc : __wctob_alias (__wc)); }
+# endif
+
extern __inline size_t
__NTH (mbrlen (__const char *__restrict __s, size_t __n,
mbstate_t *__restrict __ps))
@@ -491,26 +509,30 @@ extern long double __wcstold_internal (__const wchar_t *__restrict __nptr,
wchar_t **__restrict __endptr,
int __group) __THROW;
-#ifndef __wcstol_internal_defined
+#if !defined __wcstol_internal_defined \
+ && defined __OPTIMIZE__ && __GNUC__ >= 2
extern long int __wcstol_internal (__const wchar_t *__restrict __nptr,
wchar_t **__restrict __endptr,
int __base, int __group) __THROW;
# define __wcstol_internal_defined 1
#endif
-#ifndef __wcstoul_internal_defined
+#if !defined __wcstoul_internal_defined \
+ && defined __OPTIMIZE__ && __GNUC__ >= 2
extern unsigned long int __wcstoul_internal (__const wchar_t *__restrict __npt,
wchar_t **__restrict __endptr,
int __base, int __group) __THROW;
# define __wcstoul_internal_defined 1
#endif
-#ifndef __wcstoll_internal_defined
+#if !defined __wcstoll_internal_defined \
+ && defined __OPTIMIZE__ && __GNUC__ >= 2
__extension__
extern long long int __wcstoll_internal (__const wchar_t *__restrict __nptr,
wchar_t **__restrict __endptr,
int __base, int __group) __THROW;
# define __wcstoll_internal_defined 1
#endif
-#ifndef __wcstoull_internal_defined
+#if !defined __wcstoull_internal_defined \
+ && defined __OPTIMIZE__ && __GNUC__ >= 2
__extension__
extern unsigned long long int __wcstoull_internal (__const wchar_t *
__restrict __nptr,
@@ -545,12 +567,12 @@ extern __inline float
__NTH (wcstof (__const wchar_t *__restrict __nptr,
wchar_t **__restrict __endptr))
{ return __wcstof_internal (__nptr, __endptr, 0); }
+# ifndef __LDBL_COMPAT
extern __inline long double
__NTH (wcstold (__const wchar_t *__restrict __nptr,
wchar_t **__restrict __endptr))
{ return __wcstold_internal (__nptr, __endptr, 0); }
-
-
+# endif
__extension__
extern __inline long long int
__NTH (wcstoq (__const wchar_t *__restrict __nptr,
@@ -578,6 +600,13 @@ extern wchar_t *wcpncpy (wchar_t *__dest, __const wchar_t *__src, size_t __n)
/* Wide character I/O functions. */
+
+#ifdef __USE_GNU
+/* Like OPEN_MEMSTREAM, but the stream is wide oriented and produces
+ a wide character string. */
+extern __FILE *open_wmemstream (wchar_t **__bufloc, size_t *__sizeloc) __THROW;
+#endif
+
#if defined __USE_ISOC99 || defined __USE_UNIX98
__BEGIN_NAMESPACE_C99
@@ -817,6 +846,15 @@ extern size_t wcsftime_l (wchar_t *__restrict __s, size_t __maxsize,
# include <wctype.h>
#endif
+/* Define some macros helping to catch buffer overflows. */
+#if __USE_FORTIFY_LEVEL > 0 && !defined __cplusplus
+# include <bits/wchar2.h>
+#endif
+
+#ifdef __LDBL_COMPAT
+# include <bits/wchar-ldbl.h>
+#endif
+
__END_DECLS
#endif /* _WCHAR_H defined */
diff --git a/wcsmbs/wcrtomb.c b/wcsmbs/wcrtomb.c
index 38144796f8..aa51b6891b 100644
--- a/wcsmbs/wcrtomb.c
+++ b/wcsmbs/wcrtomb.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996,1997,1998,2000,2002 Free Software Foundation, Inc.
+/* Copyright (C) 1996,1997,1998,2000,2002,2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -17,6 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <assert.h>
#include <dlfcn.h>
#include <errno.h>
#include <gconv.h>
@@ -24,7 +25,7 @@
#include <wchar.h>
#include <wcsmbsload.h>
-#include <assert.h>
+#include <sysdep.h>
#ifndef EILSEQ
# define EILSEQ EINVAL
@@ -60,20 +61,24 @@ __wcrtomb (char *s, wchar_t wc, mbstate_t *ps)
}
/* Tell where we want to have the result. */
- data.__outbuf = s;
- data.__outbufend = s + MB_CUR_MAX;
+ data.__outbuf = (unsigned char *) s;
+ data.__outbufend = (unsigned char *) s + MB_CUR_MAX;
/* Get the conversion functions. */
fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE));
+ __gconv_fct fct = fcts->tomb->__fct;
+#ifdef PTR_DEMANGLE
+ if (fcts->tomb->__shlib_handle != NULL)
+ PTR_DEMANGLE (fct);
+#endif
/* If WC is the NUL character we write into the output buffer the byte
sequence necessary for PS to get into the initial state, followed
by a NUL byte. */
if (wc == L'\0')
{
- status = DL_CALL_FCT (fcts->tomb->__fct,
- (fcts->tomb, &data, NULL, NULL,
- NULL, &dummy, 1, 1));
+ status = DL_CALL_FCT (fct, (fcts->tomb, &data, NULL, NULL,
+ NULL, &dummy, 1, 1));
if (status == __GCONV_OK || status == __GCONV_EMPTY_INPUT)
*data.__outbuf++ = '\0';
@@ -83,7 +88,7 @@ __wcrtomb (char *s, wchar_t wc, mbstate_t *ps)
/* Do a normal conversion. */
const unsigned char *inbuf = (const unsigned char *) &wc;
- status = DL_CALL_FCT (fcts->tomb->__fct,
+ status = DL_CALL_FCT (fct,
(fcts->tomb, &data, &inbuf,
inbuf + sizeof (wchar_t), NULL, &dummy, 0, 1));
}
diff --git a/wcsmbs/wcscoll.c b/wcsmbs/wcscoll.c
index ed6db06e4e..ae3d48c623 100644
--- a/wcsmbs/wcscoll.c
+++ b/wcsmbs/wcscoll.c
@@ -22,12 +22,11 @@
#define STRING_TYPE wchar_t
#define USTRING_TYPE wint_t
-#define STRCOLL __wcscoll
+#define STRCOLL wcscoll
#define STRCOLL_L __wcscoll_l
#include "../string/strcoll.c"
#ifndef USE_IN_EXTENDED_LOCALE_MODEL
-weak_alias (__wcscoll, wcscoll)
libc_hidden_weak (wcscoll)
#endif
diff --git a/wcsmbs/wcsmbsload.c b/wcsmbs/wcsmbsload.c
index 1d7374b386..e82b1ffaff 100644
--- a/wcsmbs/wcsmbsload.c
+++ b/wcsmbs/wcsmbsload.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998,1999,2000,2001,2002,2004 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2002,2004,2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
@@ -29,7 +29,7 @@
/* These are the descriptions for the default conversion functions. */
-static struct __gconv_step to_wc =
+static const struct __gconv_step to_wc =
{
.__shlib_handle = NULL,
.__modname = NULL,
@@ -48,7 +48,7 @@ static struct __gconv_step to_wc =
.__data = NULL
};
-static struct __gconv_step to_mb =
+static const struct __gconv_step to_mb =
{
.__shlib_handle = NULL,
.__modname = NULL,
@@ -71,9 +71,9 @@ static struct __gconv_step to_mb =
/* For the default locale we only have to handle ANSI_X3.4-1968. */
const struct gconv_fcts __wcsmbs_gconv_fcts_c =
{
- .towc = &to_wc,
+ .towc = (struct __gconv_step *) &to_wc,
.towc_nsteps = 1,
- .tomb = &to_mb,
+ .tomb = (struct __gconv_step *) &to_mb,
.tomb_nsteps = 1
};
diff --git a/wcsmbs/wcsncpy.c b/wcsmbs/wcsncpy.c
index 8469d94d79..06a20d2333 100644
--- a/wcsmbs/wcsncpy.c
+++ b/wcsmbs/wcsncpy.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 1996, 1997, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
@@ -22,7 +22,7 @@
/* Copy no more than N wide-characters of SRC to DEST. */
wchar_t *
-wcsncpy (dest, src, n)
+__wcsncpy (dest, src, n)
wchar_t *dest;
const wchar_t *src;
size_t n;
@@ -84,3 +84,4 @@ wcsncpy (dest, src, n)
return s;
}
+weak_alias (__wcsncpy, wcsncpy)
diff --git a/wcsmbs/wcsnrtombs.c b/wcsmbs/wcsnrtombs.c
index 0ff26d6671..171fc3c227 100644
--- a/wcsmbs/wcsnrtombs.c
+++ b/wcsmbs/wcsnrtombs.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2000, 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2000, 2002, 2003, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.org>, 1996.
@@ -17,13 +17,14 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <assert.h>
#include <dlfcn.h>
#include <errno.h>
#include <gconv.h>
#include <wchar.h>
#include <wcsmbsload.h>
-#include <assert.h>
+#include <sysdep.h>
#ifndef EILSEQ
# define EILSEQ EINVAL
@@ -67,6 +68,11 @@ __wcsnrtombs (dst, src, nwc, len, ps)
/* Get the structure with the function pointers. */
tomb = fcts->tomb;
+ __gconv_fct fct = tomb->__fct;
+#ifdef PTR_DEMANGLE
+ if (tomb->__shlib_handle != NULL)
+ PTR_DEMANGLE (fct);
+#endif
/* We have to handle DST == NULL special. */
if (dst == NULL)
@@ -82,10 +88,9 @@ __wcsnrtombs (dst, src, nwc, len, ps)
{
data.__outbuf = buf;
- status = DL_CALL_FCT (tomb->__fct,
- (tomb, &data, &inbuf,
- (const unsigned char *) srcend, NULL,
- &dummy, 0, 1));
+ status = DL_CALL_FCT (fct, (tomb, &data, &inbuf,
+ (const unsigned char *) srcend, NULL,
+ &dummy, 0, 1));
/* Count the number of bytes. */
result += data.__outbuf - buf;
@@ -104,13 +109,12 @@ __wcsnrtombs (dst, src, nwc, len, ps)
of the string. */
size_t dummy;
- data.__outbuf = dst;
- data.__outbufend = dst + len;
+ data.__outbuf = (unsigned char *) dst;
+ data.__outbufend = (unsigned char *) dst + len;
- status = DL_CALL_FCT (tomb->__fct,
- (tomb, &data, (const unsigned char **) src,
- (const unsigned char *) srcend, NULL,
- &dummy, 0, 1));
+ status = DL_CALL_FCT (fct, (tomb, &data, (const unsigned char **) src,
+ (const unsigned char *) srcend, NULL,
+ &dummy, 0, 1));
/* Count the number of bytes. */
result = data.__outbuf - (unsigned char *) dst;
diff --git a/wcsmbs/wcsrtombs.c b/wcsmbs/wcsrtombs.c
index 8b444ed8a2..5973fd9303 100644
--- a/wcsmbs/wcsrtombs.c
+++ b/wcsmbs/wcsrtombs.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2000, 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2000, 2002, 2003, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.org>, 1996.
@@ -17,6 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <assert.h>
#include <dlfcn.h>
#include <errno.h>
#include <stdlib.h>
@@ -24,7 +25,7 @@
#include <wchar.h>
#include <wcsmbsload.h>
-#include <assert.h>
+#include <sysdep.h>
#ifndef EILSEQ
# define EILSEQ EINVAL
@@ -59,6 +60,11 @@ __wcsrtombs (dst, src, len, ps)
/* Get the structure with the function pointers. */
tomb = fcts->tomb;
+ __gconv_fct fct = tomb->__fct;
+#ifdef PTR_DEMANGLE
+ if (tomb->__shlib_handle != NULL)
+ PTR_DEMANGLE (fct);
+#endif
/* We have to handle DST == NULL special. */
if (dst == NULL)
@@ -79,10 +85,9 @@ __wcsrtombs (dst, src, len, ps)
{
data.__outbuf = buf;
- status = DL_CALL_FCT (tomb->__fct,
- (tomb, &data, &inbuf,
- (const unsigned char *) srcend, NULL,
- &dummy, 0, 1));
+ status = DL_CALL_FCT (fct, (tomb, &data, &inbuf,
+ (const unsigned char *) srcend, NULL,
+ &dummy, 0, 1));
/* Count the number of bytes. */
result += data.__outbuf - buf;
@@ -105,13 +110,12 @@ __wcsrtombs (dst, src, len, ps)
const wchar_t *srcend = *src + __wcsnlen (*src, len) + 1;
size_t dummy;
- data.__outbuf = dst;
- data.__outbufend = dst + len;
+ data.__outbuf = (unsigned char *) dst;
+ data.__outbufend = (unsigned char *) dst + len;
- status = DL_CALL_FCT (tomb->__fct,
- (tomb, &data, (const unsigned char **) src,
- (const unsigned char *) srcend, NULL,
- &dummy, 0, 1));
+ status = DL_CALL_FCT (fct, (tomb, &data, (const unsigned char **) src,
+ (const unsigned char *) srcend, NULL,
+ &dummy, 0, 1));
/* Count the number of bytes. */
result = data.__outbuf - (unsigned char *) dst;
diff --git a/wcsmbs/wcstol.c b/wcsmbs/wcstol.c
new file mode 100644
index 0000000000..b238d04b19
--- /dev/null
+++ b/wcsmbs/wcstol.c
@@ -0,0 +1,23 @@
+/* Function to parse a `long int' from text.
+ Copyright (C) 1996, 1997, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
+
+ 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. */
+
+#define USE_WIDE_CHAR 1
+
+#include <stdlib/strtol.c>
diff --git a/wcsmbs/wcstol_l.c b/wcsmbs/wcstol_l.c
new file mode 100644
index 0000000000..3d3bf76ea6
--- /dev/null
+++ b/wcsmbs/wcstol_l.c
@@ -0,0 +1,30 @@
+/* Convert string representing a number to integer value, using given locale.
+ Copyright (C) 1997, 2002, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+ 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. */
+
+#define __need_wchar_t
+#include <stddef.h>
+#include <locale.h>
+
+#define USE_WIDE_CHAR 1
+
+extern long int ____wcstol_l_internal (const wchar_t *, wchar_t **, int, int,
+ __locale_t);
+
+#include <stdlib/strtol_l.c>
diff --git a/wcsmbs/wcstoll.c b/wcsmbs/wcstoll.c
new file mode 100644
index 0000000000..b666762da4
--- /dev/null
+++ b/wcsmbs/wcstoll.c
@@ -0,0 +1,25 @@
+/* Function to parse a `long long int' from text.
+ Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
+
+ 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. */
+
+#define QUAD 1
+
+#include "wcstol.c"
+
+weak_alias (wcstoll, wcstoq)
diff --git a/wcsmbs/wcstoll_l.c b/wcsmbs/wcstoll_l.c
new file mode 100644
index 0000000000..f1a4ca1623
--- /dev/null
+++ b/wcsmbs/wcstoll_l.c
@@ -0,0 +1,30 @@
+/* Convert string representing a number to integer value, using given locale.
+ Copyright (C) 1997, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+ 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. */
+
+#define __need_wchar_t
+#include <stddef.h>
+#include <locale.h>
+
+#define QUAD 1
+
+extern long long int ____wcstoll_l_internal (const wchar_t *, wchar_t **,
+ int, int, __locale_t);
+
+#include <wcstol_l.c>
diff --git a/wcsmbs/wcstoul.c b/wcsmbs/wcstoul.c
new file mode 100644
index 0000000000..f25f7a9bff
--- /dev/null
+++ b/wcsmbs/wcstoul.c
@@ -0,0 +1,23 @@
+/* Function to parse an `unsigned long int' from text.
+ Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
+
+ 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. */
+
+#define UNSIGNED 1
+
+#include "wcstol.c"
diff --git a/wcsmbs/wcstoul_l.c b/wcsmbs/wcstoul_l.c
new file mode 100644
index 0000000000..25058de817
--- /dev/null
+++ b/wcsmbs/wcstoul_l.c
@@ -0,0 +1,30 @@
+/* Convert string representing a number to integer value, using given locale.
+ Copyright (C) 1997, 2002, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+ 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. */
+
+#define __need_wchar_t
+#include <stddef.h>
+#include <locale.h>
+
+#define UNSIGNED 1
+
+extern unsigned long int ____wcstoul_l_internal (const wchar_t *, wchar_t **,
+ int, int, __locale_t);
+
+#include "wcstol_l.c"
diff --git a/wcsmbs/wcstoull.c b/wcsmbs/wcstoull.c
new file mode 100644
index 0000000000..a69a103515
--- /dev/null
+++ b/wcsmbs/wcstoull.c
@@ -0,0 +1,25 @@
+/* Function to parse an `unsigned long long int' from text.
+ Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
+
+ 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. */
+
+#define QUAD 1
+
+#include "wcstoul.c"
+
+weak_alias (wcstoull, wcstouq)
diff --git a/wcsmbs/wcstoull_l.c b/wcsmbs/wcstoull_l.c
new file mode 100644
index 0000000000..32bc3c4bb9
--- /dev/null
+++ b/wcsmbs/wcstoull_l.c
@@ -0,0 +1,31 @@
+/* Convert string representing a number to integer value, using given locale.
+ Copyright (C) 1997, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+ 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. */
+
+#define __need_wchar_t
+#include <stddef.h>
+#include <locale.h>
+
+#define UNSIGNED 1
+
+extern unsigned long long int ____wcstoull_l_internal (const wchar_t *,
+ wchar_t **, int, int,
+ __locale_t);
+
+#include <wcstoll_l.c>
diff --git a/wcsmbs/wctob.c b/wcsmbs/wctob.c
index b85ba6dd8f..cbaac53367 100644
--- a/wcsmbs/wctob.c
+++ b/wcsmbs/wctob.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2000, 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2000, 2002, 2003, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
@@ -24,12 +24,14 @@
#include <wchar.h>
#include <wcsmbsload.h>
+#include <sysdep.h>
+
int
wctob (c)
wint_t c;
{
- char buf[MB_LEN_MAX];
+ unsigned char buf[MB_LEN_MAX];
struct __gconv_step_data data;
wchar_t inbuf[1];
wchar_t *inptr = inbuf;
@@ -40,6 +42,11 @@ wctob (c)
if (c == WEOF)
return EOF;
+ /* We know that only ASCII compatible encodings are used for the
+ locale and that the wide character encoding is ISO 10646. */
+ if (c >= L'\0' && c <= L'\x7f')
+ return (int) c;
+
/* Tell where we want the result. */
data.__outbuf = buf;
data.__outbufend = buf + MB_LEN_MAX;
@@ -59,7 +66,12 @@ wctob (c)
inbuf[0] = c;
const unsigned char *argptr = (const unsigned char *) inptr;
- status = DL_CALL_FCT (fcts->tomb->__fct,
+ __gconv_fct fct = fcts->tomb->__fct;
+#ifdef PTR_DEMANGLE
+ if (fcts->tomb->__shlib_handle != NULL)
+ PTR_DEMANGLE (fct);
+#endif
+ status = DL_CALL_FCT (fct,
(fcts->tomb, &data, &argptr,
argptr + sizeof (inbuf[0]), NULL, &dummy, 0, 1));
@@ -69,5 +81,5 @@ wctob (c)
|| data.__outbuf != (unsigned char *) (buf + 1))
return EOF;
- return (unsigned char) buf[0];
+ return buf[0];
}