diff options
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | wcsmbs/Makefile | 5 | ||||
-rw-r--r-- | wcsmbs/c32rtomb.c | 32 | ||||
-rw-r--r-- | wcsmbs/mbrtoc32.c | 32 | ||||
-rw-r--r-- | wcsmbs/mbrtowc.c | 5 | ||||
-rw-r--r-- | wcsmbs/tst-c32-state.c | 44 | ||||
-rw-r--r-- | wcsmbs/wcrtomb.c | 5 |
7 files changed, 124 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog index c3fbad184e..073d034c40 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2018-10-22 Joseph Myers <joseph@codesourcery.com> + + [BZ #23793] + * wcsmbs/c32rtomb.c: New file. + * wcsmbs/mbrtoc32.c: Likewise. + * wcsmbs/tst-c32-state.c: Likewise. + * wcsmbs/mbrtowc.c (mbrtoc32): Do not define as alias. + * wcsmbs/wcrtomb.c (c32rtomb): Likewise. + * wcsmbs/Makefile (routines): Add mbrtoc32 and c32rtomb. + (tests): Add tst-c32-state. + [$(run-built-tests) = yes] ($(objpfx)tst-c32-state.out): Depend on + $(gen-locales). + 2018-10-21 H.J. Lu <hongjiu.lu@intel.com> * sysdeps/x86/hp-timing.h: Don't include <x86intrin.h>. diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile index a58d36ff8f..cdd8dd5c50 100644 --- a/wcsmbs/Makefile +++ b/wcsmbs/Makefile @@ -42,7 +42,7 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \ wcsmbsload mbsrtowcs_l \ isoc99_wscanf isoc99_vwscanf isoc99_fwscanf isoc99_vfwscanf \ isoc99_swscanf isoc99_vswscanf \ - mbrtoc16 c16rtomb + mbrtoc16 c16rtomb mbrtoc32 c32rtomb strop-tests := wcscmp wcsncmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen \ wcpcpy wcsncpy wcpncpy wcscat wcsncat wcschrnul wcsspn wcspbrk \ @@ -51,7 +51,7 @@ tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \ tst-wcrtomb tst-wcpncpy tst-mbsrtowcs tst-wchar-h tst-mbrtowc2 \ tst-c16c32-1 wcsatcliff tst-wcstol-locale tst-wcstod-nan-locale \ tst-wcstod-round test-char-types tst-fgetwc-after-eof \ - tst-wcstod-nan-sign tst-c16-surrogate \ + tst-wcstod-nan-sign tst-c16-surrogate tst-c32-state \ $(addprefix test-,$(strop-tests)) include ../Rules @@ -70,6 +70,7 @@ $(objpfx)wcsmbs-tst1.out: $(gen-locales) $(objpfx)tst-wcstol-locale.out: $(gen-locales) $(objpfx)tst-wcstod-nan-locale.out: $(gen-locales) $(objpfx)tst-c16-surrogate.out: $(gen-locales) +$(objpfx)tst-c32-state.out: $(gen-locales) endif $(objpfx)tst-wcstod-round: $(libm) diff --git a/wcsmbs/c32rtomb.c b/wcsmbs/c32rtomb.c new file mode 100644 index 0000000000..f370ae28ad --- /dev/null +++ b/wcsmbs/c32rtomb.c @@ -0,0 +1,32 @@ +/* Convert char32_t to multibyte. + Copyright (C) 2018 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, see + <http://www.gnu.org/licenses/>. */ + +#include <uchar.h> +#include <wchar.h> + + +/* This is the private state used if PS is NULL. */ +static mbstate_t state; + +size_t +c32rtomb (char *s, char32_t c32, mbstate_t *ps) +{ + if (ps == NULL) + ps = &state; + return wcrtomb (s, c32, ps); +} diff --git a/wcsmbs/mbrtoc32.c b/wcsmbs/mbrtoc32.c new file mode 100644 index 0000000000..d3f6ef8e5d --- /dev/null +++ b/wcsmbs/mbrtoc32.c @@ -0,0 +1,32 @@ +/* Convert multibyte to char32_t. + Copyright (C) 2018 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, see + <http://www.gnu.org/licenses/>. */ + +#include <uchar.h> +#include <wchar.h> + + +/* This is the private state used if PS is NULL. */ +static mbstate_t state; + +size_t +mbrtoc32 (char32_t *pc32, const char *s, size_t n, mbstate_t *ps) +{ + if (ps == NULL) + ps = &state; + return mbrtowc ((wchar_t *) pc32, s, n, ps); +} diff --git a/wcsmbs/mbrtowc.c b/wcsmbs/mbrtowc.c index 954933d068..410f6855cd 100644 --- a/wcsmbs/mbrtowc.c +++ b/wcsmbs/mbrtowc.c @@ -122,8 +122,3 @@ __mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) libc_hidden_def (__mbrtowc) weak_alias (__mbrtowc, mbrtowc) libc_hidden_weak (mbrtowc) - -/* There should be no difference between the UTF-32 handling required - by mbrtoc32 and the wchar_t handling which has long since been - implemented in mbrtowc. */ -weak_alias (__mbrtowc, mbrtoc32) diff --git a/wcsmbs/tst-c32-state.c b/wcsmbs/tst-c32-state.c new file mode 100644 index 0000000000..68f646c801 --- /dev/null +++ b/wcsmbs/tst-c32-state.c @@ -0,0 +1,44 @@ +/* Test mbrtowc and mbrtoc32 do not share state (bug 23793). + Copyright (C) 2018 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, see + <http://www.gnu.org/licenses/>. */ + +#include <locale.h> +#include <uchar.h> +#include <wchar.h> +#include <support/check.h> + +static int +do_test (void) +{ + TEST_VERIFY_EXIT (setlocale (LC_ALL, "de_DE.UTF-8") != NULL); + const char buf[] = "\u00ff"; + wchar_t wc = 0; + char32_t c32 = 0; + size_t ret = mbrtowc (&wc, buf, 1, NULL); + TEST_COMPARE (ret, (size_t) -2); + ret = mbrtoc32 (&c32, buf, 1, NULL); + TEST_COMPARE (ret, (size_t) -2); + ret = mbrtowc (&wc, buf + 1, 1, NULL); + TEST_COMPARE (ret, 1); + TEST_COMPARE (wc, 0xff); + ret = mbrtoc32 (&c32, buf + 1, 1, NULL); + TEST_COMPARE (ret, 1); + TEST_COMPARE (c32, 0xff); + return 0; +} + +#include <support/test-driver.c> diff --git a/wcsmbs/wcrtomb.c b/wcsmbs/wcrtomb.c index 23f122599a..b10295e939 100644 --- a/wcsmbs/wcrtomb.c +++ b/wcsmbs/wcrtomb.c @@ -113,8 +113,3 @@ __wcrtomb (char *s, wchar_t wc, mbstate_t *ps) } weak_alias (__wcrtomb, wcrtomb) libc_hidden_weak (wcrtomb) - -/* There should be no difference between the UTF-32 handling required - by c32rtomb and the wchar_t handling which has long since been - implemented in wcrtomb. */ -weak_alias (__wcrtomb, c32rtomb) |