X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fwchar%2Fmbsinit.c;fp=functions%2Fwchar%2Fmbsinit.c;h=145edd81983ab07b7ebd0360361ce1a8e53e156a;hb=d5a91cea7e7837289f9d830936c001cab0adf667;hp=0000000000000000000000000000000000000000;hpb=a86fc06b877aa1418ae52f36720957e4cb9a4300;p=pdclib diff --git a/functions/wchar/mbsinit.c b/functions/wchar/mbsinit.c new file mode 100644 index 0000000..145edd8 --- /dev/null +++ b/functions/wchar/mbsinit.c @@ -0,0 +1,53 @@ +/* mbsinit(mbstate_t *ps); + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include +#ifndef REGTEST +#include <_PDCLIB_encoding.h> +#include <_PDCLIB_locale.h> + +int _PDCLIB_mbsinit_l( const mbstate_t *ps, locale_t l ) +{ + if( ps ) { + return ps->_Surrogate == 0 + && ps->_PendState == 0 + && l->_Codec->__mbsinit(ps); + } else return 1; +} + +int mbsinit( const mbstate_t * ps ) +{ + return _PDCLIB_mbsinit_l(ps, _PDCLIB_threadlocale()); +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + mbstate_t mbs; + memset(&mbs, 0, sizeof mbs); + + TESTCASE(mbsinit(NULL) != 0); + TESTCASE(mbsinit(&mbs) != 0); + +#ifndef REGTEST + // Surrogate pending + mbs._Surrogate = 0xFEED; + TESTCASE(mbsinit(&mbs) == 0); + + mbs._Surrogate = 0; + mbs._PendState = 1; + TESTCASE(mbsinit(&mbs) == 0); +#endif + return TEST_RESULTS; +} +#endif + + +