1
/* localename.c - Determine the current selected locale.
2
Copyright (C) 1995-1999, 2000-2003, 2007,
3
2008 Free Software Foundation, Inc.
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public License
7
as published by the Free Software Foundation; either version 2.1,
8
or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Lesser General Public
16
License along with this program; if not, see <http://www.gnu.org/licenses/>.
18
/* Written by Ulrich Drepper <drepper@gnu.org>, 1995. */
19
/* Win32 code written by Tor Lillqvist <tml@iki.fi>. */
20
/* Modified for GpgOL use by Werner Koch <wk@gnupg.org>, 2005. */
21
/* Modified for GnuPG use by Werner Koch <wk@gnupg.org>, 2007 */
33
#include "../jnlib/w32help.h"
35
/* XPG3 defines the result of 'setlocale (category, NULL)' as:
36
"Directs 'setlocale()' to query 'category' and return the current
38
However it does not specify the exact format. Neither do SUSV2 and
39
ISO C 99. So we can use this feature only on selected systems (e.g.
40
those using GNU C Library). */
41
#if defined _LIBC || (defined __GNU_LIBRARY__ && __GNU_LIBRARY__ >= 2)
42
# define HAVE_LOCALE_NULL
45
/* Use a dummy value for LC_MESSAGES in case it is not defined. This
46
works becuase we always test for HAVE_LC_MESSAGES and the core
47
fucntion takes the category as a string as well. */
48
#ifndef HAVE_LC_MESSAGES
53
/* Determine the current locale's name, and canonicalize it into XPG syntax
54
language[_territory[.codeset]][@modifier]
55
The codeset part in the result is not reliable; the locale_charset()
56
should be used for codeset information instead.
57
The result must not be freed; it is statically allocated. */
59
#ifndef HAVE_W32_SYSTEM
61
do_nl_locale_name (int category, const char *categoryname)
65
/* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
66
On some systems this can be done by the 'setlocale' function itself. */
67
# if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
68
retval = setlocale (category, NULL);
70
/* Setting of LC_ALL overwrites all other. */
71
retval = getenv ("LC_ALL");
72
if (retval == NULL || retval[0] == '\0')
74
/* Next comes the name of the desired category. */
75
retval = getenv (categoryname);
76
if (retval == NULL || retval[0] == '\0')
78
/* Last possibility is the LANG environment variable. */
79
retval = getenv ("LANG");
80
if (retval == NULL || retval[0] == '\0')
81
/* We use C as the default domain. POSIX says this is
82
implementation defined. */
90
#endif /* HAVE_W32_SYSTEM */
94
/* Return the locale used for translatable messages. The standard C
95
and POSIX are locale names are mapped to an empty string. If a
96
locale can't be found an empty string will be returned. */
98
gnupg_messages_locale_name (void)
102
#ifdef HAVE_W32_SYSTEM
103
/* We use the localname function from ../jnlib/w32-gettext.c. */
104
s = gettext_localename ();
106
s = do_nl_locale_name (LC_MESSAGES, "LC_MESSAGES");
110
else if (!strcmp (s, "C") || !strcmp (s, "POSIX"))