


MBLEN(3)               C LIBRARY FUNCTIONS               MBLEN(3)



NAME
     mblen, mbstowcs, mbtowc, wcstombs, wctomb - multibyte  char-
     acter handling

SYNOPSIS
     #include <stdlib.h>

     int mblen(s, n)
     char *s;
     size_t n;

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

     int mbtowc(pwc, s, n)
     wchar_t *pwc;
     char *s;
     size_t n;

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

     int wctomb(s, wchar)
     char *s;
     wchar_t wcar;

DESCRIPTION
     The behavior of these functions is affected by the  LC_CTYPE
     category  of  the  program's  locale.   For a stat-dependent
     encoding, each function is placed into its initial state  by
     a  call  for  which  its character pointer argument, _s, is a
     NULL pointer.  Subsequent calls with _s as other than a  NULL
     pointer  cause  the  internal  stste  of  the function to be
     altered as necessary.  A call with a _s  as  a  NULL  pointer
     causes  these  functions to return a nonzero value if encod-
     ings have state dependency, and zero  otherwise.  After  the
     LC_CTYPE category is changed, the shift state of these func-
     tions is indeterminate.

     If _s is not a NULL pointer, these functions work as follows:

     mblen()
          Determines the number of bytes comprising the multibyte
          character pointed to by _s.

     mbstowcs()
          Converts a sequence of multibyte characters that begins
          in the initial shift state from the array pointed to by



Sun Release 4.1   Last change: 21 January 1990                  1






MBLEN(3)               C LIBRARY FUNCTIONS               MBLEN(3)



          _s into a sequence of corresponding codes and stores  no
          more  than  _n  codes into the array pointed to by _p_w_c_s.
          No multibyte characters that follow  a  null  character
          (which  is  converted into a code with value zero) will
          be examined or converted.  Each multibyte character  is
          converted  as if by a call to mbtowc(), except that the
          shift state of mbtowc() is not affected.

          No more than _n elements will be modified in  the  array
          pointed  to  by  _p_w_c_s.   If copying takes place between
          objects that overlap, the behavior is undefined.

     mbtowc()
          Determines the number of bytes that comprise the multi-
          byte  character  pointed to by _s.  mbtowc() then deter-
          mines  the  code  for  value  of  type   wchar_t   that
          corresponds  to that multibyte character.  The value of
          the code corresponding to the null caharacter is  zero.
          If  the  multibyte  character is valid and _p_w_c is not a
          null pointer, mbtowc() stores the code  in  the  object
          pointed  to  by  _p_w_c.   At  most  _n  bytes of the array
          pointed to by _s will be examined.

     wcstowcs()
          Converts a sequence of codes that correspond to  multi-
          byte  characters from the array pointed to by _p_w_c_s into
          a sequence of multibyte characters that begins  in  the
          initial  shift state and stores these multibyte charac-
          ters into the array pointed to by _s, stopping if a mul-
          tibyte  character  would  exceed  the  limit of _n total
          bytes or if a null character is stored.  Each  code  is
          converted  as if by a call to wctomb(), except that the
          shift state of wctomb() is not affected.

     wctomb()
          Determines the number of bytes needed to represent  the
          multibyte  character  corresponding  to  the code whose
          value is _w_c_h_a_r (including any change in  shift  state).
          wctomb()  stores the multibyte character representation
          in the array object pointed to by _s (if _s is not a null
          pointer).   At  most, MB_CUR_MAX characters are stored.
          If the value of _w_c_h_a_r is zero, wctomb() is left in  the
          initial shift state.

RETURN VALUES
     If _s is a null  pointer,  mblen(),  mbtowc(),  and  wctomb()
     return  a  nonzero  or  zero  value,  if multibyte character
     encodings, respectively, do or do not have  state  dependent
     encodings.

     If _s is not a null  pointer,  mblen()  and  mbtowc()  either
     return  0 (if _s points to the null character), or return the



Sun Release 4.1   Last change: 21 January 1990                  2






MBLEN(3)               C LIBRARY FUNCTIONS               MBLEN(3)



     number of bytes that comprise the converted multibyte  char-
     acter  (if  the next _n or fewer bytes form a valid multibyte
     character), or return -1 (if they do not form a valid multi-
     byte character).

     In no case will the value returned by  mbtowc()  be  greater
     than  _n or the value of the MB_CUR_MAX macro.  If _s is not a
     null pointer, wctomb() returns -1 (if  the  value  does  not
     correspond  to  a valid multibyte character), or returns the
     number  of  bytes  that  comprise  the  multibyte  character
     corresponding to _w_c_h_a_r.

     If an invalid multibyte character is encountered, mbstowcs()
     and  wcstombs()  return (size_t) -1.  Otherwise, they return
     the number of bytes modified, not  including  a  terminating
     null character, if any.







































Sun Release 4.1   Last change: 21 January 1990                  3



