diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-08-19 23:27:12 +0200 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-08-19 23:27:12 +0200 |
commit | 26fbe7f1e68bb0c96da32491efcf3696fe6c299b (patch) | |
tree | c4d95289187a64e9c7517bf73d8208026c3d2fb3 /gl/mbrtowc.c | |
parent | 5f79e3e9f62ca5487d9881973149136ba1d19d3e (diff) | |
download | monitoring-plugins-26fbe7f1e68bb0c96da32491efcf3696fe6c299b.tar.gz |
Sync with the latest Gnulib code (6f2d632)
Diffstat (limited to 'gl/mbrtowc.c')
-rw-r--r-- | gl/mbrtowc.c | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/gl/mbrtowc.c b/gl/mbrtowc.c index 5c2650e9..5ee44aea 100644 --- a/gl/mbrtowc.c +++ b/gl/mbrtowc.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* Convert multibyte character to wide character. | 1 | /* Convert multibyte character to wide character. |
2 | Copyright (C) 1999-2002, 2005-2010 Free Software Foundation, Inc. | 2 | Copyright (C) 1999-2002, 2005-2013 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 program is free software: you can redistribute it and/or modify |
@@ -40,9 +40,6 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) | |||
40 | { | 40 | { |
41 | char *pstate = (char *)ps; | 41 | char *pstate = (char *)ps; |
42 | 42 | ||
43 | if (pstate == NULL) | ||
44 | pstate = internal_state; | ||
45 | |||
46 | if (s == NULL) | 43 | if (s == NULL) |
47 | { | 44 | { |
48 | pwc = NULL; | 45 | pwc = NULL; |
@@ -54,6 +51,10 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) | |||
54 | return (size_t)(-2); | 51 | return (size_t)(-2); |
55 | 52 | ||
56 | /* Here n > 0. */ | 53 | /* Here n > 0. */ |
54 | |||
55 | if (pstate == NULL) | ||
56 | pstate = internal_state; | ||
57 | |||
57 | { | 58 | { |
58 | size_t nstate = pstate[0]; | 59 | size_t nstate = pstate[0]; |
59 | char buf[4]; | 60 | char buf[4]; |
@@ -91,7 +92,7 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) | |||
91 | 92 | ||
92 | /* Here m > 0. */ | 93 | /* Here m > 0. */ |
93 | 94 | ||
94 | # if __GLIBC__ | 95 | # if __GLIBC__ || defined __UCLIBC__ |
95 | /* Work around bug <http://sourceware.org/bugzilla/show_bug.cgi?id=9674> */ | 96 | /* Work around bug <http://sourceware.org/bugzilla/show_bug.cgi?id=9674> */ |
96 | mbtowc (NULL, NULL, 0); | 97 | mbtowc (NULL, NULL, 0); |
97 | # endif | 98 | # endif |
@@ -127,7 +128,7 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) | |||
127 | { | 128 | { |
128 | const char *encoding = locale_charset (); | 129 | const char *encoding = locale_charset (); |
129 | 130 | ||
130 | if (STREQ (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0)) | 131 | if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0)) |
131 | { | 132 | { |
132 | /* Cf. unistr/u8-mblen.c. */ | 133 | /* Cf. unistr/u8-mblen.c. */ |
133 | unsigned char c = (unsigned char) p[0]; | 134 | unsigned char c = (unsigned char) p[0]; |
@@ -184,7 +185,8 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) | |||
184 | /* As a reference for this code, you can use the GNU libiconv | 185 | /* As a reference for this code, you can use the GNU libiconv |
185 | implementation. Look for uses of the RET_TOOFEW macro. */ | 186 | implementation. Look for uses of the RET_TOOFEW macro. */ |
186 | 187 | ||
187 | if (STREQ (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0)) | 188 | if (STREQ_OPT (encoding, |
189 | "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0)) | ||
188 | { | 190 | { |
189 | if (m == 1) | 191 | if (m == 1) |
190 | { | 192 | { |
@@ -207,9 +209,12 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) | |||
207 | } | 209 | } |
208 | goto invalid; | 210 | goto invalid; |
209 | } | 211 | } |
210 | if (STREQ (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0) | 212 | if (STREQ_OPT (encoding, |
211 | || STREQ (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0) | 213 | "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0) |
212 | || STREQ (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0)) | 214 | || STREQ_OPT (encoding, |
215 | "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0) | ||
216 | || STREQ_OPT (encoding, | ||
217 | "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0)) | ||
213 | { | 218 | { |
214 | if (m == 1) | 219 | if (m == 1) |
215 | { | 220 | { |
@@ -220,7 +225,8 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) | |||
220 | } | 225 | } |
221 | goto invalid; | 226 | goto invalid; |
222 | } | 227 | } |
223 | if (STREQ (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0)) | 228 | if (STREQ_OPT (encoding, |
229 | "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0)) | ||
224 | { | 230 | { |
225 | if (m == 1) | 231 | if (m == 1) |
226 | { | 232 | { |
@@ -238,7 +244,8 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) | |||
238 | } | 244 | } |
239 | goto invalid; | 245 | goto invalid; |
240 | } | 246 | } |
241 | if (STREQ (encoding, "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0)) | 247 | if (STREQ_OPT (encoding, |
248 | "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0)) | ||
242 | { | 249 | { |
243 | if (m == 1) | 250 | if (m == 1) |
244 | { | 251 | { |
@@ -271,7 +278,7 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) | |||
271 | } | 278 | } |
272 | goto invalid; | 279 | goto invalid; |
273 | } | 280 | } |
274 | if (STREQ (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0)) | 281 | if (STREQ_OPT (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0)) |
275 | { | 282 | { |
276 | if (m == 1) | 283 | if (m == 1) |
277 | { | 284 | { |
@@ -321,7 +328,7 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) | |||
321 | size_t | 328 | size_t |
322 | rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) | 329 | rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) |
323 | { | 330 | { |
324 | # if MBRTOWC_NULL_ARG_BUG || MBRTOWC_RETVAL_BUG | 331 | # if MBRTOWC_NULL_ARG2_BUG || MBRTOWC_RETVAL_BUG |
325 | if (s == NULL) | 332 | if (s == NULL) |
326 | { | 333 | { |
327 | pwc = NULL; | 334 | pwc = NULL; |
@@ -334,7 +341,7 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) | |||
334 | { | 341 | { |
335 | static mbstate_t internal_state; | 342 | static mbstate_t internal_state; |
336 | 343 | ||
337 | /* Override mbrtowc's internal state. We can not call mbsinit() on the | 344 | /* Override mbrtowc's internal state. We cannot call mbsinit() on the |
338 | hidden internal state, but we can call it on our variable. */ | 345 | hidden internal state, but we can call it on our variable. */ |
339 | if (ps == NULL) | 346 | if (ps == NULL) |
340 | ps = &internal_state; | 347 | ps = &internal_state; |
@@ -379,7 +386,16 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) | |||
379 | return ret; | 386 | return ret; |
380 | } | 387 | } |
381 | # else | 388 | # else |
382 | return mbrtowc (pwc, s, n, ps); | 389 | { |
390 | # if MBRTOWC_NULL_ARG1_BUG | ||
391 | wchar_t dummy; | ||
392 | |||
393 | if (pwc == NULL) | ||
394 | pwc = &dummy; | ||
395 | # endif | ||
396 | |||
397 | return mbrtowc (pwc, s, n, ps); | ||
398 | } | ||
383 | # endif | 399 | # endif |
384 | } | 400 | } |
385 | 401 | ||