~ubuntu-branches/ubuntu/lucid/postgresql-8.4/lucid-proposed

« back to all changes in this revision

Viewing changes to src/backend/utils/adt/pg_locale.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-11 16:59:35 UTC
  • mfrom: (5.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090711165935-jfwin6gfrxf0gfsi
Tags: 8.4.0-2
* debian/libpq-dev.install: Ship catalog/genbki.h. (Closes: #536139)
* debian/rules: Drop --enable-cassert for final release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 *
5
5
 * Portions Copyright (c) 2002-2009, PostgreSQL Global Development Group
6
6
 *
7
 
 * $PostgreSQL: pgsql/src/backend/utils/adt/pg_locale.c,v 1.49 2009/04/01 09:17:32 heikki Exp $
 
7
 * $PostgreSQL: pgsql/src/backend/utils/adt/pg_locale.c,v 1.50 2009/06/11 14:49:03 momjian Exp $
8
8
 *
9
9
 *-----------------------------------------------------------------------
10
10
 */
11
11
 
12
12
/*----------
13
13
 * Here is how the locale stuff is handled: LC_COLLATE and LC_CTYPE
14
 
 * are fixed at CREATE DATABASE time, stored in pg_database, and cannot 
 
14
 * are fixed at CREATE DATABASE time, stored in pg_database, and cannot
15
15
 * be changed. Thus, the effects of strcoll(), strxfrm(), isupper(),
16
16
 * toupper(), etc. are always in the same fixed locale.
17
17
 *
93
93
static char lc_time_envbuf[LC_ENV_BUFSIZE];
94
94
 
95
95
#if defined(WIN32) && defined(LC_MESSAGES)
96
 
static char *IsoLocaleName(const char *); /* MSVC specific */
 
96
static char *IsoLocaleName(const char *);               /* MSVC specific */
97
97
#endif
98
98
 
99
99
 
159
159
                        result = IsoLocaleName(locale);
160
160
                        if (result == NULL)
161
161
                                result = (char *) locale;
162
 
#endif /* WIN32 */
 
162
#endif   /* WIN32 */
163
163
                        break;
164
 
#endif /* LC_MESSAGES */
 
164
#endif   /* LC_MESSAGES */
165
165
                case LC_MONETARY:
166
166
                        envvar = "LC_MONETARY";
167
167
                        envbuf = lc_monetary_envbuf;
468
468
 * pg_strftime(), which isn't locale-aware and does not need to be replaced.
469
469
 */
470
470
static size_t
471
 
strftime_win32(char *dst, size_t dstlen, const wchar_t *format, const struct tm *tm)
 
471
strftime_win32(char *dst, size_t dstlen, const wchar_t *format, const struct tm * tm)
472
472
{
473
 
        size_t  len;
474
 
        wchar_t wbuf[MAX_L10N_DATA];
475
 
        int             encoding;
 
473
        size_t          len;
 
474
        wchar_t         wbuf[MAX_L10N_DATA];
 
475
        int                     encoding;
476
476
 
477
477
        encoding = GetDatabaseEncoding();
478
478
 
479
479
        len = wcsftime(wbuf, MAX_L10N_DATA, format, tm);
480
480
        if (len == 0)
481
 
                /* strftime call failed - return 0 with the contents of dst unspecified */
 
481
 
 
482
                /*
 
483
                 * strftime call failed - return 0 with the contents of dst
 
484
                 * unspecified
 
485
                 */
482
486
                return 0;
483
487
 
484
488
        len = WideCharToMultiByte(CP_UTF8, 0, wbuf, len, dst, dstlen, NULL, NULL);
485
489
        if (len == 0)
486
490
                elog(ERROR,
487
 
                        "could not convert string to UTF-8:error %lu", GetLastError());
 
491
                         "could not convert string to UTF-8:error %lu", GetLastError());
488
492
 
489
493
        dst[len] = '\0';
490
494
        if (encoding != PG_UTF8)
491
495
        {
492
 
                char *convstr = pg_do_encoding_conversion(dst, len, PG_UTF8, encoding);
 
496
                char       *convstr = pg_do_encoding_conversion(dst, len, PG_UTF8, encoding);
 
497
 
493
498
                if (dst != convstr)
494
499
                {
495
500
                        strlcpy(dst, convstr, dstlen);
501
506
}
502
507
 
503
508
#define strftime(a,b,c,d) strftime_win32(a,b,L##c,d)
504
 
 
505
 
#endif /* WIN32 */
 
509
#endif   /* WIN32 */
506
510
 
507
511
 
508
512
/*
511
515
void
512
516
cache_locale_time(void)
513
517
{
514
 
        char            *save_lc_time;
 
518
        char       *save_lc_time;
515
519
        time_t          timenow;
516
 
        struct tm       *timeinfo;
 
520
        struct tm  *timeinfo;
517
521
        char            buf[MAX_L10N_DATA];
518
522
        char       *ptr;
519
523
        int                     i;
 
524
 
520
525
#ifdef WIN32
521
526
        char       *save_lc_ctype;
522
527
#endif
611
616
 *      contains the iso formatted locale name.
612
617
 */
613
618
static
614
 
char *IsoLocaleName(const char *winlocname)
 
619
char *
 
620
IsoLocaleName(const char *winlocname)
615
621
{
616
 
#if (_MSC_VER >= 1400) /* VC8.0 or later */
617
 
        static char     iso_lc_messages[32];
 
622
#if (_MSC_VER >= 1400)                  /* VC8.0 or later */
 
623
        static char iso_lc_messages[32];
618
624
        _locale_t       loct = NULL;
619
625
 
620
626
        if (pg_strcasecmp("c", winlocname) == 0 ||
627
633
        loct = _create_locale(LC_CTYPE, winlocname);
628
634
        if (loct != NULL)
629
635
        {
630
 
                char    isolang[32], isocrty[32];
631
 
                LCID    lcid;
 
636
                char            isolang[32],
 
637
                                        isocrty[32];
 
638
                LCID            lcid;
632
639
 
633
640
                lcid = loct->locinfo->lc_handle[LC_CTYPE];
634
641
                if (lcid == 0)
644
651
        }
645
652
        return NULL;
646
653
#else
647
 
        return NULL; /* Not supported on this version of msvc/mingw */
648
 
#endif /* _MSC_VER >= 1400 */
 
654
        return NULL;                            /* Not supported on this version of msvc/mingw */
 
655
#endif   /* _MSC_VER >= 1400 */
649
656
}
650
 
#endif /* WIN32 && LC_MESSAGES */
651
657
 
 
658
#endif   /* WIN32 && LC_MESSAGES */