]> git.ipfire.org Git - thirdparty/glibc.git/blob - localedata/bug-setlocale1.c
Support run bug-setlocale1 directly
[thirdparty/glibc.git] / localedata / bug-setlocale1.c
1 // BZ 12788
2 #include <locale.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <unistd.h>
7
8
9 static int
10 do_test (int argc, char *argv[])
11 {
12 if (argc > 1)
13 {
14 char *newargv[5];
15 int i;
16 if (argc != 2 && argc != 5)
17 {
18 printf ("wrong number of arguments (%d)\n", argc);
19 return 1;
20 }
21
22 for (i = 0; i < (argc == 5 ? 4 : 1); i++)
23 newargv[i] = argv[i + 1];
24 newargv[i] = NULL;
25
26 char *env[3];
27 env[0] = (char *) "LC_CTYPE=de_DE.UTF-8";
28 char *loc = getenv ("LOCPATH");
29 if (loc == NULL || loc[0] == '\0')
30 {
31 puts ("LOCPATH not set");
32 return 1;
33 }
34 asprintf (&env[1], "LOCPATH=%s", loc);
35 if (env[1] == NULL)
36 {
37 puts ("asprintf failed");
38 return 1;
39 }
40 env[2] = NULL;
41
42 execve (newargv[0], newargv, env);
43
44 puts ("execve returned");
45 return 1;
46 }
47
48 int result = 0;
49
50 char *a = setlocale (LC_ALL, "");
51 printf ("setlocale(LC_ALL, \"\") = %s\n", a);
52 if (a == NULL)
53 return 1;
54 a = strdupa (a);
55
56 char *b = setlocale (LC_CTYPE, "");
57 printf ("setlocale(LC_CTYPE, \"\") = %s\n", b);
58 if (b == NULL)
59 return 1;
60
61 char *c = setlocale (LC_ALL, NULL);
62 printf ("setlocale(LC_ALL, NULL) = %s\n", c);
63 if (c == NULL)
64 return 1;
65 c = strdupa (c);
66
67 if (strcmp (a, c) != 0)
68 {
69 puts ("*** first and third result do not match");
70 result = 1;
71 }
72
73 char *d = setlocale (LC_NUMERIC, "");
74 printf ("setlocale(LC_NUMERIC, \"\") = %s\n", d);
75 if (d == NULL)
76 return 1;
77
78 if (strcmp (d, "C") != 0)
79 {
80 puts ("*** LC_NUMERIC not C");
81 result = 1;
82 }
83
84 char *e = setlocale (LC_ALL, NULL);
85 printf ("setlocale(LC_ALL, NULL) = %s\n", e);
86 if (e == NULL)
87 return 1;
88
89 if (strcmp (a, e) != 0)
90 {
91 puts ("*** first and fifth result do not match");
92 result = 1;
93 }
94
95 char *f = setlocale (LC_ALL, "C");
96 printf ("setlocale(LC_ALL, \"C\") = %s\n", f);
97 if (f == NULL)
98 return 1;
99
100 if (strcmp (f, "C") != 0)
101 {
102 puts ("*** LC_ALL not C");
103 result = 1;
104 }
105
106 char *g = setlocale (LC_ALL, NULL);
107 printf ("setlocale(LC_ALL, NULL) = %s\n", g);
108 if (g == NULL)
109 return 1;
110
111 if (strcmp (g, "C") != 0)
112 {
113 puts ("*** LC_ALL not C");
114 result = 1;
115 }
116
117 char *h = setlocale (LC_CTYPE, NULL);
118 printf ("setlocale(LC_CTYPE, NULL) = %s\n", h);
119 if (h == NULL)
120 return 1;
121
122 if (strcmp (h, "C") != 0)
123 {
124 puts ("*** LC_CTYPE not C");
125 result = 1;
126 }
127
128 return result;
129 }
130
131 #define TEST_FUNCTION do_test (argc, argv)
132 #include "../test-skeleton.c"