No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / diffutils / lib / hard-locale.c
blob4818ad86419c1e5b3f77f33d52b49398bfff000a
1 /* $NetBSD$ */
3 /* hard-locale.c -- Determine whether a locale is hard.
5 Copyright (C) 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #if HAVE_CONFIG_H
22 # include <config.h>
23 #endif
25 #if HAVE_LOCALE_H
26 # include <locale.h>
27 #endif
29 #if HAVE_STDLIB_H
30 # include <stdlib.h>
31 #endif
33 #if HAVE_STRING_H
34 # include <string.h>
35 #endif
37 #include "hard-locale.h"
39 /* Return nonzero if the current CATEGORY locale is hard, i.e. if you
40 can't get away with assuming traditional C or POSIX behavior. */
41 int
42 hard_locale (int category)
44 #if ! HAVE_SETLOCALE
45 return 0;
46 #else
48 int hard = 1;
49 char const *p = setlocale (category, 0);
51 if (p)
53 # if defined __GLIBC__ && 2 <= __GLIBC__
54 if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0)
55 hard = 0;
56 # else
57 char *locale = malloc (strlen (p) + 1);
58 if (locale)
60 strcpy (locale, p);
62 /* Temporarily set the locale to the "C" and "POSIX" locales
63 to find their names, so that we can determine whether one
64 or the other is the caller's locale. */
65 if (((p = setlocale (category, "C"))
66 && strcmp (p, locale) == 0)
67 || ((p = setlocale (category, "POSIX"))
68 && strcmp (p, locale) == 0))
69 hard = 0;
71 /* Restore the caller's locale. */
72 setlocale (category, locale);
73 free (locale);
75 # endif
78 return hard;
80 #endif