Back to index

glibc  2.9
Defines | Functions
tst-mbswcs1.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)

Functions

int main (void)

Define Documentation

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

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


Function Documentation

int main ( void  )

Definition at line 38 of file tst-mbswcs1.c.

{
  const unsigned char buf[6] = { 0x25,  0xe2, 0x82, 0xac,  0xce, 0xbb };
  mbstate_t state;
  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));

  show (mbrtowc (&wc, (const char *) buf + 0, 1, &state), 1, 37);
  show (mbrtowc (&wc, (const char *) buf + 1, 1, &state), -2, 37);
  show (mbrtowc (&wc, (const char *) buf + 2, 3, &state), 2, 8364);
  show (mbrtowc (&wc, (const char *) buf + 4, 1, &state), -2, 8364);
  show (mbrtowc (&wc, (const char *) buf + 5, 1, &state), 1, 955);
  show (mbrtowc (&wc, (const char *) buf + 5, 1, &state), -1, 955);

  return result;
}

Here is the call graph for this function: