Back to index

glibc  2.9
Defines | Functions
tst-mbswcs2.c File Reference
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <locale.h>

Go to the source code of this file.

Defines

#define show(expr, nexp, wcexp, end)

Functions

int main (void)

Define Documentation

#define show (   expr,
  nexp,
  wcexp,
  end 
)
Value:
n = expr;                                                      \
  printf (#expr " -> %Zd", n);                                        \
  printf (", wc = %lu, src = buf+%d", (unsigned long int) wc,         \
         src - (const char *) buf);                                   \
  if (n != (size_t) nexp || wc != wcexp || src != (const char *) (end))      \
    {                                                          \
      printf (", expected %Zd and %lu and buf+%d", nexp,              \
             (unsigned long int) wcexp, (end) - buf);                 \
      result = 1;                                              \
    }                                                          \
  putc ('\n', stdout)

Definition at line 26 of file tst-mbswcs2.c.


Function Documentation

int main ( void  )

Definition at line 40 of file tst-mbswcs2.c.

{
  unsigned char buf[6] = { 0x25,  0xe2, 0x82, 0xac,  0xce, 0xbb };
  mbstate_t state;
  const char *src;
  wchar_t wc = 42;
  size_t n;
  int result = 0;
  const char *used_locale;

  setlocale (LC_CTYPE,"de_DE.UTF-8");
  /* Double check.  */
  used_locale = setlocale (LC_CTYPE, NULL);
  printf ("used locale: \"%s\"\n", used_locale);
  result = strcmp (used_locale, "de_DE.UTF-8");

  memset (&state, '\0', sizeof (state));

  src = (const char *) buf;
  show (mbsnrtowcs (&wc, &src, 1, 1, &state), 1, 37, buf + 1);
  show (mbsnrtowcs (&wc, &src, 3, 1, &state), 1, 8364, buf + 4);
  show (mbsnrtowcs (&wc, &src, 1, 1, &state), 0, 8364, buf + 5);
  show (mbsnrtowcs (&wc, &src, 1, 1, &state), 1, 955, buf + 6);

  return result;
}

Here is the call graph for this function: