wcsrtombs

Converts a wide-character string to a multibyte character string.

Library:LibC
Classification:ANSI
Service:Characters and Strings

Syntax

  #include <wchar.h> 
   
  size_t   wcsrtombs (
     char             *dst,
     const wchar_t   **src,
     size_t            len,
     mbstate_t        *ps);
  

Parameters

dst

(OUT) Points to the converted multibyte string.

src

(IN) Points to the wide-character string to convert.

len

(IN) Specifies the number of wide characters to convert.

ps

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

Return Values

If successful, returns the number of bytes converted, not including the null-terminating character (if any). Otherwise, returns -1 and sets errno to one of the following:

Decimal

Constant

Description

9

EINVAL

The ps parameter points to an object that contains an invalid conversion state.

101

EILSEQ

The src parameter contains an invalid wide-character code.

Remarks

The wcsrtombs function converts a sequence of wide characters from the array pointed to by src into a sequence of corresponding characters, beginning in the conversion state described by the object pointed to by ps. If dst is not a NULL pointer, the converted characters are stored into the array pointed to by dst. Conversion continues up to and including a null-terminating wide character, which is also stored. Conversion stops earlier in the following cases:

  • When a code is reached that does not correspond to a valid character

  • When the next character would exceed the limit of len total bytes to be stored in the array pointed to by dst (and dst is not a NULL pointer)

Each character conversion takes place as if the wcrtomb function has been called.

See Also