~ubuntu-branches/ubuntu/oneiric/gnupg2/oneiric-updates

« back to all changes in this revision

Viewing changes to common/localename.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* localename.c - Determine the current selected locale.
 
2
   Copyright (C) 1995-1999, 2000-2003, 2007, 
 
3
                 2008 Free Software Foundation, Inc.
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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/>.
 
17
*/
 
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 */
 
22
 
 
23
#ifdef HAVE_CONFIG_H
 
24
# include <config.h>
 
25
#endif
 
26
 
 
27
#include <stdlib.h>
 
28
#include <string.h>
 
29
#ifdef HAVE_LOCALE_H
 
30
#include <locale.h>
 
31
#endif
 
32
 
 
33
#include "../jnlib/w32help.h"
 
34
 
 
35
/* XPG3 defines the result of 'setlocale (category, NULL)' as:
 
36
   "Directs 'setlocale()' to query 'category' and return the current
 
37
    setting of 'local'."
 
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
 
43
#endif
 
44
 
 
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
 
49
#define LC_MESSAGES 0
 
50
#endif
 
51
 
 
52
 
 
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.  */
 
58
 
 
59
#ifndef HAVE_W32_SYSTEM
 
60
static const char *
 
61
do_nl_locale_name (int category, const char *categoryname)
 
62
{
 
63
  const char *retval;
 
64
 
 
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);
 
69
# else 
 
70
  /* Setting of LC_ALL overwrites all other.  */
 
71
  retval = getenv ("LC_ALL");
 
72
  if (retval == NULL || retval[0] == '\0')
 
73
    {
 
74
      /* Next comes the name of the desired category.  */
 
75
      retval = getenv (categoryname);
 
76
      if (retval == NULL || retval[0] == '\0')
 
77
        {
 
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.  */
 
83
            retval = "C";
 
84
        }
 
85
    }
 
86
# endif
 
87
 
 
88
  return retval;
 
89
}
 
90
#endif /* HAVE_W32_SYSTEM */
 
91
 
 
92
 
 
93
 
 
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.  */
 
97
const char *
 
98
gnupg_messages_locale_name (void)
 
99
{
 
100
  const char *s;
 
101
 
 
102
#ifdef HAVE_W32_SYSTEM
 
103
  /* We use the localname function from ../jnlib/w32-gettext.c. */
 
104
  s = gettext_localename ();
 
105
#else
 
106
  s = do_nl_locale_name (LC_MESSAGES, "LC_MESSAGES");
 
107
#endif
 
108
  if (!s)
 
109
    s = "";
 
110
  else if (!strcmp (s, "C") || !strcmp (s, "POSIX"))
 
111
    s = "";
 
112
 
 
113
  return s;
 
114
}
 
115