mbrtowc

Converts a multibyte character to a wide-character code, using conversion states.

Library:LibC
Classification:ANSI
Service:Characters and Strings

Syntax

  #include <wchar.h> 
   
  int  mbrtowc (
     wchar_t      *pwc,
     const char   *s,
     size_t        n,
     mbstate_t    *ps);
  

Parameters

pwc

(IN) Points to a buffer to receive the converted character.

s

(IN) Points to the character whose bytes are to be converted.

n

(IN) Specifies the maximum number of bytes to examine.

ps

(IN) Points to the conversion state of the character sequence. If ps is a NULL pointer, mbrlen uses its own state, which is initialized at program startup. A thread-safe application must not pass a NULL pointer.

Return Values

Returns the first of the following that applies:

Value

Description

0

If the next n or fewer bytes complete the character that corresponds to the NULL wide character.

positive integer

If the next n or fewer bytes complete a valid character; the value returned is the number of bytes that complete the character.

-2

If the next n bytes contribute to an incomplete but potentially valid character, and all n bytes have been processed. No value is stored in pwc.

-1

If an encoding error occurs, in which case the next n or fewer bytes do not contribute to a complete and valid character. In this case, [EILSEQ] is stored in errno and the conversion state is undefined. No value is stored in pwc.

See Also