[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    mbstring(3C) manual page Table of Contents

Name

mbstring, mbstowcs, wcstombs - multibyte string functions

Synopsis

#include <stdlib.h>

size_t mbstowcs(wchar_t *pwcs, const char *s, size_t n);
size_t wcstombs(char *s, const wchar_t *pwcs, size_t n);

MT-Level

MT-Safe with exceptions

Description

mbstowcs() converts a sequence of multibyte characters from the array pointed to by s into a sequence of corresponding wide character codes and stores these codes into the array pointed to by pwcs, stopping after n codes are stored or a code with value zero (a converted null character) is stored. If an invalid multibyte character is encountered, mbstowcs() returns (size_t) -1; otherwise, mbstowcs() returns the number of array elements modified, not including the terminating zero code, if any.

wcstombs() converts a sequence of wide character codes from the array pointed to by pwcs into a sequence of multibyte characters and stores these multibyte characters into the array pointed to by s, stopping if a multibyte character would exceed the limit of n total bytes or if a null character is stored. If a wide character code is encountered that does not correspond to a valid multibyte character, wcstombs() returns (size_t) -1; otherwise, wcstombs() returns the number of bytes modified, not including a terminating null character, if any. If s is a null pointer, wcstombs() returns the number of bytes required for the character array.

See Also

chrtbl(1M) , mbchar(3C) , setlocale(3C) , environ(5)

Notes

mbstowcs and wcstombs can be used safely in a multi-thread application, as long as setlocale(3C) is not being called to change the locale.


Table of Contents