Mercurial > hg > octave-kai > gnulib-hg
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 |
rev | line source |
---|---|
1869 | 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 | 3 Copyright (C) 1997, 1998, 1999, 2002, 2003, 2004 Free Software |
4 Foundation, Inc. | |
1869 | 5 |
6 This program is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2, or (at your option) | |
9 any later version. | |
10 | |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
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 | 19 |
20 #if HAVE_CONFIG_H | |
21 # include <config.h> | |
22 #endif | |
23 | |
4658 | 24 #include "hard-locale.h" |
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 | 27 #include <stdlib.h> |
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 | 38 /* Return true if the current CATEGORY locale is hard, i.e. if you |
1869 | 39 can't get away with assuming traditional C or POSIX behavior. */ |
5159 | 40 bool |
1869 | 41 hard_locale (int category) |
42 { | |
5159 | 43 bool hard = true; |
44 char const *p = setlocale (category, NULL); | |
1869 | 45 |
46 if (p) | |
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 | 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 | 72 } |
73 | |
74 return hard; | |
75 } |