1#include <stdio.h>
2#include <stdlib.h>
3
4int
5main (int argc, char *argv[])
6{
7 wchar_t w[10];
8 char c[10];
9 int i;
10 int lose = 0;
11
12 i = mbstowcs (pwcs: w, s: "bar", n: 4);
13 if (!(i == 3 && w[1] == 'a'))
14 {
15 puts (s: "mbstowcs FAILED!");
16 lose = 1;
17 }
18
19 i = mbstowcs (NULL, s: "bar", n: 4);
20 if (!(i == 3 && w[1] == 'a'))
21 {
22 puts (s: "mbstowcs FAILED2!");
23 lose = 1;
24 }
25
26 mbstowcs (pwcs: w, s: "blah", n: 5);
27 i = wcstombs (s: c, pwcs: w, n: 10);
28 if (i != 4)
29 {
30 puts (s: "wcstombs FAILED!");
31 lose = 1;
32 }
33
34 if (mblen (s: "foobar", n: 7) != 1)
35 {
36 puts (s: "mblen 1 FAILED!");
37 lose = 1;
38 }
39
40 if (mblen (s: "", n: 1) != 0)
41 {
42 puts (s: "mblen 2 FAILED!");
43 lose = 1;
44 }
45
46 {
47 int r;
48 char c = 'x';
49 wchar_t wc;
50 char mbc[MB_CUR_MAX];
51
52 if ((r = mbtowc (&wc, &c, MB_CUR_MAX)) <= 0)
53 {
54 printf (format: "conversion to wide failed, result: %d\n", r);
55 lose = 1;
56 }
57 else
58 {
59 printf (format: "wide value: 0x%04lx\n", (unsigned long) wc);
60 mbc[0] = '\0';
61 if ((r = wctomb (mbc, wc)) <= 0)
62 {
63 printf (format: "conversion to multibyte failed, result: %d\n", r);
64 lose = 1;
65 }
66 }
67
68 }
69
70 puts (s: lose ? "Test FAILED!" : "Test succeeded.");
71 return lose;
72}
73

source code of glibc/stdlib/testmb.c