mbsinit() — Test state object for initial state

Standards

Standards / Extensions C or C++ Dependencies

ISO C Amendment
C99
Single UNIX Specification, Version 3

both  

Format

Non-XPG4
#include <wchar.h>

int mbsinit(const mbstate_t *ps);
XPG4
#define _XOPEN_SOURCE
#define _MSE_PROTOS
#include <wchar.h>

int mbsinit(const mbstate_t *ps);

General description

If ps is not a NULL pointer the mbsinit() function determines whether the pointer to mbstate_t object describes an initial conversion state.

The behavior of this wide-character function is affected by the LC_CTYPE category of the current locale. If you change the category, undefined results can occur.

Special behavior for XPG4

If you define any feature test macro specifying XPG4 behavior before the statement in your program source file to include the wchar header, then you must also define the _MSE_PROTOS feature test macro to make the declaration of the mbsinit() function in the wchar header available when you compile your program. Please see Table 1 for a list of XPG4 and other feature test macros.

Returned value

If ps is a NULL pointer or if the pointed-to object describes an initial conversion state, mbsinit() returns nonzero.

Otherwise, mbsinit() returns 0.

Example

CELEBM05
⁄* CELEBM05

   This example checks the conversion state to see if it is in the
   initial state.

 *⁄
#include "stdio.h"
#include "wchar.h"
#include "stdlib.h"

main() {
   char     *string = "ABC";
   mbstate_t state = 0;
   wchar_t   wc;
   int   rc;

   rc = mbrtowc(&wc, string, MB_CUR_MAX, &state);
   if (mbsinit(&state))
     printf("In initial conversion state\n");
}

Related information