Mercurial > gnulib
comparison lib/wcrtomb.c @ 40137:9e646f080d9e
wcrtomb: Work around bug on Android 4.3.
* m4/wcrtomb.m4 (gl_FUNC_WCRTOMB): Test also whether wcrtomb works in
the C locale.
* lib/wcrtomb.c (wcrtomb): Provide alternate implementation for Android,
which does not have the 'wctomb' function.
* doc/posix-functions/wcrtomb.texi: Mention the Android bug.
* tests/test-wcrtomb.c (main): Accept argument '5'.
* tests/test-wcrtomb.sh: Add tests in the POSIX locale.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 25 Jan 2019 23:39:28 +0100 |
parents | b06060465f09 |
children |
comparison
equal
deleted
inserted
replaced
40136:06c22cab9098 | 40137:9e646f080d9e |
---|---|
25 | 25 |
26 | 26 |
27 size_t | 27 size_t |
28 wcrtomb (char *s, wchar_t wc, mbstate_t *ps) | 28 wcrtomb (char *s, wchar_t wc, mbstate_t *ps) |
29 { | 29 { |
30 /* This implementation of wcrtomb on top of wctomb() supports only | 30 /* This implementation of wcrtomb supports only stateless encodings. |
31 stateless encodings. ps must be in the initial state. */ | 31 ps must be in the initial state. */ |
32 if (ps != NULL && !mbsinit (ps)) | 32 if (ps != NULL && !mbsinit (ps)) |
33 { | 33 { |
34 errno = EINVAL; | 34 errno = EINVAL; |
35 return (size_t)(-1); | 35 return (size_t)(-1); |
36 } | 36 } |
38 if (s == NULL) | 38 if (s == NULL) |
39 /* We know the NUL wide character corresponds to the NUL character. */ | 39 /* We know the NUL wide character corresponds to the NUL character. */ |
40 return 1; | 40 return 1; |
41 else | 41 else |
42 { | 42 { |
43 #if defined __ANDROID__ | |
44 /* Implement consistently with mbrtowc(): through a 1:1 correspondence, | |
45 as in ISO-8859-1. */ | |
46 if (wc >= 0 && wc <= 0xff) | |
47 { | |
48 *s = (unsigned char) wc; | |
49 return 1; | |
50 } | |
51 #else | |
52 /* Implement on top of wctomb(). */ | |
43 int ret = wctomb (s, wc); | 53 int ret = wctomb (s, wc); |
44 | 54 |
45 if (ret >= 0) | 55 if (ret >= 0) |
46 return ret; | 56 return ret; |
57 #endif | |
47 else | 58 else |
48 { | 59 { |
49 errno = EILSEQ; | 60 errno = EILSEQ; |
50 return (size_t)(-1); | 61 return (size_t)(-1); |
51 } | 62 } |