annotate lib/hard-locale.c @ 6163:bba2240c9260

* iconvme.h: Add prototype for iconv_alloc.
author Simon Josefsson <simon@josefsson.org>
date Tue, 30 Aug 2005 07:38:53 +0000
parents a48fb0e98c8c
children 96c32553b4c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1869
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1 /* hard-locale.c -- Determine whether a locale is hard.
3835
53af3dbd40fa Upgrade to version used in GNU Diffutils 2.8.1.
Jim Meyering <jim@meyering.net>
parents: 3561
diff changeset
2
5159
a535859efd14 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4658
diff changeset
3 Copyright (C) 1997, 1998, 1999, 2002, 2003, 2004 Free Software
a535859efd14 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4658
diff changeset
4 Foundation, Inc.
1869
Jim Meyering <jim@meyering.net>
parents:
diff changeset
5
Jim Meyering <jim@meyering.net>
parents:
diff changeset
6 This program is free software; you can redistribute it and/or modify
Jim Meyering <jim@meyering.net>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
Jim Meyering <jim@meyering.net>
parents:
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
Jim Meyering <jim@meyering.net>
parents:
diff changeset
9 any later version.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
10
Jim Meyering <jim@meyering.net>
parents:
diff changeset
11 This program is distributed in the hope that it will be useful,
Jim Meyering <jim@meyering.net>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
Jim Meyering <jim@meyering.net>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Jim Meyering <jim@meyering.net>
parents:
diff changeset
14 GNU General Public License for more details.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
15
Jim Meyering <jim@meyering.net>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
Jim Meyering <jim@meyering.net>
parents:
diff changeset
17 along with this program; if not, write to the Free Software Foundation,
5848
a48fb0e98c8c *** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents: 5510
diff changeset
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
1869
Jim Meyering <jim@meyering.net>
parents:
diff changeset
19
Jim Meyering <jim@meyering.net>
parents:
diff changeset
20 #if HAVE_CONFIG_H
Jim Meyering <jim@meyering.net>
parents:
diff changeset
21 # include <config.h>
Jim Meyering <jim@meyering.net>
parents:
diff changeset
22 #endif
Jim Meyering <jim@meyering.net>
parents:
diff changeset
23
4658
6ef2ff78cbad Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3835
diff changeset
24 #include "hard-locale.h"
6ef2ff78cbad Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3835
diff changeset
25
5510
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
26 #include <locale.h>
4658
6ef2ff78cbad Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3835
diff changeset
27 #include <stdlib.h>
6ef2ff78cbad Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3835
diff changeset
28 #include <string.h>
3835
53af3dbd40fa Upgrade to version used in GNU Diffutils 2.8.1.
Jim Meyering <jim@meyering.net>
parents: 3561
diff changeset
29
5510
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
30 #include "strdup.h"
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
31
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
32 #ifdef __GLIBC__
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
33 # define GLIBC_VERSION __GLIBC__
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
34 #else
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
35 # define GLIBC_VERSION 0
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
36 #endif
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
37
5159
a535859efd14 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4658
diff changeset
38 /* Return true if the current CATEGORY locale is hard, i.e. if you
1869
Jim Meyering <jim@meyering.net>
parents:
diff changeset
39 can't get away with assuming traditional C or POSIX behavior. */
5159
a535859efd14 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4658
diff changeset
40 bool
1869
Jim Meyering <jim@meyering.net>
parents:
diff changeset
41 hard_locale (int category)
Jim Meyering <jim@meyering.net>
parents:
diff changeset
42 {
5159
a535859efd14 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4658
diff changeset
43 bool hard = true;
a535859efd14 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4658
diff changeset
44 char const *p = setlocale (category, NULL);
1869
Jim Meyering <jim@meyering.net>
parents:
diff changeset
45
Jim Meyering <jim@meyering.net>
parents:
diff changeset
46 if (p)
Jim Meyering <jim@meyering.net>
parents:
diff changeset
47 {
5510
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
48 if (2 <= GLIBC_VERSION)
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
49 {
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
50 if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0)
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
51 hard = false;
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
52 }
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
53 else
3835
53af3dbd40fa Upgrade to version used in GNU Diffutils 2.8.1.
Jim Meyering <jim@meyering.net>
parents: 3561
diff changeset
54 {
5510
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
55 char *locale = strdup (p);
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
56 if (locale)
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
57 {
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
58 /* Temporarily set the locale to the "C" and "POSIX" locales
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
59 to find their names, so that we can determine whether one
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
60 or the other is the caller's locale. */
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
61 if (((p = setlocale (category, "C"))
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
62 && strcmp (p, locale) == 0)
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
63 || ((p = setlocale (category, "POSIX"))
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
64 && strcmp (p, locale) == 0))
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
65 hard = false;
1869
Jim Meyering <jim@meyering.net>
parents:
diff changeset
66
5510
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
67 /* Restore the caller's locale. */
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
68 setlocale (category, locale);
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
69 free (locale);
fd10cf72c81b Import chamges from coreutils, so that the code now assumes
Paul Eggert <eggert@cs.ucla.edu>
parents: 5159
diff changeset
70 }
3835
53af3dbd40fa Upgrade to version used in GNU Diffutils 2.8.1.
Jim Meyering <jim@meyering.net>
parents: 3561
diff changeset
71 }
1869
Jim Meyering <jim@meyering.net>
parents:
diff changeset
72 }
Jim Meyering <jim@meyering.net>
parents:
diff changeset
73
Jim Meyering <jim@meyering.net>
parents:
diff changeset
74 return hard;
Jim Meyering <jim@meyering.net>
parents:
diff changeset
75 }