diff options
author | Bruno Haible <bruno@clisp.org> | 2023-03-30 13:25:20 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2023-03-30 19:39:46 +0200 |
commit | 11fe27f76c63c14b6f88c815b656f3f72d37ea41 (patch) | |
tree | 8a4661c83efd2d544ff729373b33955d54054d47 /tests | |
parent | 60745587a2e0073df7fe4cb1ec462f423c8f2bb2 (diff) | |
download | gnulib-11fe27f76c63c14b6f88c815b656f3f72d37ea41.tar.gz |
btowc: Fix behaviour in the C locale.
* lib/btowc.c: Include <string.h>
(btowc): Use mbrtowc instead of mbtowc when possible.
* m4/btowc.m4 (gl_FUNC_BTOWC): Test for the mingw bug in the C locale.
Invoke gl_MBRTOWC_C_LOCALE. If mbrtowc is buggy in the C locale,
override also btowc.
(gl_PREREQ_BTOWC): Test whether mbrtowc exists.
* modules/btowc (Files): Add m4/mbrtowc.m4.
(Depends-on): Add mbrtowc.
* tests/test-btowc.c (main): Add a test of the C locale, based on
tests/test-mbrtowc.c.
* tests/test-btowc3.sh: New file, based on tests/test-mbrtowc5.sh.
* modules/btowc-tests (Files): Add it.
(Makefile.am): Test it.
* doc/posix-functions/btowc.texi: Mention the two C locale behaviour
bugs and that they are worked around.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-btowc.c | 19 | ||||
-rwxr-xr-x | tests/test-btowc3.sh | 9 |
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/test-btowc.c b/tests/test-btowc.c index 849db470f4..e5918c36e9 100644 --- a/tests/test-btowc.c +++ b/tests/test-btowc.c @@ -57,6 +57,25 @@ main (int argc, char *argv[]) for (c = 0x80; c < 0x100; c++) ASSERT (btowc (c) == WEOF); return 0; + + case '3': + /* C or POSIX locale. */ + for (c = 0; c < 0x100; c++) + if (c != 0) + { + /* We are testing all nonnull bytes. */ + wint_t wc = btowc (c); + /* POSIX:2018 says: "In the POSIX locale, btowc() shall not return + WEOF if c has a value in the range 0 to 255 inclusive." */ + if (c < 0x80) + /* c is an ASCII character. */ + ASSERT (wc == c); + else + /* On most platforms, the bytes 0x80..0xFF map to U+0080..U+00FF. + But on musl libc, the bytes 0x80..0xFF map to U+DF80..U+DFFF. */ + ASSERT (wc == c || wc == 0xDF00 + c); + } + return 0; } return 1; diff --git a/tests/test-btowc3.sh b/tests/test-btowc3.sh new file mode 100755 index 0000000000..ee9e143c1c --- /dev/null +++ b/tests/test-btowc3.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# Test whether the POSIX locale has encoding errors. +LC_ALL=C \ +${CHECKER} ./test-btowc${EXEEXT} 3 || exit 1 +LC_ALL=POSIX \ +${CHECKER} ./test-btowc${EXEEXT} 3 || exit 1 + +exit 0 |