1 /* 2 FUNCTION 3 <<mbstowcs>>---minimal multibyte string to wide char converter 4 5 INDEX 6 mbstowcs 7 8 ANSI_SYNOPSIS 9 #include <stdlib.h> 10 int mbstowcs(wchar_t *<[pwc]>, const char *<[s]>, size_t <[n]>); 11 12 TRAD_SYNOPSIS 13 #include <stdlib.h> 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 <<mbstowcs>>. In this case, the 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 <<mbstowcs>> returns <<0>> if 33 <[s]> is <<NULL>> or is the empty string; 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: <<n>> or the 37 number of multi-byte characters in <<s>> plus 1 (to 38 compensate for the nul character). 39 If the return value is -1, the state of the <<pwc>> string is 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 <<mbstowcs>> is required in the ANSI C standard. However, the precise 45 effects vary with the locale. 46 47 <<mbstowcs>> requires no supporting OS subroutines. 48 */ 49 50 #ifndef _REENT_ONLY 51 52 #include <stdlib.h> 53 #include <wchar.h> 54 55 size_t 56 _DEFUN (mbstowcs, (pwcs, s, n), 57 wchar_t *pwcs _AND 58 const char *s _AND 59 size_t n) 60 { 61 #ifdef MB_CAPABLE 62 mbstate_t state; 63 state.__count = 0; 64 65 return _mbstowcs_r (_REENT, pwcs, s, n, &state); 66 #else /* not MB_CAPABLE */ 67 68 int count = 0; 69 70 if (n != 0) { 71 do { 72 if ((*pwcs++ = (wchar_t) *s++) == 0) 73 break; 74 count++; 75 } while (--n != 0); 76 } 77 78 return count; 79 #endif /* not MB_CAPABLE */ 80 } 81 82 #endif /* !_REENT_ONLY */ 83