Name

mblen - determines number of bytes in next multibyte character

Library

libc.lib

Synopsis

  #include <stdlib.h>
  int mblen (const char *mbchar, size_t nbytes);

Return values

If mbchar is NULL, the mblen function returns nonzero if shift states are supported, zero otherwise.

Otherwise, if mbchar is not a null pointer, mblen either returns 0 if mbchar represents the null wide character, or returns the number of bytes processed in mbchar, or returns -1 if no multibyte character could be recognized or converted. In this case, mblen (Ns, ’s);
internal conversion state is undefined.


Detailed description

The mblen function computes the length in bytes of a multibyte character mbchar according to the current conversion state. Up to nbytes bytes are examined.

A call with a null mbchar pointer returns nonzero if the current locale requires shift states, zero otherwise; if shift states are required, the shift state is reset to the initial state.

The behavior of the mblen is affected by LC_CTYPE category of the current locale.


Examples

#include <stdlib.h>
#include <wchar.h>
/* Illustrates how to use mblen API */
int example_mblen(wchar_t wc)
{
 int len;
 
 /* determine the number bytes in the multibyte char */
 len = mblen(wc, MB_CUR_MAX);
 if(len == -1)
 {
        wprintf(L"mblen returned error!!\n");
 }
 /* return the no of bytes */
 return(len);
}

         


Errors

The mblen function will fail if:
[EILSEQ]
  An invalid multibyte sequence was detected.
[EINVAL]
  The internal conversion state is not valid.

Limitations

The current implementation of mblen is not affected by the LC_CTYPE category of the current locale. It works only for UTF8 character set.

See also

mbrlen, mbtowc

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top