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