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
8char const string[] = "";
9
10
11static int
12test (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 (format: "cannot set locale \"%s\"\n", locale);
24 return 1;
25 }
26 bufsize = strxfrm (NULL, src: string, n: 0) + 1;
27 buf = malloc (size: bufsize);
28 if (buf == NULL)
29 {
30 printf (format: "cannot allocate %zd bytes\n", bufsize);
31 return 1;
32 }
33 r = strxfrm (dest: buf, src: string, n: bufsize);
34 l = strlen (buf);
35 if (r != l)
36 {
37 printf (format: "locale \"%s\": strxfrm returned %zu, strlen returned %zu\n",
38 locale, r, l);
39 result = 1;
40 }
41
42 loc = newlocale (category_mask: 1 << LC_ALL, locale: locale, NULL);
43
44 r = strxfrm_l (dest: buf, src: string, n: bufsize, l: loc);
45 l = strlen (buf);
46 if (r != l)
47 {
48 printf (format: "locale \"%s\": strxfrm_l returned %zu, strlen returned %zu\n",
49 locale, r, l);
50 result = 1;
51 }
52
53 freelocale (dataset: loc);
54
55 free (ptr: buf);
56
57 return result;
58}
59
60
61int
62do_test (void)
63{
64 int result = 0;
65
66 result |= test (locale: "C");
67 result |= test (locale: "en_US.ISO-8859-1");
68 result |= test (locale: "de_DE.UTF-8");
69
70 return result;
71}
72
73#include <support/test-driver.c>
74

source code of glibc/string/tst-strxfrm.c