Mercurial > hg > octave-kai > gnulib-hg
annotate lib/hard-locale.c @ 3561:74b404d45147
(alloca): Define to __builtin_alloca if __GNUC__,
to avoid a warning if -Wall.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Mon, 22 Oct 2001 08:01:22 +0000 |
parents | 216a29ec230c |
children | 53af3dbd40fa |
rev | line source |
---|---|
1869 | 1 /* hard-locale.c -- Determine whether a locale is hard. |
2807
807294ed0f4f
back out Copyright date changes for files with no changes year
Jim Meyering <jim@meyering.net>
parents:
2718
diff
changeset
|
2 Copyright 1997, 1998, 1999 Free Software Foundation, Inc. |
1869 | 3 |
4 This program is free software; you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 2, or (at your option) | |
7 any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program; if not, write to the Free Software Foundation, | |
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
17 | |
18 #if HAVE_CONFIG_H | |
19 # include <config.h> | |
20 #endif | |
21 | |
3561
74b404d45147
(alloca): Define to __builtin_alloca if __GNUC__,
Jim Meyering <jim@meyering.net>
parents:
2910
diff
changeset
|
22 #if __GNUC__ |
74b404d45147
(alloca): Define to __builtin_alloca if __GNUC__,
Jim Meyering <jim@meyering.net>
parents:
2910
diff
changeset
|
23 # define alloca __builtin_alloca |
74b404d45147
(alloca): Define to __builtin_alloca if __GNUC__,
Jim Meyering <jim@meyering.net>
parents:
2910
diff
changeset
|
24 #else |
1869 | 25 # ifdef HAVE_ALLOCA_H |
26 # include <alloca.h> | |
27 # else | |
28 # ifdef _AIX | |
29 # pragma alloca | |
30 # else | |
31 # ifdef _WIN32 | |
32 # include <malloc.h> | |
33 # include <io.h> | |
34 # else | |
35 # ifndef alloca | |
36 char *alloca (); | |
37 # endif | |
38 # endif | |
39 # endif | |
40 # endif | |
41 #endif | |
42 | |
43 #if HAVE_LOCALE_H | |
44 # include <locale.h> | |
45 #endif | |
46 | |
47 #if HAVE_STRING_H | |
48 # include <string.h> | |
49 #endif | |
50 | |
51 /* Return nonzero if the current CATEGORY locale is hard, i.e. if you | |
52 can't get away with assuming traditional C or POSIX behavior. */ | |
53 int | |
54 hard_locale (int category) | |
55 { | |
56 #if ! (defined ENABLE_NLS && HAVE_SETLOCALE) | |
57 return 0; | |
58 #else | |
59 | |
60 int hard = 1; | |
2910
216a29ec230c
(hard_locale): Revert last change -- it was simply
Jim Meyering <jim@meyering.net>
parents:
2883
diff
changeset
|
61 char const *p = setlocale (category, 0); |
1869 | 62 |
63 if (p) | |
64 { | |
65 # if defined __GLIBC__ && __GLIBC__ >= 2 | |
66 if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0) | |
67 hard = 0; | |
68 # else | |
69 char *locale = alloca (strlen (p) + 1); | |
70 strcpy (locale, p); | |
71 | |
72 /* Temporarily set the locale to the "C" and "POSIX" locales to | |
73 find their names, so that we can determine whether one or the | |
74 other is the caller's locale. */ | |
75 if (((p = setlocale (category, "C")) && strcmp (p, locale) == 0) | |
76 || ((p = setlocale (category, "POSIX")) && strcmp (p, locale) == 0)) | |
77 hard = 0; | |
78 | |
79 /* Restore the caller's locale. */ | |
80 setlocale (category, locale); | |
81 # endif | |
82 } | |
83 | |
84 return hard; | |
85 | |
86 #endif | |
87 } |