Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
MBRLEN(3)		 BSD Library Functions Manual		     MBRLEN(3)

NAME
     mbrlen -- get number of bytes in a	character (restartable)

LIBRARY
     Standard C	Library	(libc, -lc)

SYNOPSIS
     #include <wchar.h>

     size_t
     mbrlen(const char * restrict s, size_t n, mbstate_t * restrict ps);

DESCRIPTION
     The mbrlen() function determines the number of bytes constituting the
     multibyte character sequence pointed to by	s, examining at	most n bytes.

     The mbstate_t argument, ps, is used to keep track of the shift state.  If
     it	is NULL, mbrlen() uses an internal, static mbstate_t object.

     It	is equivalent to:

	   mbrtowc(NULL, s, n, ps);

     Except that when ps is a NULL pointer, mbrlen() uses its own static, in-
     ternal mbstate_t object to	keep track of the shift	state.

RETURN VALUES
     The mbrlen() functions returns:

     0	     The first n or fewer bytes	of s represent the null	wide character
	     (L'\0').

     >0	     The first n or fewer bytes	of s represent a valid character,
	     mbrtowc() returns the length (in bytes) of	the multibyte se-
	     quence.

     (size_t)-2
	     The first n bytes of s are	an incomplete multibyte	sequence.

     (size_t)-1
	     The byte sequence pointed to by s is an invalid multibyte se-
	     quence.

EXAMPLES
     A function	which calculates the number of characters in a multibyte char-
     acter string:

	   size_t
	   nchars(const	char *s)
	   {
		   size_t charlen, chars;
		   mbstate_t mbs;

		   chars = 0;
		   memset(&mbs,	0, sizeof(mbs));
		   while ((charlen = mbrlen(s, MB_CUR_MAX, &mbs)) != 0 &&
		       charlen != (size_t)-1 &&	charlen	!= (size_t)-2) {
			   s +=	charlen;
			   chars++;
		   }

		   return (chars);
	   }

ERRORS
     The mbrlen() function will	fail if:

     [EILSEQ]		An invalid multibyte sequence was detected.

SEE ALSO
     mblen(3), mbrtowc(3)

STANDARDS
     The mbrlen() function conforms to ISO/IEC 9899:1999 ("ISO C99").

BUGS
     The current implementation	does not support shift states.

BSD			       November	11, 2002			   BSD

NAME | LIBRARY | SYNOPSIS | DESCRIPTION | RETURN VALUES | EXAMPLES | ERRORS | SEE ALSO | STANDARDS | BUGS

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=mbrlen&sektion=3&manpath=FreeBSD+5.2-RELEASE+and+Ports>

home | help