2007-12-04 11:23:31 +00:00
|
|
|
/* localename.c - Determine the current selected locale.
|
Change license for some files in common to LGPLv3+/GPLv2+.
Having the LGPL on the common GnuPG code helps to share code
between GnuPG and related projects (like GPGME and Libassuan). This
is good for interoperability and to reduces bugs.
* common/asshelp.c, common/asshelp.h, common/asshelp2.c, common/b64dec.c
* common/b64enc.c, common/convert.c, common/dns-cert.c
* common/dns-cert.h common/exechelp-posix.c, common/exechelp-w32.c
* common/exechelp-w32ce.c, common/exechelp.h, common/get-passphrase.c
* common/get-passphrase.h, common/gettime.c, common/gpgrlhelp.c
* common/helpfile.c, common/homedir.c, common/http.c, common/http.h
* common/i18n.c, common/init.c, common/init.h, common/iobuf.c
* common/iobuf.h, common/localename.c, common/membuf.c, common/membuf.h
* common/miscellaneous.c, common/openpgp-oid.c, common/openpgpdefs.h
* common/percent.c, common/pka.c, common/pka.h, common/session-env.c
* common/session-env.h, common/sexp-parse.h, common/sexputil.c
* common/signal.c, common/srv.c, common/srv.h, common/ssh-utils.c
* common/ssh-utils.h, common/sysutils.c, common/sysutils.h
* common/tlv.c, common/tlv.h, common/ttyio.c, common/ttyio.h
* common/userids.c, common/userids.h, common/xasprintf.c: Change
license to LGPLv3+/GPLv2+/
2012-04-20 15:43:06 +02:00
|
|
|
* Copyright (C) 1995-1999, 2000-2003, 2007,
|
|
|
|
* 2008 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of either
|
|
|
|
*
|
|
|
|
* - the GNU Lesser General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 3 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* or
|
|
|
|
*
|
|
|
|
* - the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* or both in parallel, as here.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2007-12-04 11:23:31 +00:00
|
|
|
/* Written by Ulrich Drepper <drepper@gnu.org>, 1995. */
|
|
|
|
/* Win32 code written by Tor Lillqvist <tml@iki.fi>. */
|
2011-02-04 12:57:53 +01:00
|
|
|
/* Modified for GpgOL use by Werner Koch <wk@gnupg.org>, 2005. */
|
2007-12-04 11:23:31 +00:00
|
|
|
/* Modified for GnuPG use by Werner Koch <wk@gnupg.org>, 2007 */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#ifdef HAVE_LOCALE_H
|
|
|
|
#include <locale.h>
|
|
|
|
#endif
|
2010-03-15 13:08:51 +00:00
|
|
|
#include <gpg-error.h> /* We need gettext_localename for W32. */
|
2007-12-04 11:23:31 +00:00
|
|
|
|
2010-03-10 12:24:58 +00:00
|
|
|
#include "../common/w32help.h"
|
2007-12-04 11:23:31 +00:00
|
|
|
|
|
|
|
/* XPG3 defines the result of 'setlocale (category, NULL)' as:
|
|
|
|
"Directs 'setlocale()' to query 'category' and return the current
|
|
|
|
setting of 'local'."
|
|
|
|
However it does not specify the exact format. Neither do SUSV2 and
|
|
|
|
ISO C 99. So we can use this feature only on selected systems (e.g.
|
|
|
|
those using GNU C Library). */
|
|
|
|
#if defined _LIBC || (defined __GNU_LIBRARY__ && __GNU_LIBRARY__ >= 2)
|
|
|
|
# define HAVE_LOCALE_NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Use a dummy value for LC_MESSAGES in case it is not defined. This
|
Change license for some files in common to LGPLv3+/GPLv2+.
Having the LGPL on the common GnuPG code helps to share code
between GnuPG and related projects (like GPGME and Libassuan). This
is good for interoperability and to reduces bugs.
* common/asshelp.c, common/asshelp.h, common/asshelp2.c, common/b64dec.c
* common/b64enc.c, common/convert.c, common/dns-cert.c
* common/dns-cert.h common/exechelp-posix.c, common/exechelp-w32.c
* common/exechelp-w32ce.c, common/exechelp.h, common/get-passphrase.c
* common/get-passphrase.h, common/gettime.c, common/gpgrlhelp.c
* common/helpfile.c, common/homedir.c, common/http.c, common/http.h
* common/i18n.c, common/init.c, common/init.h, common/iobuf.c
* common/iobuf.h, common/localename.c, common/membuf.c, common/membuf.h
* common/miscellaneous.c, common/openpgp-oid.c, common/openpgpdefs.h
* common/percent.c, common/pka.c, common/pka.h, common/session-env.c
* common/session-env.h, common/sexp-parse.h, common/sexputil.c
* common/signal.c, common/srv.c, common/srv.h, common/ssh-utils.c
* common/ssh-utils.h, common/sysutils.c, common/sysutils.h
* common/tlv.c, common/tlv.h, common/ttyio.c, common/ttyio.h
* common/userids.c, common/userids.h, common/xasprintf.c: Change
license to LGPLv3+/GPLv2+/
2012-04-20 15:43:06 +02:00
|
|
|
works because we always test for HAVE_LC_MESSAGES and the core
|
2007-12-04 11:23:31 +00:00
|
|
|
fucntion takes the category as a string as well. */
|
|
|
|
#ifndef HAVE_LC_MESSAGES
|
|
|
|
#define LC_MESSAGES 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* Determine the current locale's name, and canonicalize it into XPG syntax
|
|
|
|
language[_territory[.codeset]][@modifier]
|
|
|
|
The codeset part in the result is not reliable; the locale_charset()
|
|
|
|
should be used for codeset information instead.
|
|
|
|
The result must not be freed; it is statically allocated. */
|
|
|
|
|
2008-03-25 19:41:11 +00:00
|
|
|
#ifndef HAVE_W32_SYSTEM
|
2007-12-04 11:23:31 +00:00
|
|
|
static const char *
|
|
|
|
do_nl_locale_name (int category, const char *categoryname)
|
|
|
|
{
|
|
|
|
const char *retval;
|
|
|
|
|
|
|
|
/* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
|
|
|
|
On some systems this can be done by the 'setlocale' function itself. */
|
|
|
|
# if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
|
2008-10-20 13:53:23 +00:00
|
|
|
(void)categoryname;
|
2007-12-04 11:23:31 +00:00
|
|
|
retval = setlocale (category, NULL);
|
2011-02-04 12:57:53 +01:00
|
|
|
# else
|
2007-12-04 11:23:31 +00:00
|
|
|
/* Setting of LC_ALL overwrites all other. */
|
|
|
|
retval = getenv ("LC_ALL");
|
|
|
|
if (retval == NULL || retval[0] == '\0')
|
|
|
|
{
|
|
|
|
/* Next comes the name of the desired category. */
|
|
|
|
retval = getenv (categoryname);
|
|
|
|
if (retval == NULL || retval[0] == '\0')
|
|
|
|
{
|
|
|
|
/* Last possibility is the LANG environment variable. */
|
|
|
|
retval = getenv ("LANG");
|
|
|
|
if (retval == NULL || retval[0] == '\0')
|
|
|
|
/* We use C as the default domain. POSIX says this is
|
|
|
|
implementation defined. */
|
|
|
|
retval = "C";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2008-03-25 19:41:11 +00:00
|
|
|
#endif /* HAVE_W32_SYSTEM */
|
2007-12-04 11:23:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Return the locale used for translatable messages. The standard C
|
|
|
|
and POSIX are locale names are mapped to an empty string. If a
|
|
|
|
locale can't be found an empty string will be returned. */
|
|
|
|
const char *
|
|
|
|
gnupg_messages_locale_name (void)
|
|
|
|
{
|
|
|
|
const char *s;
|
|
|
|
|
2008-03-25 19:41:11 +00:00
|
|
|
#ifdef HAVE_W32_SYSTEM
|
2010-03-15 13:08:51 +00:00
|
|
|
/* We use the localename function libgpg-error. */
|
2008-03-25 19:41:11 +00:00
|
|
|
s = gettext_localename ();
|
|
|
|
#else
|
2007-12-04 11:23:31 +00:00
|
|
|
s = do_nl_locale_name (LC_MESSAGES, "LC_MESSAGES");
|
2008-03-25 19:41:11 +00:00
|
|
|
#endif
|
2007-12-04 11:23:31 +00:00
|
|
|
if (!s)
|
|
|
|
s = "";
|
|
|
|
else if (!strcmp (s, "C") || !strcmp (s, "POSIX"))
|
|
|
|
s = "";
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|