summaryrefslogtreecommitdiffstats
path: root/gl/wcrtomb.c
diff options
context:
space:
mode:
authorKristian Schuster <116557017+KriSchu@users.noreply.github.com>2023-02-19 23:49:18 +0100
committerKristian Schuster <116557017+KriSchu@users.noreply.github.com>2023-02-19 23:49:18 +0100
commita0d42777217296c0a7bdb1e1be8d8f6de1b24dd7 (patch)
tree8effe94c57b2f9796ba36090b07551baa8f1e1cb /gl/wcrtomb.c
parentca3d59cd6918c9e2739e783b721d4c1122640fd3 (diff)
parentc07206f2ccc2356aa74bc6813a94c2190017d44e (diff)
downloadmonitoring-plugins-a0d4277.tar.gz
Merge remote-tracking branch 'origin/master' into feature_check_disk_add_ignore_missing_option
Diffstat (limited to 'gl/wcrtomb.c')
-rw-r--r--gl/wcrtomb.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/gl/wcrtomb.c b/gl/wcrtomb.c
index da42809b..48a6c8eb 100644
--- a/gl/wcrtomb.c
+++ b/gl/wcrtomb.c
@@ -1,19 +1,19 @@
1/* Convert wide character to multibyte character. 1/* Convert wide character to multibyte character.
2 Copyright (C) 2008-2013 Free Software Foundation, Inc. 2 Copyright (C) 2008-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008. 3 Written by Bruno Haible <bruno@clisp.org>, 2008.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU Lesser General Public License as
7 the Free Software Foundation; either version 3 of the License, or 7 published by the Free Software Foundation; either version 2.1 of the
8 (at your option) any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU Lesser General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18#include <config.h> 18#include <config.h>
19 19
@@ -26,20 +26,46 @@
26 26
27size_t 27size_t
28wcrtomb (char *s, wchar_t wc, mbstate_t *ps) 28wcrtomb (char *s, wchar_t wc, mbstate_t *ps)
29#undef wcrtomb
29{ 30{
30 /* This implementation of wcrtomb on top of wctomb() supports only 31 /* This implementation of wcrtomb supports only stateless encodings.
31 stateless encodings. ps must be in the initial state. */ 32 ps must be in the initial state. */
32 if (ps != NULL && !mbsinit (ps)) 33 if (ps != NULL && !mbsinit (ps))
33 { 34 {
34 errno = EINVAL; 35 errno = EINVAL;
35 return (size_t)(-1); 36 return (size_t)(-1);
36 } 37 }
37 38
39#if !HAVE_WCRTOMB /* IRIX 6.5 */ \
40 || WCRTOMB_RETVAL_BUG /* Solaris 11.3, MSVC */ \
41 || WCRTOMB_C_LOCALE_BUG /* Android */
38 if (s == NULL) 42 if (s == NULL)
39 /* We know the NUL wide character corresponds to the NUL character. */ 43 /* We know the NUL wide character corresponds to the NUL character. */
40 return 1; 44 return 1;
41 else 45 else
46#endif
42 { 47 {
48#if HAVE_WCRTOMB
49# if WCRTOMB_C_LOCALE_BUG /* Android */
50 /* Implement consistently with mbrtowc(): through a 1:1 correspondence,
51 as in ISO-8859-1. */
52 if (wc >= 0 && wc <= 0xff)
53 {
54 *s = (unsigned char) wc;
55 return 1;
56 }
57 else
58 {
59 errno = EILSEQ;
60 return (size_t)(-1);
61 }
62# else
63 return wcrtomb (s, wc, ps);
64# endif
65#else /* IRIX 6.5 */
66 /* Fallback for platforms that don't have wcrtomb().
67 Implement on top of wctomb().
68 This code is not multithread-safe. */
43 int ret = wctomb (s, wc); 69 int ret = wctomb (s, wc);
44 70
45 if (ret >= 0) 71 if (ret >= 0)
@@ -49,5 +75,6 @@ wcrtomb (char *s, wchar_t wc, mbstate_t *ps)
49 errno = EILSEQ; 75 errno = EILSEQ;
50 return (size_t)(-1); 76 return (size_t)(-1);
51 } 77 }
78#endif
52 } 79 }
53} 80}