C Programming/C Reference/wchar.h/mbrlen

From Wikibooks, open books for an open world
Jump to: navigation, search

mbrlen is the standard library function used to determine the length of the multi-byte character using conversion state . The mbrlen function differ from 'mblen' 'mblen l' by its restartability.

Need[edit]

To use this function in program one include the standrad header file<wchar.h>.

Syntax[edit]

size_t mbrlen (const char *s, size_t maxsize, mbstate_t *ps ).

the mbrlen() function inspects at most maxsize of the string pointed i.e. s and extracts the next complete multibyte character . It updates the shift state *ps .If the multibyte character is not the NULL wide character , it returns the number of the bytes that were consumed by s.

Return value[edit]

(size_t) - 2 : the resulting conversion state indicates an incomplete multibyte character after all maxsize character were converted .

(size_t) - 1 : the function detected an encoding error before completing the next multibyte chracter , in which case the function errno to EILSEQ amd leaves the resulting conversion state undefined.

0 : the next complete character is a null character , in which case the resulting conversion state is the initial conversion state .

positive : if the next n or fewer byte complete a valid character ; the value returned shall be the number of bytes that complete the character .

Sources[edit]