source: vendor/glibc-tests/glibc/string/tst-strxfrm.c

Last change on this file was 2036, checked in by bird, 20 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.2 KB
Line 
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 ("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
61int
62main (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}
Note: See TracBrowser for help on using the repository browser.