iconv: fix missing bounds checking for shift_jis decoding
[musl.git] / src / ctype / iswctype.c
blob71b09b8d24ae56c5cc29bab7053bf2b014e972b7
1 #include <wctype.h>
2 #include <string.h>
4 #define WCTYPE_ALNUM 1
5 #define WCTYPE_ALPHA 2
6 #define WCTYPE_BLANK 3
7 #define WCTYPE_CNTRL 4
8 #define WCTYPE_DIGIT 5
9 #define WCTYPE_GRAPH 6
10 #define WCTYPE_LOWER 7
11 #define WCTYPE_PRINT 8
12 #define WCTYPE_PUNCT 9
13 #define WCTYPE_SPACE 10
14 #define WCTYPE_UPPER 11
15 #define WCTYPE_XDIGIT 12
17 int iswctype(wint_t wc, wctype_t type)
19 switch (type) {
20 case WCTYPE_ALNUM:
21 return iswalnum(wc);
22 case WCTYPE_ALPHA:
23 return iswalpha(wc);
24 case WCTYPE_BLANK:
25 return iswblank(wc);
26 case WCTYPE_CNTRL:
27 return iswcntrl(wc);
28 case WCTYPE_DIGIT:
29 return iswdigit(wc);
30 case WCTYPE_GRAPH:
31 return iswgraph(wc);
32 case WCTYPE_LOWER:
33 return iswlower(wc);
34 case WCTYPE_PRINT:
35 return iswprint(wc);
36 case WCTYPE_PUNCT:
37 return iswpunct(wc);
38 case WCTYPE_SPACE:
39 return iswspace(wc);
40 case WCTYPE_UPPER:
41 return iswupper(wc);
42 case WCTYPE_XDIGIT:
43 return iswxdigit(wc);
45 return 0;
48 wctype_t wctype(const char *s)
50 int i;
51 const char *p;
52 /* order must match! */
53 static const char names[] =
54 "alnum\0" "alpha\0" "blank\0"
55 "cntrl\0" "digit\0" "graph\0"
56 "lower\0" "print\0" "punct\0"
57 "space\0" "upper\0" "xdigit";
58 for (i=1, p=names; *p; i++, p+=6)
59 if (*s == *p && !strcmp(s, p))
60 return i;
61 return 0;
64 int __iswctype_l(wint_t c, wctype_t t, locale_t l)
66 return iswctype(c, t);
69 wctype_t __wctype_l(const char *s, locale_t l)
71 return wctype(s);
74 weak_alias(__iswctype_l, iswctype_l);
75 weak_alias(__wctype_l, wctype_l);