PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pg_locale.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  collate_methods
 
struct  pg_locale_struct
 

Macros

#define LOCALE_NAME_BUFLEN   128
 

Typedefs

typedef struct pg_locale_structpg_locale_t
 

Functions

bool check_locale (int category, const char *locale, char **canonname)
 
char * pg_perm_setlocale (int category, const char *locale)
 
struct lconv * PGLC_localeconv (void)
 
void cache_locale_time (void)
 
void init_database_collation (void)
 
pg_locale_t pg_newlocale_from_collation (Oid collid)
 
char * get_collation_actual_version (char collprovider, const char *collcollate)
 
size_t pg_strlower (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
size_t pg_strtitle (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
size_t pg_strupper (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
size_t pg_strfold (char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
int pg_strcoll (const char *arg1, const char *arg2, pg_locale_t locale)
 
int pg_strncoll (const char *arg1, ssize_t len1, const char *arg2, ssize_t len2, pg_locale_t locale)
 
bool pg_strxfrm_enabled (pg_locale_t locale)
 
size_t pg_strxfrm (char *dest, const char *src, size_t destsize, pg_locale_t locale)
 
size_t pg_strnxfrm (char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
bool pg_strxfrm_prefix_enabled (pg_locale_t locale)
 
size_t pg_strxfrm_prefix (char *dest, const char *src, size_t destsize, pg_locale_t locale)
 
size_t pg_strnxfrm_prefix (char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)
 
int builtin_locale_encoding (const char *locale)
 
const char * builtin_validate_locale (int encoding, const char *locale)
 
void icu_validate_locale (const char *loc_str)
 
char * icu_language_tag (const char *loc_str, int elevel)
 
void report_newlocale_failure (const char *localename)
 
size_t wchar2char (char *to, const wchar_t *from, size_t tolen, pg_locale_t locale)
 
size_t char2wchar (wchar_t *to, size_t tolen, const char *from, size_t fromlen, pg_locale_t locale)
 

Variables

PGDLLIMPORT char * locale_messages
 
PGDLLIMPORT char * locale_monetary
 
PGDLLIMPORT char * locale_numeric
 
PGDLLIMPORT char * locale_time
 
PGDLLIMPORT int icu_validation_level
 
PGDLLIMPORT char * localized_abbrev_days []
 
PGDLLIMPORT char * localized_full_days []
 
PGDLLIMPORT char * localized_abbrev_months []
 
PGDLLIMPORT char * localized_full_months []
 
PGDLLIMPORT bool database_ctype_is_c
 

Macro Definition Documentation

◆ LOCALE_NAME_BUFLEN

#define LOCALE_NAME_BUFLEN   128

Definition at line 20 of file pg_locale.h.

Typedef Documentation

◆ pg_locale_t

typedef struct pg_locale_struct* pg_locale_t

Definition at line 51 of file pg_locale.h.

Function Documentation

◆ builtin_locale_encoding()

int builtin_locale_encoding ( const char *  locale)

Definition at line 1471 of file pg_locale.c.

1472{
1473 if (strcmp(locale, "C") == 0)
1474 return -1;
1475 else if (strcmp(locale, "C.UTF-8") == 0)
1476 return PG_UTF8;
1477 else if (strcmp(locale, "PG_UNICODE_FAST") == 0)
1478 return PG_UTF8;
1479
1480
1481 ereport(ERROR,
1482 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1483 errmsg("invalid locale name \"%s\" for builtin provider",
1484 locale)));
1485
1486 return 0; /* keep compiler quiet */
1487}
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
static char * locale
Definition: initdb.c:140
@ PG_UTF8
Definition: pg_wchar.h:232

References ereport, errcode(), errmsg(), ERROR, locale, and PG_UTF8.

Referenced by builtin_validate_locale(), and DefineCollation().

◆ builtin_validate_locale()

const char * builtin_validate_locale ( int  encoding,
const char *  locale 
)

Definition at line 1495 of file pg_locale.c.

1496{
1497 const char *canonical_name = NULL;
1498 int required_encoding;
1499
1500 if (strcmp(locale, "C") == 0)
1501 canonical_name = "C";
1502 else if (strcmp(locale, "C.UTF-8") == 0 || strcmp(locale, "C.UTF8") == 0)
1503 canonical_name = "C.UTF-8";
1504 else if (strcmp(locale, "PG_UNICODE_FAST") == 0)
1505 canonical_name = "PG_UNICODE_FAST";
1506
1507 if (!canonical_name)
1508 ereport(ERROR,
1509 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1510 errmsg("invalid locale name \"%s\" for builtin provider",
1511 locale)));
1512
1513 required_encoding = builtin_locale_encoding(canonical_name);
1514 if (required_encoding >= 0 && encoding != required_encoding)
1515 ereport(ERROR,
1516 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1517 errmsg("encoding \"%s\" does not match locale \"%s\"",
1519
1520 return canonical_name;
1521}
int32 encoding
Definition: pg_database.h:41
int builtin_locale_encoding(const char *locale)
Definition: pg_locale.c:1471
#define pg_encoding_to_char
Definition: pg_wchar.h:630

References builtin_locale_encoding(), encoding, ereport, errcode(), errmsg(), ERROR, locale, and pg_encoding_to_char.

Referenced by create_pg_locale_builtin(), createdb(), and DefineCollation().

◆ cache_locale_time()

void cache_locale_time ( void  )

Definition at line 720 of file pg_locale.c.

721{
722 char buf[(2 * 7 + 2 * 12) * MAX_L10N_DATA];
723 char *bufptr;
724 time_t timenow;
725 struct tm *timeinfo;
726 struct tm timeinfobuf;
727 bool strftimefail = false;
728 int encoding;
729 int i;
731
732 /* did we do this already? */
734 return;
735
736 elog(DEBUG3, "cache_locale_time() executed; locale: \"%s\"", locale_time);
737
738 errno = ENOENT;
739#ifdef WIN32
740 locale = _create_locale(LC_ALL, locale_time);
741 if (locale == (locale_t) 0)
742 _dosmaperr(GetLastError());
743#else
744 locale = newlocale(LC_ALL_MASK, locale_time, (locale_t) 0);
745#endif
746 if (!locale)
748
749 /* We use times close to current time as data for strftime(). */
750 timenow = time(NULL);
751 timeinfo = gmtime_r(&timenow, &timeinfobuf);
752
753 /* Store the strftime results in MAX_L10N_DATA-sized portions of buf[] */
754 bufptr = buf;
755
756 /*
757 * MAX_L10N_DATA is sufficient buffer space for every known locale, and
758 * POSIX defines no strftime() errors. (Buffer space exhaustion is not an
759 * error.) An implementation might report errors (e.g. ENOMEM) by
760 * returning 0 (or, less plausibly, a negative value) and setting errno.
761 * Report errno just in case the implementation did that, but clear it in
762 * advance of the calls so we don't emit a stale, unrelated errno.
763 */
764 errno = 0;
765
766 /* localized days */
767 for (i = 0; i < 7; i++)
768 {
769 timeinfo->tm_wday = i;
770 if (strftime_l(bufptr, MAX_L10N_DATA, "%a", timeinfo, locale) <= 0)
771 strftimefail = true;
772 bufptr += MAX_L10N_DATA;
773 if (strftime_l(bufptr, MAX_L10N_DATA, "%A", timeinfo, locale) <= 0)
774 strftimefail = true;
775 bufptr += MAX_L10N_DATA;
776 }
777
778 /* localized months */
779 for (i = 0; i < 12; i++)
780 {
781 timeinfo->tm_mon = i;
782 timeinfo->tm_mday = 1; /* make sure we don't have invalid date */
783 if (strftime_l(bufptr, MAX_L10N_DATA, "%b", timeinfo, locale) <= 0)
784 strftimefail = true;
785 bufptr += MAX_L10N_DATA;
786 if (strftime_l(bufptr, MAX_L10N_DATA, "%B", timeinfo, locale) <= 0)
787 strftimefail = true;
788 bufptr += MAX_L10N_DATA;
789 }
790
791#ifdef WIN32
792 _free_locale(locale);
793#else
794 freelocale(locale);
795#endif
796
797 /*
798 * At this point we've done our best to clean up, and can throw errors, or
799 * call functions that might throw errors, with a clean conscience.
800 */
801 if (strftimefail)
802 elog(ERROR, "strftime_l() failed");
803
804#ifndef WIN32
805
806 /*
807 * As in PGLC_localeconv(), we must convert strftime()'s output from the
808 * encoding implied by LC_TIME to the database encoding. If we can't
809 * identify the LC_TIME encoding, just perform encoding validation.
810 */
812 if (encoding < 0)
814
815#else
816
817 /*
818 * On Windows, strftime_win32() always returns UTF8 data, so convert from
819 * that if necessary.
820 */
822
823#endif /* WIN32 */
824
825 bufptr = buf;
826
827 /* localized days */
828 for (i = 0; i < 7; i++)
829 {
831 bufptr += MAX_L10N_DATA;
833 bufptr += MAX_L10N_DATA;
834 }
835 localized_abbrev_days[7] = NULL;
836 localized_full_days[7] = NULL;
837
838 /* localized months */
839 for (i = 0; i < 12; i++)
840 {
842 bufptr += MAX_L10N_DATA;
844 bufptr += MAX_L10N_DATA;
845 }
846 localized_abbrev_months[12] = NULL;
847 localized_full_months[12] = NULL;
848
849 CurrentLCTimeValid = true;
850}
#define DEBUG3
Definition: elog.h:28
#define elog(elevel,...)
Definition: elog.h:226
int i
Definition: isn.c:77
static struct pg_tm tm
Definition: localtime.c:104
char * localized_full_months[12+1]
Definition: pg_locale.c:125
static bool CurrentLCTimeValid
Definition: pg_locale.c:134
char * locale_time
Definition: pg_locale.c:111
static void cache_single_string(char **dst, const char *src, int encoding)
Definition: pg_locale.c:697
#define MAX_L10N_DATA
Definition: pg_locale.c:65
char * localized_abbrev_months[12+1]
Definition: pg_locale.c:124
char * localized_full_days[7+1]
Definition: pg_locale.c:123
char * localized_abbrev_days[7+1]
Definition: pg_locale.c:122
void report_newlocale_failure(const char *localename)
static char * buf
Definition: pg_test_fsync.c:72
@ PG_SQL_ASCII
Definition: pg_wchar.h:226
int pg_get_encoding_from_locale(const char *ctype, bool write_message)
Definition: chklocale.c:301
#define locale_t
Definition: win32_port.h:432
void _dosmaperr(unsigned long)
Definition: win32error.c:177

References _dosmaperr(), buf, cache_single_string(), CurrentLCTimeValid, DEBUG3, elog, encoding, ERROR, i, locale, locale_t, locale_time, localized_abbrev_days, localized_abbrev_months, localized_full_days, localized_full_months, MAX_L10N_DATA, pg_get_encoding_from_locale(), PG_SQL_ASCII, PG_UTF8, report_newlocale_failure(), and tm.

Referenced by DCH_from_char(), and DCH_to_char().

◆ char2wchar()

size_t char2wchar ( wchar_t *  to,
size_t  tolen,
const char *  from,
size_t  fromlen,
pg_locale_t  locale 
)

Definition at line 936 of file pg_locale_libc.c.

938{
939 size_t result;
940
941 if (tolen == 0)
942 return 0;
943
944#ifdef WIN32
945 /* See WIN32 "Unicode" comment above */
947 {
948 /* Win32 API does not work for zero-length input */
949 if (fromlen == 0)
950 result = 0;
951 else
952 {
953 result = MultiByteToWideChar(CP_UTF8, 0, from, fromlen, to, tolen - 1);
954 /* A zero return is failure */
955 if (result == 0)
956 result = -1;
957 }
958
959 if (result != -1)
960 {
961 Assert(result < tolen);
962 /* Append trailing null wchar (MultiByteToWideChar() does not) */
963 to[result] = 0;
964 }
965 }
966 else
967#endif /* WIN32 */
968 {
969 /* mbstowcs requires ending '\0' */
970 char *str = pnstrdup(from, fromlen);
971
972 if (locale == (pg_locale_t) 0)
973 {
974 /* Use mbstowcs directly for the default locale */
975 result = mbstowcs(to, str, tolen);
976 }
977 else
978 {
979 /* Use mbstowcs_l for nondefault locales */
980 result = mbstowcs_l(to, str, tolen, locale->info.lt);
981 }
982
983 pfree(str);
984 }
985
986 if (result == -1)
987 {
988 /*
989 * Invalid multibyte character encountered. We try to give a useful
990 * error message by letting pg_verifymbstr check the string. But it's
991 * possible that the string is OK to us, and not OK to mbstowcs ---
992 * this suggests that the LC_CTYPE locale is different from the
993 * database encoding. Give a generic error message if pg_verifymbstr
994 * can't find anything wrong.
995 */
996 pg_verifymbstr(from, fromlen, false); /* might not return */
997 /* but if it does ... */
999 (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
1000 errmsg("invalid multibyte character for locale"),
1001 errhint("The server's LC_CTYPE locale is probably incompatible with the database encoding.")));
1002 }
1003
1004 return result;
1005}
int errhint(const char *fmt,...)
Definition: elog.c:1318
Assert(PointerIsAligned(start, uint64))
const char * str
int GetDatabaseEncoding(void)
Definition: mbutils.c:1261
bool pg_verifymbstr(const char *mbstr, int len, bool noError)
Definition: mbutils.c:1556
void pfree(void *pointer)
Definition: mcxt.c:2146
char * pnstrdup(const char *in, Size len)
Definition: mcxt.c:2332
static size_t mbstowcs_l(wchar_t *dest, const char *src, size_t n, locale_t loc)

References Assert(), ereport, errcode(), errhint(), errmsg(), ERROR, GetDatabaseEncoding(), locale, mbstowcs_l(), pfree(), PG_UTF8, pg_verifymbstr(), pnstrdup(), and str.

Referenced by strlower_libc_mb(), strtitle_libc_mb(), strupper_libc_mb(), t_isalnum(), t_isalpha(), and TParserInit().

◆ check_locale()

bool check_locale ( int  category,
const char *  locale,
char **  canonname 
)

Definition at line 293 of file pg_locale.c.

294{
295 char *save;
296 char *res;
297
298 /* Don't let Windows' non-ASCII locale names in. */
299 if (!pg_is_ascii(locale))
300 {
302 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
303 errmsg("locale name \"%s\" contains non-ASCII characters",
304 locale)));
305 return false;
306 }
307
308 if (canonname)
309 *canonname = NULL; /* in case of failure */
310
311 save = setlocale(category, NULL);
312 if (!save)
313 return false; /* won't happen, we hope */
314
315 /* save may be pointing at a modifiable scratch variable, see above. */
316 save = pstrdup(save);
317
318 /* set the locale with setlocale, to see if it accepts it. */
319 res = setlocale(category, locale);
320
321 /* save canonical name if requested. */
322 if (res && canonname)
323 *canonname = pstrdup(res);
324
325 /* restore old value. */
326 if (!setlocale(category, save))
327 elog(WARNING, "failed to restore old locale \"%s\"", save);
328 pfree(save);
329
330 /* Don't let Windows' non-ASCII locale names out. */
331 if (canonname && *canonname && !pg_is_ascii(*canonname))
332 {
334 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
335 errmsg("locale name \"%s\" contains non-ASCII characters",
336 *canonname)));
337 pfree(*canonname);
338 *canonname = NULL;
339 return false;
340 }
341
342 return (res != NULL);
343}
#define WARNING
Definition: elog.h:36
char * pstrdup(const char *in)
Definition: mcxt.c:2321
bool pg_is_ascii(const char *str)
Definition: string.c:132
#define setlocale(a, b)
Definition: win32_port.h:475

References elog, ereport, errcode(), errmsg(), locale, pfree(), pg_is_ascii(), pstrdup(), setlocale, and WARNING.

Referenced by check_locale_messages(), check_locale_monetary(), check_locale_numeric(), check_locale_time(), and createdb().

◆ get_collation_actual_version()

char * get_collation_actual_version ( char  collprovider,
const char *  collcollate 
)

Definition at line 1239 of file pg_locale.c.

1240{
1241 char *collversion = NULL;
1242
1243 if (collprovider == COLLPROVIDER_BUILTIN)
1244 collversion = get_collation_actual_version_builtin(collcollate);
1245#ifdef USE_ICU
1246 else if (collprovider == COLLPROVIDER_ICU)
1247 collversion = get_collation_actual_version_icu(collcollate);
1248#endif
1249 else if (collprovider == COLLPROVIDER_LIBC)
1250 collversion = get_collation_actual_version_libc(collcollate);
1251
1252 return collversion;
1253}
char * get_collation_actual_version_libc(const char *collcollate)
char * get_collation_actual_version_builtin(const char *collcollate)

References get_collation_actual_version_builtin(), and get_collation_actual_version_libc().

Referenced by AlterCollation(), AlterDatabaseRefreshColl(), CheckMyDatabase(), create_pg_locale(), createdb(), DefineCollation(), pg_collation_actual_version(), pg_database_collation_actual_version(), and pg_import_system_collations().

◆ icu_language_tag()

char * icu_language_tag ( const char *  loc_str,
int  elevel 
)

Definition at line 1535 of file pg_locale.c.

1536{
1537#ifdef USE_ICU
1538 UErrorCode status;
1539 char *langtag;
1540 size_t buflen = 32; /* arbitrary starting buffer size */
1541 const bool strict = true;
1542
1543 /*
1544 * A BCP47 language tag doesn't have a clearly-defined upper limit (cf.
1545 * RFC5646 section 4.4). Additionally, in older ICU versions,
1546 * uloc_toLanguageTag() doesn't always return the ultimate length on the
1547 * first call, necessitating a loop.
1548 */
1549 langtag = palloc(buflen);
1550 while (true)
1551 {
1552 status = U_ZERO_ERROR;
1553 uloc_toLanguageTag(loc_str, langtag, buflen, strict, &status);
1554
1555 /* try again if the buffer is not large enough */
1556 if ((status == U_BUFFER_OVERFLOW_ERROR ||
1557 status == U_STRING_NOT_TERMINATED_WARNING) &&
1558 buflen < MaxAllocSize)
1559 {
1560 buflen = Min(buflen * 2, MaxAllocSize);
1561 langtag = repalloc(langtag, buflen);
1562 continue;
1563 }
1564
1565 break;
1566 }
1567
1568 if (U_FAILURE(status))
1569 {
1570 pfree(langtag);
1571
1572 if (elevel > 0)
1573 ereport(elevel,
1574 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1575 errmsg("could not convert locale name \"%s\" to language tag: %s",
1576 loc_str, u_errorName(status))));
1577 return NULL;
1578 }
1579
1580 return langtag;
1581#else /* not USE_ICU */
1582 ereport(ERROR,
1583 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1584 errmsg("ICU is not supported in this build")));
1585 return NULL; /* keep compiler quiet */
1586#endif /* not USE_ICU */
1587}
#define Min(x, y)
Definition: c.h:975
#define MaxAllocSize
Definition: fe_memutils.h:22
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:2166
void * palloc(Size size)
Definition: mcxt.c:1939

References ereport, errcode(), errmsg(), ERROR, MaxAllocSize, Min, palloc(), pfree(), and repalloc().

Referenced by createdb(), DefineCollation(), and pg_import_system_collations().

◆ icu_validate_locale()

void icu_validate_locale ( const char *  loc_str)

Definition at line 1593 of file pg_locale.c.

1594{
1595#ifdef USE_ICU
1596 UCollator *collator;
1597 UErrorCode status;
1598 char lang[ULOC_LANG_CAPACITY];
1599 bool found = false;
1600 int elevel = icu_validation_level;
1601
1602 /* no validation */
1603 if (elevel < 0)
1604 return;
1605
1606 /* downgrade to WARNING during pg_upgrade */
1607 if (IsBinaryUpgrade && elevel > WARNING)
1608 elevel = WARNING;
1609
1610 /* validate that we can extract the language */
1611 status = U_ZERO_ERROR;
1612 uloc_getLanguage(loc_str, lang, ULOC_LANG_CAPACITY, &status);
1613 if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING)
1614 {
1615 ereport(elevel,
1616 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1617 errmsg("could not get language from ICU locale \"%s\": %s",
1618 loc_str, u_errorName(status)),
1619 errhint("To disable ICU locale validation, set the parameter \"%s\" to \"%s\".",
1620 "icu_validation_level", "disabled")));
1621 return;
1622 }
1623
1624 /* check for special language name */
1625 if (strcmp(lang, "") == 0 ||
1626 strcmp(lang, "root") == 0 || strcmp(lang, "und") == 0)
1627 found = true;
1628
1629 /* search for matching language within ICU */
1630 for (int32_t i = 0; !found && i < uloc_countAvailable(); i++)
1631 {
1632 const char *otherloc = uloc_getAvailable(i);
1633 char otherlang[ULOC_LANG_CAPACITY];
1634
1635 status = U_ZERO_ERROR;
1636 uloc_getLanguage(otherloc, otherlang, ULOC_LANG_CAPACITY, &status);
1637 if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING)
1638 continue;
1639
1640 if (strcmp(lang, otherlang) == 0)
1641 found = true;
1642 }
1643
1644 if (!found)
1645 ereport(elevel,
1646 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1647 errmsg("ICU locale \"%s\" has unknown language \"%s\"",
1648 loc_str, lang),
1649 errhint("To disable ICU locale validation, set the parameter \"%s\" to \"%s\".",
1650 "icu_validation_level", "disabled")));
1651
1652 /* check that it can be opened */
1653 collator = pg_ucol_open(loc_str);
1654 ucol_close(collator);
1655#else /* not USE_ICU */
1656 /* could get here if a collation was created by a build with ICU */
1657 ereport(ERROR,
1658 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1659 errmsg("ICU is not supported in this build")));
1660#endif /* not USE_ICU */
1661}
bool IsBinaryUpgrade
Definition: globals.c:122
int icu_validation_level
Definition: pg_locale.c:113

References ereport, errcode(), errhint(), errmsg(), ERROR, i, icu_validation_level, IsBinaryUpgrade, and WARNING.

Referenced by createdb(), and DefineCollation().

◆ init_database_collation()

void init_database_collation ( void  )

Definition at line 1146 of file pg_locale.c.

1147{
1148 HeapTuple tup;
1149 Form_pg_database dbform;
1150 pg_locale_t result;
1151
1152 Assert(default_locale == NULL);
1153
1154 /* Fetch our pg_database row normally, via syscache */
1155 tup = SearchSysCache1(DATABASEOID, ObjectIdGetDatum(MyDatabaseId));
1156 if (!HeapTupleIsValid(tup))
1157 elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
1158 dbform = (Form_pg_database) GETSTRUCT(tup);
1159
1160 if (dbform->datlocprovider == COLLPROVIDER_BUILTIN)
1161 result = create_pg_locale_builtin(DEFAULT_COLLATION_OID,
1163 else if (dbform->datlocprovider == COLLPROVIDER_ICU)
1164 result = create_pg_locale_icu(DEFAULT_COLLATION_OID,
1166 else if (dbform->datlocprovider == COLLPROVIDER_LIBC)
1167 result = create_pg_locale_libc(DEFAULT_COLLATION_OID,
1169 else
1170 /* shouldn't happen */
1171 PGLOCALE_SUPPORT_ERROR(dbform->datlocprovider);
1172
1173 result->is_default = true;
1174 ReleaseSysCache(tup);
1175
1176 default_locale = result;
1177}
Oid MyDatabaseId
Definition: globals.c:95
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
MemoryContext TopMemoryContext
Definition: mcxt.c:165
FormData_pg_database * Form_pg_database
Definition: pg_database.h:96
pg_locale_t create_pg_locale_libc(Oid collid, MemoryContext context)
pg_locale_t create_pg_locale_builtin(Oid collid, MemoryContext context)
#define PGLOCALE_SUPPORT_ERROR(provider)
Definition: pg_locale.c:56
pg_locale_t create_pg_locale_icu(Oid collid, MemoryContext context)
static pg_locale_t default_locale
Definition: pg_locale.c:130
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:257
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:269
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:221

References Assert(), create_pg_locale_builtin(), create_pg_locale_icu(), create_pg_locale_libc(), default_locale, elog, ERROR, GETSTRUCT(), HeapTupleIsValid, pg_locale_struct::is_default, MyDatabaseId, ObjectIdGetDatum(), PGLOCALE_SUPPORT_ERROR, ReleaseSysCache(), SearchSysCache1(), and TopMemoryContext.

Referenced by CheckMyDatabase().

◆ pg_newlocale_from_collation()

pg_locale_t pg_newlocale_from_collation ( Oid  collid)

Definition at line 1188 of file pg_locale.c.

1189{
1190 collation_cache_entry *cache_entry;
1191 bool found;
1192
1193 if (collid == DEFAULT_COLLATION_OID)
1194 return default_locale;
1195
1196 if (!OidIsValid(collid))
1197 elog(ERROR, "cache lookup failed for collation %u", collid);
1198
1200
1203
1204 if (CollationCache == NULL)
1205 {
1207 "collation cache",
1209 CollationCache = collation_cache_create(CollationCacheContext,
1210 16, NULL);
1211 }
1212
1213 cache_entry = collation_cache_insert(CollationCache, collid, &found);
1214 if (!found)
1215 {
1216 /*
1217 * Make sure cache entry is marked invalid, in case we fail before
1218 * setting things.
1219 */
1220 cache_entry->locale = 0;
1221 }
1222
1223 if (cache_entry->locale == 0)
1224 {
1226 }
1227
1229 last_collation_cache_locale = cache_entry->locale;
1230
1231 return cache_entry->locale;
1232}
#define OidIsValid(objectId)
Definition: c.h:746
Oid collid
#define AllocSetContextCreate
Definition: memutils.h:149
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:180
static pg_locale_t last_collation_cache_locale
Definition: pg_locale.c:169
static pg_locale_t create_pg_locale(Oid collid, MemoryContext context)
Definition: pg_locale.c:1067
static MemoryContext CollationCacheContext
Definition: pg_locale.c:161
static collation_cache_hash * CollationCache
Definition: pg_locale.c:162
static Oid last_collation_cache_oid
Definition: pg_locale.c:168
static void AssertCouldGetRelation(void)
Definition: relcache.h:44
Definition: pg_locale.c:139
pg_locale_t locale
Definition: pg_locale.c:141

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, AssertCouldGetRelation(), CollationCache, CollationCacheContext, collid, create_pg_locale(), default_locale, elog, ERROR, last_collation_cache_locale, last_collation_cache_oid, collation_cache_entry::locale, OidIsValid, and TopMemoryContext.

Referenced by bpchareq(), bpcharne(), btvarstrequalimage(), convert_string_datum(), DefineCollation(), Generic_Text_IC_like(), GenericMatchText(), hashbpchar(), hashbpcharextended(), hashtext(), hashtextextended(), like_fixed_prefix(), make_greater_string(), match_pattern_prefix(), pg_set_regex_collation(), spg_text_inner_consistent(), str_casefold(), str_initcap(), str_tolower(), str_toupper(), text_position(), text_position_setup(), text_starts_with(), texteq(), textne(), varstr_cmp(), and varstr_sortsupport().

◆ pg_perm_setlocale()

char * pg_perm_setlocale ( int  category,
const char *  locale 
)

Definition at line 190 of file pg_locale.c.

191{
192 char *result;
193 const char *envvar;
194
195#ifndef WIN32
196 result = setlocale(category, locale);
197#else
198
199 /*
200 * On Windows, setlocale(LC_MESSAGES) does not work, so just assume that
201 * the given value is good and set it in the environment variables. We
202 * must ignore attempts to set to "", which means "keep using the old
203 * environment value".
204 */
205#ifdef LC_MESSAGES
206 if (category == LC_MESSAGES)
207 {
208 result = (char *) locale;
209 if (locale == NULL || locale[0] == '\0')
210 return result;
211 }
212 else
213#endif
214 result = setlocale(category, locale);
215#endif /* WIN32 */
216
217 if (result == NULL)
218 return result; /* fall out immediately on failure */
219
220 /*
221 * Use the right encoding in translated messages. Under ENABLE_NLS, let
222 * pg_bind_textdomain_codeset() figure it out. Under !ENABLE_NLS, message
223 * format strings are ASCII, but database-encoding strings may enter the
224 * message via %s. This makes the overall message encoding equal to the
225 * database encoding.
226 */
227 if (category == LC_CTYPE)
228 {
229 static char save_lc_ctype[LOCALE_NAME_BUFLEN];
230
231 /* copy setlocale() return value before callee invokes it again */
232 strlcpy(save_lc_ctype, result, sizeof(save_lc_ctype));
233 result = save_lc_ctype;
234
235#ifdef ENABLE_NLS
236 SetMessageEncoding(pg_bind_textdomain_codeset(textdomain(NULL)));
237#else
239#endif
240 }
241
242 switch (category)
243 {
244 case LC_COLLATE:
245 envvar = "LC_COLLATE";
246 break;
247 case LC_CTYPE:
248 envvar = "LC_CTYPE";
249 break;
250#ifdef LC_MESSAGES
251 case LC_MESSAGES:
252 envvar = "LC_MESSAGES";
253#ifdef WIN32
254 result = IsoLocaleName(locale);
255 if (result == NULL)
256 result = (char *) locale;
257 elog(DEBUG3, "IsoLocaleName() executed; locale: \"%s\"", result);
258#endif /* WIN32 */
259 break;
260#endif /* LC_MESSAGES */
261 case LC_MONETARY:
262 envvar = "LC_MONETARY";
263 break;
264 case LC_NUMERIC:
265 envvar = "LC_NUMERIC";
266 break;
267 case LC_TIME:
268 envvar = "LC_TIME";
269 break;
270 default:
271 elog(FATAL, "unrecognized LC category: %d", category);
272 return NULL; /* keep compiler quiet */
273 }
274
275 if (setenv(envvar, result, 1) != 0)
276 return NULL;
277
278 return result;
279}
#define FATAL
Definition: elog.h:41
void SetMessageEncoding(int encoding)
Definition: mbutils.c:1171
#define LOCALE_NAME_BUFLEN
Definition: pg_locale.h:20
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define setenv(x, y, z)
Definition: win32_port.h:545

References DEBUG3, elog, FATAL, GetDatabaseEncoding(), locale, LOCALE_NAME_BUFLEN, setenv, setlocale, SetMessageEncoding(), and strlcpy().

Referenced by assign_locale_messages(), CheckMyDatabase(), and init_locale().

◆ pg_strcoll()

int pg_strcoll ( const char *  arg1,
const char *  arg2,
pg_locale_t  locale 
)

Definition at line 1338 of file pg_locale.c.

1339{
1340 return locale->collate->strncoll(arg1, -1, arg2, -1, locale);
1341}

References locale.

Referenced by varstrfastcmp_locale().

◆ pg_strfold()

size_t pg_strfold ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 1313 of file pg_locale.c.

1315{
1316 if (locale->provider == COLLPROVIDER_BUILTIN)
1317 return strfold_builtin(dst, dstsize, src, srclen, locale);
1318#ifdef USE_ICU
1319 else if (locale->provider == COLLPROVIDER_ICU)
1320 return strfold_icu(dst, dstsize, src, srclen, locale);
1321#endif
1322 /* for libc, just use strlower */
1323 else if (locale->provider == COLLPROVIDER_LIBC)
1324 return strlower_libc(dst, dstsize, src, srclen, locale);
1325 else
1326 /* shouldn't happen */
1327 PGLOCALE_SUPPORT_ERROR(locale->provider);
1328
1329 return 0; /* keep compiler quiet */
1330}
size_t strfold_icu(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
size_t strlower_libc(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
size_t strfold_builtin(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)

References locale, PGLOCALE_SUPPORT_ERROR, strfold_builtin(), strfold_icu(), and strlower_libc().

Referenced by str_casefold().

◆ pg_strlower()

size_t pg_strlower ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 1256 of file pg_locale.c.

1258{
1259 if (locale->provider == COLLPROVIDER_BUILTIN)
1260 return strlower_builtin(dst, dstsize, src, srclen, locale);
1261#ifdef USE_ICU
1262 else if (locale->provider == COLLPROVIDER_ICU)
1263 return strlower_icu(dst, dstsize, src, srclen, locale);
1264#endif
1265 else if (locale->provider == COLLPROVIDER_LIBC)
1266 return strlower_libc(dst, dstsize, src, srclen, locale);
1267 else
1268 /* shouldn't happen */
1269 PGLOCALE_SUPPORT_ERROR(locale->provider);
1270
1271 return 0; /* keep compiler quiet */
1272}
size_t strlower_icu(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
size_t strlower_builtin(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)

References locale, PGLOCALE_SUPPORT_ERROR, strlower_builtin(), strlower_icu(), and strlower_libc().

Referenced by str_tolower().

◆ pg_strncoll()

int pg_strncoll ( const char *  arg1,
ssize_t  len1,
const char *  arg2,
ssize_t  len2,
pg_locale_t  locale 
)

Definition at line 1358 of file pg_locale.c.

1360{
1361 return locale->collate->strncoll(arg1, len1, arg2, len2, locale);
1362}

References locale.

Referenced by MatchText(), text_position_next_internal(), and varstr_cmp().

◆ pg_strnxfrm()

size_t pg_strnxfrm ( char *  dest,
size_t  destsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 1413 of file pg_locale.c.

1415{
1416 return locale->collate->strnxfrm(dest, destsize, src, srclen, locale);
1417}

References generate_unaccent_rules::dest, and locale.

Referenced by hashbpchar(), hashbpcharextended(), hashtext(), and hashtextextended().

◆ pg_strnxfrm_prefix()

size_t pg_strnxfrm_prefix ( char *  dest,
size_t  destsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 1460 of file pg_locale.c.

1462{
1463 return locale->collate->strnxfrm_prefix(dest, destsize, src, srclen, locale);
1464}

References generate_unaccent_rules::dest, and locale.

◆ pg_strtitle()

size_t pg_strtitle ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 1275 of file pg_locale.c.

1277{
1278 if (locale->provider == COLLPROVIDER_BUILTIN)
1279 return strtitle_builtin(dst, dstsize, src, srclen, locale);
1280#ifdef USE_ICU
1281 else if (locale->provider == COLLPROVIDER_ICU)
1282 return strtitle_icu(dst, dstsize, src, srclen, locale);
1283#endif
1284 else if (locale->provider == COLLPROVIDER_LIBC)
1285 return strtitle_libc(dst, dstsize, src, srclen, locale);
1286 else
1287 /* shouldn't happen */
1288 PGLOCALE_SUPPORT_ERROR(locale->provider);
1289
1290 return 0; /* keep compiler quiet */
1291}
size_t strtitle_libc(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
size_t strtitle_icu(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
size_t strtitle_builtin(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)

References locale, PGLOCALE_SUPPORT_ERROR, strtitle_builtin(), strtitle_icu(), and strtitle_libc().

Referenced by str_initcap().

◆ pg_strupper()

size_t pg_strupper ( char *  dst,
size_t  dstsize,
const char *  src,
ssize_t  srclen,
pg_locale_t  locale 
)

Definition at line 1294 of file pg_locale.c.

1296{
1297 if (locale->provider == COLLPROVIDER_BUILTIN)
1298 return strupper_builtin(dst, dstsize, src, srclen, locale);
1299#ifdef USE_ICU
1300 else if (locale->provider == COLLPROVIDER_ICU)
1301 return strupper_icu(dst, dstsize, src, srclen, locale);
1302#endif
1303 else if (locale->provider == COLLPROVIDER_LIBC)
1304 return strupper_libc(dst, dstsize, src, srclen, locale);
1305 else
1306 /* shouldn't happen */
1307 PGLOCALE_SUPPORT_ERROR(locale->provider);
1308
1309 return 0; /* keep compiler quiet */
1310}
size_t strupper_icu(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
size_t strupper_libc(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
size_t strupper_builtin(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)

References locale, PGLOCALE_SUPPORT_ERROR, strupper_builtin(), strupper_icu(), and strupper_libc().

Referenced by str_toupper().

◆ pg_strxfrm()

size_t pg_strxfrm ( char *  dest,
const char *  src,
size_t  destsize,
pg_locale_t  locale 
)

Definition at line 1388 of file pg_locale.c.

1389{
1390 return locale->collate->strnxfrm(dest, destsize, src, -1, locale);
1391}

References generate_unaccent_rules::dest, and locale.

Referenced by convert_string_datum(), and varstr_abbrev_convert().

◆ pg_strxfrm_enabled()

bool pg_strxfrm_enabled ( pg_locale_t  locale)

Definition at line 1372 of file pg_locale.c.

1373{
1374 /*
1375 * locale->collate->strnxfrm is still a required method, even if it may
1376 * have the wrong behavior, because the planner uses it for estimates in
1377 * some cases.
1378 */
1379 return locale->collate->strxfrm_is_safe;
1380}

References locale.

Referenced by varstr_sortsupport().

◆ pg_strxfrm_prefix()

size_t pg_strxfrm_prefix ( char *  dest,
const char *  src,
size_t  destsize,
pg_locale_t  locale 
)

Definition at line 1435 of file pg_locale.c.

1437{
1438 return locale->collate->strnxfrm_prefix(dest, destsize, src, -1, locale);
1439}

References generate_unaccent_rules::dest, and locale.

Referenced by varstr_abbrev_convert().

◆ pg_strxfrm_prefix_enabled()

bool pg_strxfrm_prefix_enabled ( pg_locale_t  locale)

Definition at line 1424 of file pg_locale.c.

1425{
1426 return (locale->collate->strnxfrm_prefix != NULL);
1427}

References locale.

Referenced by varstr_abbrev_convert().

◆ PGLC_localeconv()

struct lconv * PGLC_localeconv ( void  )

Definition at line 524 of file pg_locale.c.

525{
526 static struct lconv CurrentLocaleConv;
527 static bool CurrentLocaleConvAllocated = false;
528 struct lconv *extlconv;
529 struct lconv tmp;
530 struct lconv worklconv = {0};
531
532 /* Did we do it already? */
534 return &CurrentLocaleConv;
535
536 /* Free any already-allocated storage */
537 if (CurrentLocaleConvAllocated)
538 {
539 free_struct_lconv(&CurrentLocaleConv);
540 CurrentLocaleConvAllocated = false;
541 }
542
543 /*
544 * Use thread-safe method of obtaining a copy of lconv from the operating
545 * system.
546 */
549 &tmp) != 0)
550 elog(ERROR,
551 "could not get lconv for LC_MONETARY = \"%s\", LC_NUMERIC = \"%s\": %m",
553
554 /* Must copy data now now so we can re-encode it. */
555 extlconv = &tmp;
556 worklconv.decimal_point = strdup(extlconv->decimal_point);
557 worklconv.thousands_sep = strdup(extlconv->thousands_sep);
558 worklconv.grouping = strdup(extlconv->grouping);
559 worklconv.int_curr_symbol = strdup(extlconv->int_curr_symbol);
560 worklconv.currency_symbol = strdup(extlconv->currency_symbol);
561 worklconv.mon_decimal_point = strdup(extlconv->mon_decimal_point);
562 worklconv.mon_thousands_sep = strdup(extlconv->mon_thousands_sep);
563 worklconv.mon_grouping = strdup(extlconv->mon_grouping);
564 worklconv.positive_sign = strdup(extlconv->positive_sign);
565 worklconv.negative_sign = strdup(extlconv->negative_sign);
566 /* Copy scalar fields as well */
567 worklconv.int_frac_digits = extlconv->int_frac_digits;
568 worklconv.frac_digits = extlconv->frac_digits;
569 worklconv.p_cs_precedes = extlconv->p_cs_precedes;
570 worklconv.p_sep_by_space = extlconv->p_sep_by_space;
571 worklconv.n_cs_precedes = extlconv->n_cs_precedes;
572 worklconv.n_sep_by_space = extlconv->n_sep_by_space;
573 worklconv.p_sign_posn = extlconv->p_sign_posn;
574 worklconv.n_sign_posn = extlconv->n_sign_posn;
575
576 /* Free the contents of the object populated by pg_localeconv_r(). */
577 pg_localeconv_free(&tmp);
578
579 /* If any of the preceding strdup calls failed, complain now. */
580 if (!struct_lconv_is_valid(&worklconv))
582 (errcode(ERRCODE_OUT_OF_MEMORY),
583 errmsg("out of memory")));
584
585 PG_TRY();
586 {
587 int encoding;
588
589 /*
590 * Now we must perform encoding conversion from whatever's associated
591 * with the locales into the database encoding. If we can't identify
592 * the encoding implied by LC_NUMERIC or LC_MONETARY (ie we get -1),
593 * use PG_SQL_ASCII, which will result in just validating that the
594 * strings are OK in the database encoding.
595 */
597 if (encoding < 0)
599
600 db_encoding_convert(encoding, &worklconv.decimal_point);
601 db_encoding_convert(encoding, &worklconv.thousands_sep);
602 /* grouping is not text and does not require conversion */
603
605 if (encoding < 0)
607
608 db_encoding_convert(encoding, &worklconv.int_curr_symbol);
609 db_encoding_convert(encoding, &worklconv.currency_symbol);
610 db_encoding_convert(encoding, &worklconv.mon_decimal_point);
611 db_encoding_convert(encoding, &worklconv.mon_thousands_sep);
612 /* mon_grouping is not text and does not require conversion */
613 db_encoding_convert(encoding, &worklconv.positive_sign);
614 db_encoding_convert(encoding, &worklconv.negative_sign);
615 }
616 PG_CATCH();
617 {
618 free_struct_lconv(&worklconv);
619 PG_RE_THROW();
620 }
621 PG_END_TRY();
622
623 /*
624 * Everything is good, so save the results.
625 */
626 CurrentLocaleConv = worklconv;
627 CurrentLocaleConvAllocated = true;
629 return &CurrentLocaleConv;
630}
#define PG_RE_THROW()
Definition: elog.h:405
#define PG_TRY(...)
Definition: elog.h:372
#define PG_END_TRY(...)
Definition: elog.h:397
#define PG_CATCH(...)
Definition: elog.h:382
char * locale_numeric
Definition: pg_locale.c:110
static void db_encoding_convert(int encoding, char **str)
Definition: pg_locale.c:494
static void free_struct_lconv(struct lconv *s)
Definition: pg_locale.c:444
static bool CurrentLocaleConvValid
Definition: pg_locale.c:133
static bool struct_lconv_is_valid(struct lconv *s)
Definition: pg_locale.c:463
char * locale_monetary
Definition: pg_locale.c:109
int pg_localeconv_r(const char *lc_monetary, const char *lc_numeric, struct lconv *output)
void pg_localeconv_free(struct lconv *lconv)

References CurrentLocaleConvValid, db_encoding_convert(), elog, encoding, ereport, errcode(), errmsg(), ERROR, free_struct_lconv(), locale_monetary, locale_numeric, PG_CATCH, PG_END_TRY, pg_get_encoding_from_locale(), pg_localeconv_free(), pg_localeconv_r(), PG_RE_THROW, PG_SQL_ASCII, PG_TRY, and struct_lconv_is_valid().

Referenced by cash_in(), cash_numeric(), cash_out(), int4_cash(), int8_cash(), NUM_prepare_locale(), and numeric_cash().

◆ report_newlocale_failure()

void report_newlocale_failure ( const char *  localename)

Definition at line 804 of file pg_locale_libc.c.

805{
806 int save_errno;
807
808 /*
809 * Windows doesn't provide any useful error indication from
810 * _create_locale(), and BSD-derived platforms don't seem to feel they
811 * need to set errno either (even though POSIX is pretty clear that
812 * newlocale should do so). So, if errno hasn't been set, assume ENOENT
813 * is what to report.
814 */
815 if (errno == 0)
816 errno = ENOENT;
817
818 /*
819 * ENOENT means "no such locale", not "no such file", so clarify that
820 * errno with an errdetail message.
821 */
822 save_errno = errno; /* auxiliary funcs might change errno */
824 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
825 errmsg("could not create locale \"%s\": %m",
826 localename),
827 (save_errno == ENOENT ?
828 errdetail("The operating system could not find any locale data for the locale name \"%s\".",
829 localename) : 0)));
830}
int errdetail(const char *fmt,...)
Definition: elog.c:1204

References ereport, errcode(), errdetail(), errmsg(), and ERROR.

Referenced by cache_locale_time(), and make_libc_collator().

◆ wchar2char()

size_t wchar2char ( char *  to,
const wchar_t *  from,
size_t  tolen,
pg_locale_t  locale 
)

Definition at line 882 of file pg_locale_libc.c.

883{
884 size_t result;
885
886 if (tolen == 0)
887 return 0;
888
889#ifdef WIN32
890
891 /*
892 * On Windows, the "Unicode" locales assume UTF16 not UTF8 encoding, and
893 * for some reason mbstowcs and wcstombs won't do this for us, so we use
894 * MultiByteToWideChar().
895 */
897 {
898 result = WideCharToMultiByte(CP_UTF8, 0, from, -1, to, tolen,
899 NULL, NULL);
900 /* A zero return is failure */
901 if (result <= 0)
902 result = -1;
903 else
904 {
905 Assert(result <= tolen);
906 /* Microsoft counts the zero terminator in the result */
907 result--;
908 }
909 }
910 else
911#endif /* WIN32 */
912 if (locale == (pg_locale_t) 0)
913 {
914 /* Use wcstombs directly for the default locale */
915 result = wcstombs(to, from, tolen);
916 }
917 else
918 {
919 /* Use wcstombs_l for nondefault locales */
920 result = wcstombs_l(to, from, tolen, locale->info.lt);
921 }
922
923 return result;
924}
static size_t wcstombs_l(char *dest, const wchar_t *src, size_t n, locale_t loc)

References Assert(), GetDatabaseEncoding(), locale, PG_UTF8, and wcstombs_l().

Referenced by strlower_libc_mb(), strtitle_libc_mb(), and strupper_libc_mb().

Variable Documentation

◆ database_ctype_is_c

PGDLLIMPORT bool database_ctype_is_c
extern

Definition at line 128 of file pg_locale.c.

Referenced by CheckMyDatabase(), t_isalnum(), t_isalpha(), and TParserInit().

◆ icu_validation_level

PGDLLIMPORT int icu_validation_level
extern

Definition at line 113 of file pg_locale.c.

Referenced by createdb(), DefineCollation(), and icu_validate_locale().

◆ locale_messages

PGDLLIMPORT char* locale_messages
extern

Definition at line 108 of file pg_locale.c.

◆ locale_monetary

PGDLLIMPORT char* locale_monetary
extern

Definition at line 109 of file pg_locale.c.

Referenced by PGLC_localeconv().

◆ locale_numeric

PGDLLIMPORT char* locale_numeric
extern

Definition at line 110 of file pg_locale.c.

Referenced by PGLC_localeconv().

◆ locale_time

PGDLLIMPORT char* locale_time
extern

Definition at line 111 of file pg_locale.c.

Referenced by cache_locale_time().

◆ localized_abbrev_days

PGDLLIMPORT char* localized_abbrev_days[]
extern

Definition at line 122 of file pg_locale.c.

Referenced by cache_locale_time(), DCH_from_char(), and DCH_to_char().

◆ localized_abbrev_months

PGDLLIMPORT char* localized_abbrev_months[]
extern

Definition at line 124 of file pg_locale.c.

Referenced by cache_locale_time(), DCH_from_char(), and DCH_to_char().

◆ localized_full_days

PGDLLIMPORT char* localized_full_days[]
extern

Definition at line 123 of file pg_locale.c.

Referenced by cache_locale_time(), DCH_from_char(), and DCH_to_char().

◆ localized_full_months

PGDLLIMPORT char* localized_full_months[]
extern

Definition at line 125 of file pg_locale.c.

Referenced by cache_locale_time(), DCH_from_char(), and DCH_to_char().