This source file includes following definitions.
- FUNC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 size_t
19 FUNC (DCHAR_T *dest, const char **srcp, size_t srclen, size_t len, mbstate_t *ps)
20 {
21 if (ps == NULL)
22 ps = &INTERNAL_STATE;
23 {
24 const char *src = *srcp;
25
26 if (dest != NULL)
27 {
28 DCHAR_T *destptr = dest;
29
30 for (; srclen > 0 && len > 0; destptr++, len--)
31 {
32 size_t src_avail;
33 size_t ret;
34
35
36
37 if (srclen == 1 || src[0] == '\0')
38 src_avail = 1;
39 else if (srclen == 2 || src[1] == '\0')
40 src_avail = 2;
41 else if (srclen == 3 || src[2] == '\0')
42 src_avail = 3;
43 else if (MB_LEN_MAX <= 4 || srclen == 4 || src[3] == '\0')
44 src_avail = 4;
45 else
46 src_avail = 4 + strnlen1 (src + 4, MIN (srclen, MB_LEN_MAX) - 4);
47
48
49 ret = MBRTOWC (destptr, src, src_avail, ps);
50
51 if (ret == (size_t)(-2))
52
53
54 abort ();
55
56 if (ret == (size_t)(-1))
57 goto bad_input;
58 if (ret == 0)
59 {
60 src = NULL;
61
62 break;
63 }
64 src += ret;
65 srclen -= ret;
66 }
67
68 *srcp = src;
69 return destptr - dest;
70 }
71 else
72 {
73
74
75 mbstate_t state = *ps;
76 size_t totalcount = 0;
77
78 for (; srclen > 0; totalcount++)
79 {
80 size_t src_avail;
81 size_t ret;
82
83
84
85 if (srclen == 1 || src[0] == '\0')
86 src_avail = 1;
87 else if (srclen == 2 || src[1] == '\0')
88 src_avail = 2;
89 else if (srclen == 3 || src[2] == '\0')
90 src_avail = 3;
91 else if (MB_LEN_MAX <= 4 || srclen == 4 || src[3] == '\0')
92 src_avail = 4;
93 else
94 src_avail = 4 + strnlen1 (src + 4, MIN (srclen, MB_LEN_MAX) - 4);
95
96
97 ret = MBRTOWC (NULL, src, src_avail, &state);
98
99 if (ret == (size_t)(-2))
100
101
102 abort ();
103
104 if (ret == (size_t)(-1))
105 goto bad_input2;
106 if (ret == 0)
107 {
108
109 break;
110 }
111 src += ret;
112 srclen -= ret;
113 }
114
115 return totalcount;
116 }
117
118 bad_input:
119 *srcp = src;
120 bad_input2:
121 errno = EILSEQ;
122 return (size_t)(-1);
123 }
124 }