Back to index

glibc  2.9
mbtowc.c File Reference
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <gconv.h>
#include <wcsmbs/wcsmbsload.h>

Go to the source code of this file.


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

Function Documentation

int mbtowc ( wchar_t *  pwc,
const char *  s,
size_t  n 

Definition at line 36 of file mbtowc.c.

  int result;
  static mbstate_t state;

  /* If S is NULL the function has to return null or not null
     depending on the encoding having a state depending encoding or
     not.  */
  if (s == NULL)
      const struct gconv_fcts *fcts;

      /* Get the conversion functions.  */
      fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE));

      /* This is an extension in the Unix standard which does not directly
        violate ISO C.  */
      memset (&state, '\0', sizeof state);

      result = fcts->towc->__stateful;
  else if (*s == '\0')
      if (pwc != NULL)
       *pwc = L'\0';
      result = 0;
      result = __mbrtowc (pwc, s, n, &state);

      /* The `mbrtowc' functions tell us more than we need.  Fold the -1
        and -2 result into -1.  */
      if (result < 0)
       result = -1;

  return result;

Here is the call graph for this function:

Here is the caller graph for this function: