Fixes to get nptl compiling for x86
[uclibc-ng.git] / test / string / tst-strxfrm.c
blobff1b396be560a7186f85d894c53a6f8c43606695
1 /* 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>
10 char const string[] = "";
13 static int
14 test (const char *locale)
16 size_t bufsize;
17 size_t r;
18 size_t l;
19 char *buf;
20 locale_t loc;
21 int result = 0;
23 if (setlocale (LC_COLLATE, locale) == NULL)
25 printf ("cannot set locale \"%s\"\n", locale);
26 return 1;
28 bufsize = strxfrm (NULL, string, 0) + 1;
29 buf = malloc (bufsize);
30 if (buf == NULL)
32 printf ("cannot allocate %zd bytes\n", bufsize);
33 return 1;
35 r = strxfrm (buf, string, bufsize);
36 l = strlen (buf);
37 if (r != l)
39 printf ("locale \"%s\": strxfrm returned %zu, strlen returned %zu\n",
40 locale, r, l);
41 result = 1;
44 loc = newlocale (1 << LC_ALL, locale, NULL);
46 r = strxfrm_l (buf, string, bufsize, loc);
47 l = strlen (buf);
48 if (r != l)
50 printf ("locale \"%s\": strxfrm_l returned %zu, strlen returned %zu\n",
51 locale, r, l);
52 result = 1;
55 freelocale (loc);
57 free (buf);
59 return result;
63 int
64 main (void)
66 int result = 0;
68 result |= test ("C");
69 result |= test ("en_US.ISO-8859-1");
70 result |= test ("de_DE.UTF-8");
72 return result;
75 #else
76 int main(void)
78 return 0;
80 #endif