summaryrefslogtreecommitdiffstats
path: root/gl/mbrtowc.c
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2009-05-20 00:32:10 +0200
committerHolger Weiss <holger@zedat.fu-berlin.de>2009-05-20 00:32:10 +0200
commit50b3ff7b91e78a61aca93247bee586d6d7eb27c8 (patch)
treedb4c7eee24479ac7ee6888ce1562facf60159b71 /gl/mbrtowc.c
parent2701ccd500e60537a8c2977a81549ff33eeaef3f (diff)
downloadmonitoring-plugins-50b3ff7b91e78a61aca93247bee586d6d7eb27c8.tar.gz
Sync with the latest Gnulib code (cb75dc5)
Signed-off-by: Holger Weiss <holger@zedat.fu-berlin.de>
Diffstat (limited to 'gl/mbrtowc.c')
-rw-r--r--gl/mbrtowc.c47
1 files changed, 42 insertions, 5 deletions
diff --git a/gl/mbrtowc.c b/gl/mbrtowc.c
index 603f0060..0fec5f1c 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-2008 Free Software Foundation, Inc. 2 Copyright (C) 1999-2002, 2005-2009 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
@@ -89,7 +89,7 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
89 return (size_t)(-1); 89 return (size_t)(-1);
90 } 90 }
91 91
92 /* Here 0 < m 4. */ 92 /* Here m > 0. */
93 93
94# if __GLIBC__ 94# if __GLIBC__
95 /* Work around bug <http://sourceware.org/bugzilla/show_bug.cgi?id=9674> */ 95 /* Work around bug <http://sourceware.org/bugzilla/show_bug.cgi?id=9674> */
@@ -118,7 +118,7 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
118 lack mbrtowc(), we use the second approach. 118 lack mbrtowc(), we use the second approach.
119 The possible encodings are: 119 The possible encodings are:
120 - 8-bit encodings, 120 - 8-bit encodings,
121 - EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, SJIS, 121 - EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, GB18030, SJIS,
122 - UTF-8. 122 - UTF-8.
123 Use specialized code for each. */ 123 Use specialized code for each. */
124 if (m >= 4 || m >= MB_CUR_MAX) 124 if (m >= 4 || m >= MB_CUR_MAX)
@@ -238,6 +238,39 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
238 } 238 }
239 goto invalid; 239 goto invalid;
240 } 240 }
241 if (STREQ (encoding, "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0))
242 {
243 if (m == 1)
244 {
245 unsigned char c = (unsigned char) p[0];
246
247 if ((c >= 0x90 && c <= 0xe3) || (c >= 0xf8 && c <= 0xfe))
248 goto incomplete;
249 }
250 else /* m == 2 || m == 3 */
251 {
252 unsigned char c = (unsigned char) p[0];
253
254 if (c >= 0x90 && c <= 0xe3)
255 {
256 unsigned char c2 = (unsigned char) p[1];
257
258 if (c2 >= 0x30 && c2 <= 0x39)
259 {
260 if (m == 2)
261 goto incomplete;
262 else /* m == 3 */
263 {
264 unsigned char c3 = (unsigned char) p[2];
265
266 if (c3 >= 0x81 && c3 <= 0xfe)
267 goto incomplete;
268 }
269 }
270 }
271 }
272 goto invalid;
273 }
241 if (STREQ (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0)) 274 if (STREQ (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0))
242 { 275 {
243 if (m == 1) 276 if (m == 1)
@@ -258,10 +291,14 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
258 incomplete: 291 incomplete:
259 { 292 {
260 size_t k = nstate; 293 size_t k = nstate;
261 /* Here 0 < k < m < 4. */ 294 /* Here 0 <= k < m < 4. */
262 pstate[++k] = s[0]; 295 pstate[++k] = s[0];
263 if (k < m) 296 if (k < m)
264 pstate[++k] = s[1]; 297 {
298 pstate[++k] = s[1];
299 if (k < m)
300 pstate[++k] = s[2];
301 }
265 if (k != m) 302 if (k != m)
266 abort (); 303 abort ();
267 } 304 }