annotate tests/test-setlocale2.c @ 17288:e1bf1347de53

doc: clarify -Werror * doc/warnings.texi (warnings): -Werror is not always a bad idea; clarify that it's intended for developers, not for ordinary builds, and mention --enable-gcc-warnings as one possible use.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 15 Jan 2013 12:21:42 -0800
parents e542fd46ad6f
children 344018b6e5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14333
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of setting the current locale.
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16201
diff changeset
2 Copyright (C) 2011-2013 Free Software Foundation, Inc.
14333
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #include <config.h>
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <locale.h>
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <stdio.h>
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include <stdlib.h>
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <string.h>
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 int
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 main ()
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 {
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 /* Try to set the locale by implicitly looking at the LC_ALL environment
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 variable. */
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 if (setlocale (LC_ALL, "") != NULL)
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 /* It was successful. Check whether LC_CTYPE is non-trivial. */
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 if (strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 {
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 fprintf (stderr, "setlocale did not fail for implicit %s\n",
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 getenv ("LC_ALL"));
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 return 1;
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 }
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 /* Reset the locale. */
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 if (setlocale (LC_ALL, "C") == NULL)
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 return 1;
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 /* Try to set the locale by explicitly looking at the LC_ALL environment
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 variable. */
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 if (setlocale (LC_ALL, getenv ("LC_ALL")) != NULL)
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 /* It was successful. Check whether LC_CTYPE is non-trivial. */
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 if (strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 {
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 fprintf (stderr, "setlocale did not fail for explicit %s\n",
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 getenv ("LC_ALL"));
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 return 1;
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 }
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 return 0;
e58fa64818aa setlocale: Workaround native Windows bug.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 }