x86: Move abilist files out of nptl/ subdirectories.
[glibc.git] / localedata / bug-setlocale1.c
blobdc7f6f3f081ed8e20de05a168e9df72125724a22
1 // BZ 12788
2 #include <locale.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <unistd.h>
9 static int
10 do_test (int argc, char *argv[])
12 if (argc > 1)
14 char *newargv[5];
15 int i;
16 if (argc != 2 && argc != 5)
18 printf ("wrong number of arguments (%d)\n", argc);
19 return 1;
22 for (i = 0; i < (argc == 5 ? 4 : 1); i++)
23 newargv[i] = argv[i + 1];
24 newargv[i] = NULL;
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')
31 puts ("LOCPATH not set");
32 return 1;
34 asprintf (&env[1], "LOCPATH=%s", loc);
35 if (env[1] == NULL)
37 puts ("asprintf failed");
38 return 1;
40 env[2] = NULL;
42 execve (newargv[0], newargv, env);
44 puts ("execve returned");
45 return 1;
48 int result = 0;
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);
56 char *b = setlocale (LC_CTYPE, "");
57 printf ("setlocale(LC_CTYPE, \"\") = %s\n", b);
58 if (b == NULL)
59 return 1;
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);
67 if (strcmp (a, c) != 0)
69 puts ("*** first and third result do not match");
70 result = 1;
73 char *d = setlocale (LC_NUMERIC, "");
74 printf ("setlocale(LC_NUMERIC, \"\") = %s\n", d);
75 if (d == NULL)
76 return 1;
78 if (strcmp (d, "C") != 0)
80 puts ("*** LC_NUMERIC not C");
81 result = 1;
84 char *e = setlocale (LC_ALL, NULL);
85 printf ("setlocale(LC_ALL, NULL) = %s\n", e);
86 if (e == NULL)
87 return 1;
89 if (strcmp (a, e) != 0)
91 puts ("*** first and fifth result do not match");
92 result = 1;
95 char *f = setlocale (LC_ALL, "C");
96 printf ("setlocale(LC_ALL, \"C\") = %s\n", f);
97 if (f == NULL)
98 return 1;
100 if (strcmp (f, "C") != 0)
102 puts ("*** LC_ALL not C");
103 result = 1;
106 char *g = setlocale (LC_ALL, NULL);
107 printf ("setlocale(LC_ALL, NULL) = %s\n", g);
108 if (g == NULL)
109 return 1;
111 if (strcmp (g, "C") != 0)
113 puts ("*** LC_ALL not C");
114 result = 1;
117 char *h = setlocale (LC_CTYPE, NULL);
118 printf ("setlocale(LC_CTYPE, NULL) = %s\n", h);
119 if (h == NULL)
120 return 1;
122 if (strcmp (h, "C") != 0)
124 puts ("*** LC_CTYPE not C");
125 result = 1;
128 return result;
131 #define TEST_FUNCTION do_test (argc, argv)
132 #include "../test-skeleton.c"