Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5220 | serge | 1 | /* |
2 | FUNCTION |
||
3 | < |
||
4 | |||
5 | INDEX |
||
6 | mbstowcs |
||
7 | |||
8 | ANSI_SYNOPSIS |
||
9 | #include |
||
10 | int mbstowcs(wchar_t *restrict <[pwc]>, const char *restrict <[s]>, size_t <[n]>); |
||
11 | |||
12 | TRAD_SYNOPSIS |
||
13 | #include |
||
14 | int mbstowcs(<[pwc]>, <[s]>, <[n]>) |
||
15 | wchar_t *<[pwc]>; |
||
16 | const char *<[s]>; |
||
17 | size_t <[n]>; |
||
18 | |||
19 | DESCRIPTION |
||
20 | When _MB_CAPABLE is not defined, this is a minimal ANSI-conforming |
||
21 | implementation of < |
||
22 | only ``multi-byte character sequences'' recognized are single bytes, |
||
23 | and they are ``converted'' to wide-char versions simply by byte |
||
24 | extension. |
||
25 | |||
26 | When _MB_CAPABLE is defined, this routine calls <<_mbstowcs_r>> to perform |
||
27 | the conversion, passing a state variable to allow state dependent |
||
28 | decoding. The result is based on the locale setting which may |
||
29 | be restricted to a defined set of locales. |
||
30 | |||
31 | RETURNS |
||
32 | This implementation of < |
||
33 | <[s]> is < |
||
34 | it returns <<-1>> if _MB_CAPABLE and one of the |
||
35 | multi-byte characters is invalid or incomplete; |
||
36 | otherwise it returns the minimum of: < |
||
37 | number of multi-byte characters in < |
||
38 | compensate for the nul character). |
||
39 | If the return value is -1, the state of the < |
||
40 | indeterminate. If the input has a length of 0, the output |
||
41 | string will be modified to contain a wchar_t nul terminator. |
||
42 | |||
43 | PORTABILITY |
||
44 | < |
||
45 | effects vary with the locale. |
||
46 | |||
47 | < |
||
48 | */ |
||
49 | |||
50 | #ifndef _REENT_ONLY |
||
51 | |||
52 | #include |
||
53 | #include |
||
54 | #include |
||
55 | |||
56 | size_t |
||
57 | _DEFUN (mbstowcs, (pwcs, s, n), |
||
58 | wchar_t *__restrict pwcs _AND |
||
59 | const char *__restrict s _AND |
||
60 | size_t n) |
||
61 | { |
||
62 | #ifdef _MB_CAPABLE |
||
63 | mbstate_t state; |
||
64 | state.__count = 0; |
||
65 | |||
66 | return _mbstowcs_r (_REENT, pwcs, s, n, &state); |
||
67 | #else /* not _MB_CAPABLE */ |
||
68 | |||
69 | int count = 0; |
||
70 | |||
71 | if (n != 0) { |
||
72 | do { |
||
73 | if ((*pwcs++ = (wchar_t) *s++) == 0) |
||
74 | break; |
||
75 | count++; |
||
76 | } while (--n != 0); |
||
77 | } |
||
78 | |||
79 | return count; |
||
80 | #endif /* not _MB_CAPABLE */ |
||
81 | } |
||
82 | |||
83 | #endif /* !_REENT_ONLY */ |