1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20: #include <stdio.h>
21: #include <string.h>
22: #include <wchar.h>
23: #include <locale.h>
24:
25: #define show(expr, nexp, wcexp, end) \
26: n = expr; \
27: printf (#expr " -> %Zd", n); \
28: printf (", wc = %lu, src = buf+%d", (unsigned long int) wc, \
29: src - (const char *) buf); \
30: if (n != (size_t) nexp || wc != wcexp || src != (const char *) (end)) \
31: { \
32: printf (", expected %Zd and %lu and buf+%d", nexp, \
33: (unsigned long int) wcexp, (end) - buf); \
34: result = 1; \
35: } \
36: putc ('\n', stdout)
37:
38: int
39: main (void)
40: {
41: unsigned char buf[6] = { 0x25, 0xe2, 0x82, 0xac, 0xce, 0xbb };
42: mbstate_t state;
43: const char *src;
44: wchar_t wc = 42;
45: size_t n;
46: int result = 0;
47: const char *used_locale;
48:
49: setlocale (LC_CTYPE,"de_DE.UTF-8");
50:
51: used_locale = setlocale (LC_CTYPE, NULL);
52: printf ("used locale: \"%s\"\n", used_locale);
53: result = strcmp (used_locale, "de_DE.UTF-8");
54:
55: memset (&state, '\0', sizeof (state));
56:
57: src = (const char *) buf;
58: show (mbsrtowcs (&wc, &src, 1, &state), 1, 37, buf + 1);
59: show (mbsrtowcs (&wc, &src, 1, &state), 1, 8364, buf + 4);
60: show (mbsrtowcs (&wc, &src, 1, &state), 1, 955, buf + 6);
61:
62: return result;
63: }