*** empty log message ***
[glibc/pb-stable.git] / string / tst-strxfrm.c
blob94fd67e06281736497188f03311b89988e66c21a
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>
8 char const string[] = "";
11 static int
12 test (const char *locale)
14 size_t bufsize;
15 size_t r;
16 size_t l;
17 char *buf;
18 int result = 0;
20 if (setlocale (LC_COLLATE, locale) == NULL)
22 printf ("cannot set locale \"%s\"\n", locale);
23 return 1;
25 bufsize = strxfrm (NULL, string, 0) + 1;
26 buf = malloc (bufsize);
27 if (buf == NULL)
29 printf ("cannot allocate %zd bytes\n", bufsize);
30 return 1;
32 r = strxfrm (buf, string, bufsize);
33 l = strlen (buf);
34 if (r != l)
36 printf ("locale \"%s\": strxfrm returned %zu, strlen returned %zu\n",
37 locale, r, l);
38 result = 1;
40 free (buf);
42 return result;
46 int
47 main (void)
49 int result = 0;
51 result |= test ("C");
52 result |= test ("en_US.ISO-8859-1");
53 result |= test ("de_DE.UTF-8");
55 return result;