~ubuntu-branches/ubuntu/hardy/gnupg2/hardy

« back to all changes in this revision

Viewing changes to intl/localcharset.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Bienia, Michael Bienia, Kees Cook
  • Date: 2006-12-07 00:28:23 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20061207002823-0i7ittrpmsm1nv0i
Tags: 2.0.1-0ubuntu1
[ Michael Bienia ]
* New upstream version.
* Remaining changes:
  - Remove libpcsclite-dev, libopensc2-dev build dependencies (they are in
    universe).
* g10/encr-data.c: remotely controllable function pointer (CVE-2006-6235)
* debian/control: add libcurl3-gnutls-dev to build-depends 
  (Closes Ubuntu: #62864)

[ Kees Cook ]
* debian/rules: include doc/ files as done with gnupg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Determine a canonical name for the current locale's character encoding.
2
2
 
3
 
   Copyright (C) 2000-2003 Free Software Foundation, Inc.
 
3
   Copyright (C) 2000-2006 Free Software Foundation, Inc.
4
4
 
5
5
   This program is free software; you can redistribute it and/or modify it
6
6
   under the terms of the GNU Library General Public License as published
14
14
 
15
15
   You should have received a copy of the GNU Library General Public
16
16
   License along with this program; if not, write to the Free Software
17
 
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
17
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18
18
   USA.  */
19
19
 
20
20
/* Written by Bruno Haible <bruno@clisp.org>.  */
41
41
#endif
42
42
 
43
43
#if defined _WIN32 || defined __WIN32__
44
 
# undef WIN32   /* avoid warning on mingw32 */
45
 
# define WIN32
 
44
# define WIN32_NATIVE
46
45
#endif
47
46
 
48
47
#if defined __EMX__
50
49
# define OS2
51
50
#endif
52
51
 
53
 
#if !defined WIN32
 
52
#if !defined WIN32_NATIVE
54
53
# if HAVE_LANGINFO_CODESET
55
54
#  include <langinfo.h>
56
55
# else
58
57
#   include <locale.h>
59
58
#  endif
60
59
# endif
61
 
#elif defined WIN32
 
60
# ifdef __CYGWIN__
 
61
#  define WIN32_LEAN_AND_MEAN
 
62
#  include <windows.h>
 
63
# endif
 
64
#elif defined WIN32_NATIVE
62
65
# define WIN32_LEAN_AND_MEAN
63
66
# include <windows.h>
64
67
#endif
73
76
# define relocate(pathname) (pathname)
74
77
#endif
75
78
 
76
 
#if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
77
 
  /* Win32, OS/2, DOS */
 
79
#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
 
80
  /* Win32, Cygwin, OS/2, DOS */
78
81
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
79
82
#endif
80
83
 
107
110
 
108
111
/* Return a pointer to the contents of the charset.alias file.  */
109
112
static const char *
110
 
get_charset_aliases ()
 
113
get_charset_aliases (void)
111
114
{
112
115
  const char *cp;
113
116
 
114
117
  cp = charset_aliases;
115
118
  if (cp == NULL)
116
119
    {
117
 
#if !(defined VMS || defined WIN32)
 
120
#if !(defined VMS || defined WIN32_NATIVE || defined __CYGWIN__)
118
121
      FILE *fp;
119
 
      const char *dir = relocate (LIBDIR);
 
122
      const char *dir;
120
123
      const char *base = "charset.alias";
121
124
      char *file_name;
122
125
 
 
126
      /* Make it possible to override the charset.alias location.  This is
 
127
         necessary for running the testsuite before "make install".  */
 
128
      dir = getenv ("CHARSETALIASDIR");
 
129
      if (dir == NULL || dir[0] == '\0')
 
130
        dir = relocate (LIBDIR);
 
131
 
123
132
      /* Concatenate dir and base into freshly allocated file_name.  */
124
133
      {
125
134
        size_t dir_len = strlen (dir);
141
150
      else
142
151
        {
143
152
          /* Parse the file's contents.  */
144
 
          int c;
145
 
          char buf1[50+1];
146
 
          char buf2[50+1];
147
153
          char *res_ptr = NULL;
148
154
          size_t res_size = 0;
149
 
          size_t l1, l2;
150
155
 
151
156
          for (;;)
152
157
            {
 
158
              int c;
 
159
              char buf1[50+1];
 
160
              char buf2[50+1];
 
161
              size_t l1, l2;
 
162
              char *old_res_ptr;
 
163
 
153
164
              c = getc (fp);
154
165
              if (c == EOF)
155
166
                break;
170
181
                break;
171
182
              l1 = strlen (buf1);
172
183
              l2 = strlen (buf2);
 
184
              old_res_ptr = res_ptr;
173
185
              if (res_size == 0)
174
186
                {
175
187
                  res_size = l1 + 1 + l2 + 1;
184
196
                {
185
197
                  /* Out of memory. */
186
198
                  res_size = 0;
 
199
                  if (old_res_ptr != NULL)
 
200
                    free (old_res_ptr);
187
201
                  break;
188
202
                }
189
203
              strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1);
229
243
           "DECKOREAN" "\0" "EUC-KR" "\0";
230
244
# endif
231
245
 
232
 
# if defined WIN32
 
246
# if defined WIN32_NATIVE || defined __CYGWIN__
233
247
      /* To avoid the troubles of installing a separate file in the same
234
248
         directory as the DLL and of retrieving the DLL's directory at
235
249
         runtime, simply inline the aliases here.  */
238
252
           "CP1361" "\0" "JOHAB" "\0"
239
253
           "CP20127" "\0" "ASCII" "\0"
240
254
           "CP20866" "\0" "KOI8-R" "\0"
 
255
           "CP20936" "\0" "GB2312" "\0"
241
256
           "CP21866" "\0" "KOI8-RU" "\0"
242
257
           "CP28591" "\0" "ISO-8859-1" "\0"
243
258
           "CP28592" "\0" "ISO-8859-2" "\0"
248
263
           "CP28597" "\0" "ISO-8859-7" "\0"
249
264
           "CP28598" "\0" "ISO-8859-8" "\0"
250
265
           "CP28599" "\0" "ISO-8859-9" "\0"
251
 
           "CP28605" "\0" "ISO-8859-15" "\0";
 
266
           "CP28605" "\0" "ISO-8859-15" "\0"
 
267
           "CP38598" "\0" "ISO-8859-8" "\0"
 
268
           "CP51932" "\0" "EUC-JP" "\0"
 
269
           "CP51936" "\0" "GB2312" "\0"
 
270
           "CP51949" "\0" "EUC-KR" "\0"
 
271
           "CP51950" "\0" "EUC-TW" "\0"
 
272
           "CP54936" "\0" "GB18030" "\0"
 
273
           "CP65001" "\0" "UTF-8" "\0";
252
274
# endif
253
275
#endif
254
276
 
268
290
STATIC
269
291
#endif
270
292
const char *
271
 
locale_charset ()
 
293
locale_charset (void)
272
294
{
273
295
  const char *codeset;
274
296
  const char *aliases;
275
297
 
276
 
#if !(defined WIN32 || defined OS2)
 
298
#if !(defined WIN32_NATIVE || defined OS2)
277
299
 
278
300
# if HAVE_LANGINFO_CODESET
279
301
 
280
302
  /* Most systems support nl_langinfo (CODESET) nowadays.  */
281
303
  codeset = nl_langinfo (CODESET);
282
304
 
 
305
#  ifdef __CYGWIN__
 
306
  /* Cygwin 2006 does not have locales.  nl_langinfo (CODESET) always
 
307
     returns "US-ASCII".  As long as this is not fixed, return the suffix
 
308
     of the locale name from the environment variables (if present) or
 
309
     the codepage as a number.  */
 
310
  if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0)
 
311
    {
 
312
      const char *locale;
 
313
      static char buf[2 + 10 + 1];
 
314
 
 
315
      locale = getenv ("LC_ALL");
 
316
      if (locale == NULL || locale[0] == '\0')
 
317
        {
 
318
          locale = getenv ("LC_CTYPE");
 
319
          if (locale == NULL || locale[0] == '\0')
 
320
            locale = getenv ("LANG");
 
321
        }
 
322
      if (locale != NULL && locale[0] != '\0')
 
323
        {
 
324
          /* If the locale name contains an encoding after the dot, return
 
325
             it.  */
 
326
          const char *dot = strchr (locale, '.');
 
327
 
 
328
          if (dot != NULL)
 
329
            {
 
330
              const char *modifier;
 
331
 
 
332
              dot++;
 
333
              /* Look for the possible @... trailer and remove it, if any.  */
 
334
              modifier = strchr (dot, '@');
 
335
              if (modifier == NULL)
 
336
                return dot;
 
337
              if (modifier - dot < sizeof (buf))
 
338
                {
 
339
                  memcpy (buf, dot, modifier - dot);
 
340
                  buf [modifier - dot] = '\0';
 
341
                  return buf;
 
342
                }
 
343
            }
 
344
        }
 
345
 
 
346
      /* Woe32 has a function returning the locale's codepage as a number.  */
 
347
      sprintf (buf, "CP%u", GetACP ());
 
348
      codeset = buf;
 
349
    }
 
350
#  endif
 
351
 
283
352
# else
284
353
 
285
354
  /* On old systems which lack it, use setlocale or getenv.  */
310
379
 
311
380
# endif
312
381
 
313
 
#elif defined WIN32
 
382
#elif defined WIN32_NATIVE
314
383
 
315
384
  static char buf[2 + 10 + 1];
316
385