]> pd.if.org Git - pdclib/blob - functions/wchar/mbsinit.c
dos2unix
[pdclib] / functions / wchar / mbsinit.c
1 /* mbsinit( mbstate_t * ps )
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #include <wchar.h>
8 #ifndef REGTEST
9 #include "_PDCLIB_encoding.h"
10 #include "_PDCLIB_locale.h"
11
12 static int _PDCLIB_mbsinit_l( const mbstate_t *ps, locale_t l )
13 {
14     if( ps ) {
15         return ps->_Surrogate == 0
16             && ps->_PendState == 0
17             && l->_Codec->__mbsinit(ps);
18     } else return 1;
19 }
20
21 int mbsinit( const mbstate_t * ps )
22 {
23     return _PDCLIB_mbsinit_l(ps, _PDCLIB_threadlocale());
24 }
25
26 #endif
27
28 #ifdef TEST
29 #include "_PDCLIB_test.h"
30
31 int main( void )
32 {
33     mbstate_t mbs;
34     memset(&mbs, 0, sizeof mbs);
35
36     TESTCASE(mbsinit(NULL) != 0);
37     TESTCASE(mbsinit(&mbs) != 0);
38
39 #ifndef REGTEST
40     // Surrogate pending
41     mbs._Surrogate = 0xFEED;
42     TESTCASE(mbsinit(&mbs) == 0);
43
44     mbs._Surrogate = 0;
45     mbs._PendState = 1;
46     TESTCASE(mbsinit(&mbs) == 0);
47 #endif
48     return TEST_RESULTS;
49 }
50 #endif
51
52
53