Last change
on this file since 2044 was 2044, checked in by bird, 20 years ago |
Porting to 64-bit FreeBSD...
|
-
Property cvs2svn:cvs-rev
set to
1.2
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
-
Property svn:keywords
set to
Author Date Id Revision
|
File size:
1.4 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 |
|
---|
8 | char const string[] = "";
|
---|
9 |
|
---|
10 |
|
---|
11 | static int
|
---|
12 | test (const char *locale)
|
---|
13 | {
|
---|
14 | size_t bufsize;
|
---|
15 | size_t r;
|
---|
16 | size_t l;
|
---|
17 | char *buf;
|
---|
18 | #ifdef HAVE_NEWLOCALE
|
---|
19 | locale_t loc;
|
---|
20 | #endif
|
---|
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 | #ifdef HAVE_NEWLOCALE
|
---|
45 | loc = newlocale (1 << LC_ALL, locale, NULL);
|
---|
46 |
|
---|
47 | r = strxfrm_l (buf, string, bufsize, loc);
|
---|
48 | l = strlen (buf);
|
---|
49 | if (r != l)
|
---|
50 | {
|
---|
51 | printf ("locale \"%s\": strxfrm_l returned %zu, strlen returned %zu\n",
|
---|
52 | locale, r, l);
|
---|
53 | result = 1;
|
---|
54 | }
|
---|
55 |
|
---|
56 | freelocale (loc);
|
---|
57 | #endif
|
---|
58 |
|
---|
59 | free (buf);
|
---|
60 |
|
---|
61 | return result;
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | int
|
---|
66 | main (void)
|
---|
67 | {
|
---|
68 | int result = 0;
|
---|
69 |
|
---|
70 | result |= test ("C");
|
---|
71 | #ifdef __BSD__ /* bsd is missing the aliases. loosers. */
|
---|
72 | result |= test ("en_US.ISO8859-1");
|
---|
73 | #else
|
---|
74 | result |= test ("en_US.ISO-8859-1");
|
---|
75 | #endif
|
---|
76 | result |= test ("de_DE.UTF-8");
|
---|
77 |
|
---|
78 | return result;
|
---|
79 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.