1 /* Based on a test case by Paul Eggert. */
2 #include <locale.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7
8 char const string[] = "";
9
10
11 static int
test(const char * locale)12 test (const char *locale)
13 {
14 size_t bufsize;
15 size_t r;
16 size_t l;
17 char *buf;
18 locale_t loc;
19 int result = 0;
20
21 if (setlocale (LC_COLLATE, locale) == NULL)
22 {
23 printf ("cannot set locale \"%s\"\n", locale);
24 return 1;
25 }
26 bufsize = strxfrm (NULL, string, 0) + 1;
27 buf = malloc (bufsize);
28 if (buf == NULL)
29 {
30 printf ("cannot allocate %zd bytes\n", bufsize);
31 return 1;
32 }
33 r = strxfrm (buf, string, bufsize);
34 l = strlen (buf);
35 if (r != l)
36 {
37 printf ("locale \"%s\": strxfrm returned %zu, strlen returned %zu\n",
38 locale, r, l);
39 result = 1;
40 }
41
42 loc = newlocale (1 << LC_ALL, locale, NULL);
43
44 r = strxfrm_l (buf, string, bufsize, loc);
45 l = strlen (buf);
46 if (r != l)
47 {
48 printf ("locale \"%s\": strxfrm_l returned %zu, strlen returned %zu\n",
49 locale, r, l);
50 result = 1;
51 }
52
53 freelocale (loc);
54
55 free (buf);
56
57 return result;
58 }
59
60
61 int
do_test(void)62 do_test (void)
63 {
64 int result = 0;
65
66 result |= test ("C");
67 result |= test ("en_US.ISO-8859-1");
68 result |= test ("de_DE.UTF-8");
69
70 return result;
71 }
72
73 #include <support/test-driver.c>
74