PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_locale_libc.c File Reference
#include "postgres.h"
#include <limits.h>
#include <wctype.h>
#include "access/htup_details.h"
#include "catalog/pg_database.h"
#include "catalog/pg_collation.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "utils/builtins.h"
#include "utils/formatting.h"
#include "utils/memutils.h"
#include "utils/pg_locale.h"
#include "utils/syscache.h"
Include dependency graph for pg_locale_libc.c:

Go to the source code of this file.

Macros

#define TEXTBUFLEN   1024
 

Functions

pg_locale_t create_pg_locale_libc (Oid collid, MemoryContext context)
 
static int strncoll_libc (const char *arg1, size_t len1, const char *arg2, size_t len2, pg_locale_t locale)
 
static int strcoll_libc (const char *arg1, const char *arg2, pg_locale_t locale)
 
static size_t strnxfrm_libc (char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
 
static size_t strxfrm_libc (char *dest, size_t destsize, const char *src, pg_locale_t locale)
 
charget_collation_actual_version_libc (const char *collcollate)
 
static locale_t make_libc_collator (const char *collate, const char *ctype)
 
static size_t char2wchar (wchar_t *to, size_t tolen, const char *from, size_t fromlen, locale_t loc)
 
static size_t strlower_libc_sb (char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
 
static size_t strlower_libc_mb (char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
 
static size_t strtitle_libc_sb (char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
 
static size_t strtitle_libc_mb (char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
 
static size_t strupper_libc_sb (char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
 
static size_t strupper_libc_mb (char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
 
static bool wc_isdigit_libc_sb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isalpha_libc_sb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isalnum_libc_sb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isupper_libc_sb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_islower_libc_sb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isgraph_libc_sb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isprint_libc_sb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_ispunct_libc_sb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isspace_libc_sb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isxdigit_libc_sb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_iscased_libc_sb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isdigit_libc_mb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isalpha_libc_mb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isalnum_libc_mb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isupper_libc_mb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_islower_libc_mb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isgraph_libc_mb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isprint_libc_mb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_ispunct_libc_mb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isspace_libc_mb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_isxdigit_libc_mb (pg_wchar wc, pg_locale_t locale)
 
static bool wc_iscased_libc_mb (pg_wchar wc, pg_locale_t locale)
 
static pg_wchar toupper_libc_sb (pg_wchar wc, pg_locale_t locale)
 
static pg_wchar toupper_libc_mb (pg_wchar wc, pg_locale_t locale)
 
static pg_wchar tolower_libc_sb (pg_wchar wc, pg_locale_t locale)
 
static pg_wchar tolower_libc_mb (pg_wchar wc, pg_locale_t locale)
 
static size_t downcase_ident_libc_sb (char *dst, size_t dstsize, const char *src, size_t srclen, pg_locale_t locale)
 
void report_newlocale_failure (const char *localename)
 
static size_t mbstowcs_l (wchar_t *dest, const char *src, size_t n, locale_t loc)
 
static size_t wcstombs_l (char *dest, const wchar_t *src, size_t n, locale_t loc)
 
size_t wchar2char (char *to, const wchar_t *from, size_t tolen, locale_t loc)
 

Variables

static const struct ctype_methods ctype_methods_libc_sb
 
static const struct ctype_methods ctype_methods_libc_other_mb
 
static const struct ctype_methods ctype_methods_libc_utf8
 
static const struct collate_methods collate_methods_libc
 

Macro Definition Documentation

◆ TEXTBUFLEN

#define TEXTBUFLEN   1024

Definition at line 81 of file pg_locale_libc.c.

Function Documentation

◆ char2wchar()

static size_t char2wchar ( wchar_t to,
size_t  tolen,
const char from,
size_t  fromlen,
locale_t  loc 
)
static

Definition at line 1258 of file pg_locale_libc.c.

1260{
1261 size_t result;
1262
1263 if (tolen == 0)
1264 return 0;
1265
1266#ifdef WIN32
1267 /* See WIN32 "Unicode" comment above */
1269 {
1270 /* Win32 API does not work for zero-length input */
1271 if (fromlen == 0)
1272 result = 0;
1273 else
1274 {
1275 result = MultiByteToWideChar(CP_UTF8, 0, from, fromlen, to, tolen - 1);
1276 /* A zero return is failure */
1277 if (result == 0)
1278 result = -1;
1279 }
1280
1281 if (result != -1)
1282 {
1283 Assert(result < tolen);
1284 /* Append trailing null wchar (MultiByteToWideChar() does not) */
1285 to[result] = 0;
1286 }
1287 }
1288 else
1289#endif /* WIN32 */
1290 {
1291 /* mbstowcs requires ending '\0' */
1292 char *str = pnstrdup(from, fromlen);
1293
1294 if (loc == (locale_t) 0)
1295 {
1296 /* Use mbstowcs directly for the default locale */
1297 result = mbstowcs(to, str, tolen);
1298 }
1299 else
1300 {
1301 /* Use mbstowcs_l for nondefault locales */
1302 result = mbstowcs_l(to, str, tolen, loc);
1303 }
1304
1305 pfree(str);
1306 }
1307
1308 if (result == -1)
1309 {
1310 /*
1311 * Invalid multibyte character encountered. We try to give a useful
1312 * error message by letting pg_verifymbstr check the string. But it's
1313 * possible that the string is OK to us, and not OK to mbstowcs ---
1314 * this suggests that the LC_CTYPE locale is different from the
1315 * database encoding. Give a generic error message if pg_verifymbstr
1316 * can't find anything wrong.
1317 */
1318 pg_verifymbstr(from, fromlen, false); /* might not return */
1319 /* but if it does ... */
1320 ereport(ERROR,
1322 errmsg("invalid multibyte character for locale"),
1323 errhint("The server's LC_CTYPE locale is probably incompatible with the database encoding.")));
1324 }
1325
1326 return result;
1327}
#define Assert(condition)
Definition c.h:943
uint32 result
int errcode(int sqlerrcode)
Definition elog.c:875
int errhint(const char *fmt,...) pg_attribute_printf(1
#define ERROR
Definition elog.h:40
#define ereport(elevel,...)
Definition elog.h:152
const char * str
#define PG_UTF8
Definition mbprint.c:43
int GetDatabaseEncoding(void)
Definition mbutils.c:1389
bool pg_verifymbstr(const char *mbstr, int len, bool noError)
Definition mbutils.c:1683
void pfree(void *pointer)
Definition mcxt.c:1619
char * pnstrdup(const char *in, Size len)
Definition mcxt.c:1921
static char * errmsg
static size_t mbstowcs_l(wchar_t *dest, const char *src, size_t n, locale_t loc)
static int fb(int x)
#define locale_t
Definition win32_port.h:429

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

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

◆ create_pg_locale_libc()

pg_locale_t create_pg_locale_libc ( Oid  collid,
MemoryContext  context 
)
extern

Definition at line 734 of file pg_locale_libc.c.

735{
736 const char *collate;
737 const char *ctype;
738 locale_t loc;
740
742 {
743 HeapTuple tp;
744 Datum datum;
745
747 if (!HeapTupleIsValid(tp))
748 elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
751 collate = TextDatumGetCString(datum);
754 ctype = TextDatumGetCString(datum);
755
756 ReleaseSysCache(tp);
757 }
758 else
759 {
760 HeapTuple tp;
761 Datum datum;
762
764 if (!HeapTupleIsValid(tp))
765 elog(ERROR, "cache lookup failed for collation %u", collid);
766
769 collate = TextDatumGetCString(datum);
772 ctype = TextDatumGetCString(datum);
773
774 ReleaseSysCache(tp);
775 }
776
777
778 loc = make_libc_collator(collate, ctype);
779
780 result = MemoryContextAllocZero(context, sizeof(struct pg_locale_struct));
781 result->deterministic = true;
782 result->collate_is_c = (strcmp(collate, "C") == 0) ||
783 (strcmp(collate, "POSIX") == 0);
784 result->ctype_is_c = (strcmp(ctype, "C") == 0) ||
785 (strcmp(ctype, "POSIX") == 0);
786 result->lt = loc;
787 if (!result->collate_is_c)
788 {
789#ifdef WIN32
792 else
793#endif
794 result->collate = &collate_methods_libc;
795 }
796 if (!result->ctype_is_c)
797 {
800 else if (pg_database_encoding_max_length() > 1)
802 else
804 }
805
806 return result;
807}
#define TextDatumGetCString(d)
Definition builtins.h:99
Oid collid
#define elog(elevel,...)
Definition elog.h:228
Oid MyDatabaseId
Definition globals.c:96
#define HeapTupleIsValid(tuple)
Definition htup.h:78
int pg_database_encoding_max_length(void)
Definition mbutils.c:1673
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition mcxt.c:1269
static const struct ctype_methods ctype_methods_libc_other_mb
static const struct ctype_methods ctype_methods_libc_utf8
static locale_t make_libc_collator(const char *collate, const char *ctype)
static const struct collate_methods collate_methods_libc
static const struct ctype_methods ctype_methods_libc_sb
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
uint64_t Datum
Definition postgres.h:70
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:265
Datum SysCacheGetAttrNotNull(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition syscache.c:626
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:221

References collate_methods_libc, collid, ctype_methods_libc_other_mb, ctype_methods_libc_sb, ctype_methods_libc_utf8, elog, ERROR, fb(), GetDatabaseEncoding(), HeapTupleIsValid, locale_t, make_libc_collator(), MemoryContextAllocZero(), MyDatabaseId, ObjectIdGetDatum(), pg_database_encoding_max_length(), PG_UTF8, ReleaseSysCache(), result, SearchSysCache1(), SysCacheGetAttrNotNull(), and TextDatumGetCString.

Referenced by create_pg_locale(), and init_database_collation().

◆ downcase_ident_libc_sb()

static size_t downcase_ident_libc_sb ( char dst,
size_t  dstsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
static

Definition at line 332 of file pg_locale_libc.c.

334{
335 locale_t loc = locale->lt;
336 int i;
337
338 for (i = 0; i < srclen && i < dstsize; i++)
339 {
340 unsigned char ch = (unsigned char) src[i];
341
342 if (ch >= 'A' && ch <= 'Z')
344 else if (IS_HIGHBIT_SET(ch) && isupper_l(ch, loc))
345 ch = tolower_l(ch, loc);
346 dst[i] = (char) ch;
347 }
348
349 if (i < dstsize)
350 dst[i] = '\0';
351
352 return srclen;
353}
#define IS_HIGHBIT_SET(ch)
Definition c.h:1244
int i
Definition isn.c:77
static unsigned char pg_ascii_tolower(unsigned char ch)
Definition port.h:189
#define tolower_l
Definition win32_port.h:430
#define isupper_l
Definition win32_port.h:440

References fb(), i, IS_HIGHBIT_SET, isupper_l, locale_t, pg_locale_struct::lt, pg_ascii_tolower(), and tolower_l.

◆ get_collation_actual_version_libc()

char * get_collation_actual_version_libc ( const char collcollate)
extern

Definition at line 973 of file pg_locale_libc.c.

974{
975 char *collversion = NULL;
976
977 if (pg_strcasecmp("C", collcollate) != 0 &&
978 pg_strncasecmp("C.", collcollate, 2) != 0 &&
979 pg_strcasecmp("POSIX", collcollate) != 0)
980 {
981#if defined(__GLIBC__)
982 /* Use the glibc version because we don't have anything better. */
984#elif defined(LC_VERSION_MASK)
985 locale_t loc;
986
987 /* Look up FreeBSD collation version. */
989 if (loc)
990 {
993 freelocale(loc);
994 }
995 else
997 (errmsg("could not load locale \"%s\"", collcollate)));
998#elif defined(WIN32)
999 /*
1000 * If we are targeting Windows Vista and above, we can ask for a name
1001 * given a collation name (earlier versions required a location code
1002 * that we don't have).
1003 */
1004 NLSVERSIONINFOEX version = {sizeof(NLSVERSIONINFOEX)};
1006
1010 {
1011 /*
1012 * GetNLSVersionEx() wants a language tag such as "en-US", not a
1013 * locale name like "English_United States.1252". Until those
1014 * values can be prevented from entering the system, or 100%
1015 * reliably converted to the more useful tag format, tolerate the
1016 * resulting error and report that we have no version data.
1017 */
1019 return NULL;
1020
1021 ereport(ERROR,
1022 (errmsg("could not get collation version for locale \"%s\": error code %lu",
1024 GetLastError())));
1025 }
1026 collversion = psprintf("%lu.%lu,%lu.%lu",
1027 (version.dwNLSVersion >> 8) & 0xFFFF,
1028 version.dwNLSVersion & 0xFF,
1029 (version.dwDefinedVersion >> 8) & 0xFFFF,
1030 version.dwDefinedVersion & 0xFF);
1031#endif
1032 }
1033
1034 return collversion;
1035}
char * pstrdup(const char *in)
Definition mcxt.c:1910
int pg_strcasecmp(const char *s1, const char *s2)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
char * psprintf(const char *fmt,...)
Definition psprintf.c:43

References ereport, errmsg, ERROR, fb(), locale_t, pg_strcasecmp(), pg_strncasecmp(), psprintf(), and pstrdup().

Referenced by get_collation_actual_version().

◆ make_libc_collator()

static locale_t make_libc_collator ( const char collate,
const char ctype 
)
static

Definition at line 818 of file pg_locale_libc.c.

819{
820 locale_t loc = 0;
821
822 if (strcmp(collate, ctype) == 0)
823 {
824 if (strcmp(ctype, "C") != 0 && strcmp(ctype, "POSIX") != 0)
825 {
826 /* Normal case where they're the same */
827 errno = 0;
828#ifndef WIN32
829 loc = newlocale(LC_COLLATE_MASK | LC_CTYPE_MASK, collate,
830 NULL);
831#else
832 loc = _create_locale(LC_ALL, collate);
833#endif
834 if (!loc)
836 }
837 }
838 else
839 {
840#ifndef WIN32
841 /* We need two newlocale() steps */
842 locale_t loc1 = 0;
843
844 if (strcmp(collate, "C") != 0 && strcmp(collate, "POSIX") != 0)
845 {
846 errno = 0;
847 loc1 = newlocale(LC_COLLATE_MASK, collate, NULL);
848 if (!loc1)
850 }
851
852 if (strcmp(ctype, "C") != 0 && strcmp(ctype, "POSIX") != 0)
853 {
854 errno = 0;
855 loc = newlocale(LC_CTYPE_MASK, ctype, loc1);
856 if (!loc)
857 {
858 if (loc1)
861 }
862 }
863 else
864 loc = loc1;
865#else
866
867 /*
868 * XXX The _create_locale() API doesn't appear to support this. Could
869 * perhaps be worked around by changing pg_locale_t to contain two
870 * separate fields.
871 */
874 errmsg("collations with different collate and ctype values are not supported on this platform")));
875#endif
876 }
877
878 return loc;
879}
void report_newlocale_failure(const char *localename)

References ereport, errcode(), errmsg, ERROR, fb(), locale_t, and report_newlocale_failure().

Referenced by create_pg_locale_libc().

◆ mbstowcs_l()

static size_t mbstowcs_l ( wchar_t dest,
const char src,
size_t  n,
locale_t  loc 
)
static

Definition at line 1160 of file pg_locale_libc.c.

1161{
1162#ifdef WIN32
1163 return _mbstowcs_l(dest, src, n, loc);
1164#else
1165 size_t result;
1167
1168 result = mbstowcs(dest, src, n);
1170 return result;
1171#endif
1172}

References fb(), locale_t, and result.

Referenced by char2wchar().

◆ report_newlocale_failure()

void report_newlocale_failure ( const char localename)

Definition at line 1126 of file pg_locale_libc.c.

1127{
1128 int save_errno;
1129
1130 /*
1131 * Windows doesn't provide any useful error indication from
1132 * _create_locale(), and BSD-derived platforms don't seem to feel they
1133 * need to set errno either (even though POSIX is pretty clear that
1134 * newlocale should do so). So, if errno hasn't been set, assume ENOENT
1135 * is what to report.
1136 */
1137 if (errno == 0)
1138 errno = ENOENT;
1139
1140 /*
1141 * ENOENT means "no such locale", not "no such file", so clarify that
1142 * errno with an errdetail message.
1143 */
1144 save_errno = errno; /* auxiliary funcs might change errno */
1145 ereport(ERROR,
1147 errmsg("could not create locale \"%s\": %m",
1148 localename),
1149 (save_errno == ENOENT ?
1150 errdetail("The operating system could not find any locale data for the locale name \"%s\".",
1151 localename) : 0)));
1152}
int errdetail(const char *fmt,...) pg_attribute_printf(1

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

Referenced by cache_locale_time(), and make_libc_collator().

◆ strcoll_libc()

static int strcoll_libc ( const char arg1,
const char arg2,
pg_locale_t  locale 
)
static

Definition at line 926 of file pg_locale_libc.c.

927{
928 return strcoll_l(arg1, arg2, locale->lt);
929}
#define strcoll_l
Definition win32_port.h:452

References fb(), pg_locale_struct::lt, and strcoll_l.

◆ strlower_libc_mb()

static size_t strlower_libc_mb ( char dest,
size_t  destsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
static

Definition at line 503 of file pg_locale_libc.c.

505{
506 locale_t loc = locale->lt;
507 size_t result_size;
508 wchar_t *workspace;
509 char *result;
510 size_t curr_char;
511 size_t max_size;
512
513 /* Overflow paranoia */
514 if ((srclen + 1) > (INT_MAX / sizeof(wchar_t)))
517 errmsg("out of memory")));
518
519 /* Output workspace cannot have more codes than input bytes */
520 workspace = palloc_array(wchar_t, srclen + 1);
521
522 char2wchar(workspace, srclen + 1, src, srclen, loc);
523
524 for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
525 workspace[curr_char] = towlower_l(workspace[curr_char], loc);
526
527 /*
528 * Make result large enough; case change might change number of bytes
529 */
531 result = palloc(max_size + 1);
532
533 result_size = wchar2char(result, workspace, max_size + 1, loc);
534
535 if (destsize >= result_size + 1)
536 {
537 memcpy(dest, result, result_size);
538 dest[result_size] = '\0';
539 }
540
541 pfree(workspace);
542 pfree(result);
543
544 return result_size;
545}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
#define palloc_array(type, count)
Definition fe_memutils.h:91
void * palloc(Size size)
Definition mcxt.c:1390
size_t wchar2char(char *to, const wchar_t *from, size_t tolen, locale_t loc)
static size_t char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen, locale_t loc)
#define towlower_l
Definition win32_port.h:432

References char2wchar(), ereport, errcode(), errmsg, ERROR, fb(), locale_t, pg_locale_struct::lt, memcpy(), palloc(), palloc_array, pfree(), pg_database_encoding_max_length(), result, towlower_l, and wchar2char().

◆ strlower_libc_sb()

static size_t strlower_libc_sb ( char dest,
size_t  destsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
static

Definition at line 467 of file pg_locale_libc.c.

469{
470 if (srclen + 1 <= destsize)
471 {
472 locale_t loc = locale->lt;
473 char *p;
474
475 memcpy(dest, src, srclen);
476 dest[srclen] = '\0';
477
478 /*
479 * Note: we assume that tolower_l() will not be so broken as to need
480 * an isupper_l() guard test. When using the default collation, we
481 * apply the traditional Postgres behavior that forces ASCII-style
482 * treatment of I/i, but in non-default collations you get exactly
483 * what the collation says.
484 */
485 for (p = dest; *p; p++)
486 {
487 if (locale->is_default)
488 {
489 if (*p >= 'A' && *p <= 'Z')
490 *p += 'a' - 'A';
491 else if (IS_HIGHBIT_SET(*p) && isupper_l(*p, loc))
492 *p = tolower_l((unsigned char) *p, loc);
493 }
494 else
495 *p = tolower_l((unsigned char) *p, loc);
496 }
497 }
498
499 return srclen;
500}

References fb(), pg_locale_struct::is_default, IS_HIGHBIT_SET, isupper_l, locale_t, pg_locale_struct::lt, memcpy(), and tolower_l.

◆ strncoll_libc()

static int strncoll_libc ( const char arg1,
size_t  len1,
const char arg2,
size_t  len2,
pg_locale_t  locale 
)
static

Definition at line 887 of file pg_locale_libc.c.

889{
890 char sbuf[TEXTBUFLEN];
891 char *buf = sbuf;
892 size_t bufsize1 = len1 + 1;
893 size_t bufsize2 = len2 + 1;
894 char *buf1;
895 char *buf2;
896 const char *arg1n;
897 const char *arg2n;
898 int result;
899
902
903 buf1 = buf;
904 buf2 = buf + bufsize1;
905
906 memcpy(buf1, arg1, len1);
907 buf1[len1] = '\0';
908 arg1n = buf1;
909
910 memcpy(buf2, arg2, len2);
911 buf2[len2] = '\0';
912 arg2n = buf2;
913
914 result = strcoll_l(arg1n, arg2n, locale->lt);
915
916 if (buf != sbuf)
917 pfree(buf);
918
919 return result;
920}
#define TEXTBUFLEN
static char buf[DEFAULT_XLOG_SEG_SIZE]

References buf, fb(), pg_locale_struct::lt, memcpy(), palloc(), pfree(), result, strcoll_l, and TEXTBUFLEN.

◆ strnxfrm_libc()

static size_t strnxfrm_libc ( char dest,
size_t  destsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
static

Definition at line 937 of file pg_locale_libc.c.

939{
940 char sbuf[TEXTBUFLEN];
941 char *buf = sbuf;
942 size_t bufsize = srclen + 1;
943 size_t result;
944
945 if (bufsize > TEXTBUFLEN)
946 buf = palloc(bufsize);
947
948 /* nul-terminate argument */
949 memcpy(buf, src, srclen);
950 buf[srclen] = '\0';
951
952 result = strxfrm_l(dest, buf, destsize, locale->lt);
953
954 if (buf != sbuf)
955 pfree(buf);
956
957 /* if dest is defined, it should be nul-terminated */
958 Assert(result >= destsize || dest[result] == '\0');
959
960 return result;
961}
#define bufsize
#define strxfrm_l
Definition win32_port.h:453

References Assert, buf, bufsize, fb(), pg_locale_struct::lt, memcpy(), palloc(), pfree(), result, strxfrm_l, and TEXTBUFLEN.

◆ strtitle_libc_mb()

static size_t strtitle_libc_mb ( char dest,
size_t  destsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
static

Definition at line 601 of file pg_locale_libc.c.

603{
604 locale_t loc = locale->lt;
605 int wasalnum = false;
606 size_t result_size;
607 wchar_t *workspace;
608 char *result;
609 size_t curr_char;
610 size_t max_size;
611
612 /* Overflow paranoia */
613 if ((srclen + 1) > (INT_MAX / sizeof(wchar_t)))
616 errmsg("out of memory")));
617
618 /* Output workspace cannot have more codes than input bytes */
619 workspace = palloc_array(wchar_t, srclen + 1);
620
621 char2wchar(workspace, srclen + 1, src, srclen, loc);
622
623 for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
624 {
625 if (wasalnum)
626 workspace[curr_char] = towlower_l(workspace[curr_char], loc);
627 else
628 workspace[curr_char] = towupper_l(workspace[curr_char], loc);
629 wasalnum = iswalnum_l(workspace[curr_char], loc);
630 }
631
632 /*
633 * Make result large enough; case change might change number of bytes
634 */
636 result = palloc(max_size + 1);
637
638 result_size = wchar2char(result, workspace, max_size + 1, loc);
639
640 if (destsize >= result_size + 1)
641 {
642 memcpy(dest, result, result_size);
643 dest[result_size] = '\0';
644 }
645
646 pfree(workspace);
647 pfree(result);
648
649 return result_size;
650}
#define iswalnum_l
Definition win32_port.h:439
#define towupper_l
Definition win32_port.h:433

References char2wchar(), ereport, errcode(), errmsg, ERROR, fb(), iswalnum_l, locale_t, pg_locale_struct::lt, memcpy(), palloc(), palloc_array, pfree(), pg_database_encoding_max_length(), result, towlower_l, towupper_l, and wchar2char().

◆ strtitle_libc_sb()

static size_t strtitle_libc_sb ( char dest,
size_t  destsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
static

Definition at line 548 of file pg_locale_libc.c.

550{
551 if (srclen + 1 <= destsize)
552 {
553 locale_t loc = locale->lt;
554 int wasalnum = false;
555 char *p;
556
557 memcpy(dest, src, srclen);
558 dest[srclen] = '\0';
559
560 /*
561 * Note: we assume that toupper_l()/tolower_l() will not be so broken
562 * as to need guard tests. When using the default collation, we apply
563 * the traditional Postgres behavior that forces ASCII-style treatment
564 * of I/i, but in non-default collations you get exactly what the
565 * collation says.
566 */
567 for (p = dest; *p; p++)
568 {
569 if (locale->is_default)
570 {
571 if (wasalnum)
572 {
573 if (*p >= 'A' && *p <= 'Z')
574 *p += 'a' - 'A';
575 else if (IS_HIGHBIT_SET(*p) && isupper_l(*p, loc))
576 *p = tolower_l((unsigned char) *p, loc);
577 }
578 else
579 {
580 if (*p >= 'a' && *p <= 'z')
581 *p -= 'a' - 'A';
582 else if (IS_HIGHBIT_SET(*p) && islower_l(*p, loc))
583 *p = toupper_l((unsigned char) *p, loc);
584 }
585 }
586 else
587 {
588 if (wasalnum)
589 *p = tolower_l((unsigned char) *p, loc);
590 else
591 *p = toupper_l((unsigned char) *p, loc);
592 }
593 wasalnum = isalnum_l((unsigned char) *p, loc);
594 }
595 }
596
597 return srclen;
598}
#define toupper_l
Definition win32_port.h:431
#define isalnum_l
Definition win32_port.h:438
#define islower_l
Definition win32_port.h:442

References fb(), pg_locale_struct::is_default, IS_HIGHBIT_SET, isalnum_l, islower_l, isupper_l, locale_t, pg_locale_struct::lt, memcpy(), tolower_l, and toupper_l.

◆ strupper_libc_mb()

static size_t strupper_libc_mb ( char dest,
size_t  destsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
static

Definition at line 689 of file pg_locale_libc.c.

691{
692 locale_t loc = locale->lt;
693 size_t result_size;
694 wchar_t *workspace;
695 char *result;
696 size_t curr_char;
697 size_t max_size;
698
699 /* Overflow paranoia */
700 if ((srclen + 1) > (INT_MAX / sizeof(wchar_t)))
703 errmsg("out of memory")));
704
705 /* Output workspace cannot have more codes than input bytes */
706 workspace = palloc_array(wchar_t, srclen + 1);
707
708 char2wchar(workspace, srclen + 1, src, srclen, loc);
709
710 for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
711 workspace[curr_char] = towupper_l(workspace[curr_char], loc);
712
713 /*
714 * Make result large enough; case change might change number of bytes
715 */
717 result = palloc(max_size + 1);
718
719 result_size = wchar2char(result, workspace, max_size + 1, loc);
720
721 if (destsize >= result_size + 1)
722 {
723 memcpy(dest, result, result_size);
724 dest[result_size] = '\0';
725 }
726
727 pfree(workspace);
728 pfree(result);
729
730 return result_size;
731}

References char2wchar(), ereport, errcode(), errmsg, ERROR, fb(), locale_t, pg_locale_struct::lt, memcpy(), palloc(), palloc_array, pfree(), pg_database_encoding_max_length(), result, towupper_l, and wchar2char().

◆ strupper_libc_sb()

static size_t strupper_libc_sb ( char dest,
size_t  destsize,
const char src,
size_t  srclen,
pg_locale_t  locale 
)
static

Definition at line 653 of file pg_locale_libc.c.

655{
656 if (srclen + 1 <= destsize)
657 {
658 locale_t loc = locale->lt;
659 char *p;
660
661 memcpy(dest, src, srclen);
662 dest[srclen] = '\0';
663
664 /*
665 * Note: we assume that toupper_l() will not be so broken as to need
666 * an islower_l() guard test. When using the default collation, we
667 * apply the traditional Postgres behavior that forces ASCII-style
668 * treatment of I/i, but in non-default collations you get exactly
669 * what the collation says.
670 */
671 for (p = dest; *p; p++)
672 {
673 if (locale->is_default)
674 {
675 if (*p >= 'a' && *p <= 'z')
676 *p -= 'a' - 'A';
677 else if (IS_HIGHBIT_SET(*p) && islower_l(*p, loc))
678 *p = toupper_l((unsigned char) *p, loc);
679 }
680 else
681 *p = toupper_l((unsigned char) *p, loc);
682 }
683 }
684
685 return srclen;
686}

References fb(), pg_locale_struct::is_default, IS_HIGHBIT_SET, islower_l, locale_t, pg_locale_struct::lt, memcpy(), and toupper_l.

◆ strxfrm_libc()

static size_t strxfrm_libc ( char dest,
size_t  destsize,
const char src,
pg_locale_t  locale 
)
static

Definition at line 967 of file pg_locale_libc.c.

968{
969 return strxfrm_l(dest, src, destsize, locale->lt);
970}

References fb(), pg_locale_struct::lt, and strxfrm_l.

◆ tolower_libc_mb()

static pg_wchar tolower_libc_mb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 314 of file pg_locale_libc.c.

315{
317
318 /* force C behavior for ASCII characters, per comments above */
319 if (locale->is_default && wc <= (pg_wchar) 127)
320 return pg_ascii_tolower((unsigned char) wc);
321 if (sizeof(wchar_t) >= 4 || wc <= (pg_wchar) 0xFFFF)
322 return towlower_l((wint_t) wc, locale->lt);
323 else
324 return wc;
325}
unsigned int pg_wchar
Definition mbprint.c:31

References Assert, fb(), GetDatabaseEncoding(), pg_locale_struct::is_default, pg_locale_struct::lt, pg_ascii_tolower(), PG_UTF8, and towlower_l.

◆ tolower_libc_sb()

static pg_wchar tolower_libc_sb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 300 of file pg_locale_libc.c.

301{
303
304 /* force C behavior for ASCII characters, per comments above */
305 if (locale->is_default && wc <= (pg_wchar) 127)
306 return pg_ascii_tolower((unsigned char) wc);
307 if (wc <= (pg_wchar) UCHAR_MAX)
308 return tolower_l((unsigned char) wc, locale->lt);
309 else
310 return wc;
311}

References Assert, fb(), GetDatabaseEncoding(), pg_locale_struct::is_default, pg_locale_struct::lt, pg_ascii_tolower(), PG_UTF8, and tolower_l.

◆ toupper_libc_mb()

static pg_wchar toupper_libc_mb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 286 of file pg_locale_libc.c.

287{
289
290 /* force C behavior for ASCII characters, per comments above */
291 if (locale->is_default && wc <= (pg_wchar) 127)
292 return pg_ascii_toupper((unsigned char) wc);
293 if (sizeof(wchar_t) >= 4 || wc <= (pg_wchar) 0xFFFF)
294 return towupper_l((wint_t) wc, locale->lt);
295 else
296 return wc;
297}
static unsigned char pg_ascii_toupper(unsigned char ch)
Definition port.h:178

References Assert, fb(), GetDatabaseEncoding(), pg_locale_struct::is_default, pg_locale_struct::lt, pg_ascii_toupper(), PG_UTF8, and towupper_l.

◆ toupper_libc_sb()

static pg_wchar toupper_libc_sb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 272 of file pg_locale_libc.c.

273{
275
276 /* force C behavior for ASCII characters, per comments above */
277 if (locale->is_default && wc <= (pg_wchar) 127)
278 return pg_ascii_toupper((unsigned char) wc);
279 if (wc <= (pg_wchar) UCHAR_MAX)
280 return toupper_l((unsigned char) wc, locale->lt);
281 else
282 return wc;
283}

References Assert, fb(), GetDatabaseEncoding(), pg_locale_struct::is_default, pg_locale_struct::lt, pg_ascii_toupper(), PG_UTF8, and toupper_l.

◆ wc_isalnum_libc_mb()

static bool wc_isalnum_libc_mb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 213 of file pg_locale_libc.c.

214{
215 return iswalnum_l((wint_t) wc, locale->lt);
216}

References fb(), iswalnum_l, and pg_locale_struct::lt.

◆ wc_isalnum_libc_sb()

static bool wc_isalnum_libc_sb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 142 of file pg_locale_libc.c.

143{
144 return isalnum_l((unsigned char) wc, locale->lt);
145}

References isalnum_l, and pg_locale_struct::lt.

◆ wc_isalpha_libc_mb()

static bool wc_isalpha_libc_mb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 207 of file pg_locale_libc.c.

208{
209 return iswalpha_l((wint_t) wc, locale->lt);
210}
#define iswalpha_l
Definition win32_port.h:437

References fb(), iswalpha_l, and pg_locale_struct::lt.

◆ wc_isalpha_libc_sb()

static bool wc_isalpha_libc_sb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 136 of file pg_locale_libc.c.

137{
138 return isalpha_l((unsigned char) wc, locale->lt);
139}
#define isalpha_l
Definition win32_port.h:436

References isalpha_l, and pg_locale_struct::lt.

◆ wc_iscased_libc_mb()

static bool wc_iscased_libc_mb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 265 of file pg_locale_libc.c.

266{
267 return iswupper_l((wint_t) wc, locale->lt) ||
268 iswlower_l((wint_t) wc, locale->lt);
269}
#define iswupper_l
Definition win32_port.h:441
#define iswlower_l
Definition win32_port.h:443

References fb(), iswlower_l, iswupper_l, and pg_locale_struct::lt.

◆ wc_iscased_libc_sb()

static bool wc_iscased_libc_sb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 194 of file pg_locale_libc.c.

195{
196 return isupper_l((unsigned char) wc, locale->lt) ||
197 islower_l((unsigned char) wc, locale->lt);
198}

References islower_l, isupper_l, and pg_locale_struct::lt.

◆ wc_isdigit_libc_mb()

static bool wc_isdigit_libc_mb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 201 of file pg_locale_libc.c.

202{
203 return iswdigit_l((wint_t) wc, locale->lt);
204}
#define iswdigit_l
Definition win32_port.h:435

References fb(), iswdigit_l, and pg_locale_struct::lt.

◆ wc_isdigit_libc_sb()

static bool wc_isdigit_libc_sb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 130 of file pg_locale_libc.c.

131{
132 return isdigit_l((unsigned char) wc, locale->lt);
133}
#define isdigit_l
Definition win32_port.h:434

References isdigit_l, and pg_locale_struct::lt.

◆ wc_isgraph_libc_mb()

static bool wc_isgraph_libc_mb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 231 of file pg_locale_libc.c.

232{
233 return iswgraph_l((wint_t) wc, locale->lt);
234}
#define iswgraph_l
Definition win32_port.h:445

References fb(), iswgraph_l, and pg_locale_struct::lt.

◆ wc_isgraph_libc_sb()

static bool wc_isgraph_libc_sb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 160 of file pg_locale_libc.c.

161{
162 return isgraph_l((unsigned char) wc, locale->lt);
163}
#define isgraph_l
Definition win32_port.h:444

References isgraph_l, and pg_locale_struct::lt.

◆ wc_islower_libc_mb()

static bool wc_islower_libc_mb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 225 of file pg_locale_libc.c.

226{
227 return iswlower_l((wint_t) wc, locale->lt);
228}

References fb(), iswlower_l, and pg_locale_struct::lt.

◆ wc_islower_libc_sb()

static bool wc_islower_libc_sb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 154 of file pg_locale_libc.c.

155{
156 return islower_l((unsigned char) wc, locale->lt);
157}

References islower_l, and pg_locale_struct::lt.

◆ wc_isprint_libc_mb()

static bool wc_isprint_libc_mb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 237 of file pg_locale_libc.c.

238{
239 return iswprint_l((wint_t) wc, locale->lt);
240}
#define iswprint_l
Definition win32_port.h:447

References fb(), iswprint_l, and pg_locale_struct::lt.

◆ wc_isprint_libc_sb()

static bool wc_isprint_libc_sb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 166 of file pg_locale_libc.c.

167{
168 return isprint_l((unsigned char) wc, locale->lt);
169}
#define isprint_l
Definition win32_port.h:446

References isprint_l, and pg_locale_struct::lt.

◆ wc_ispunct_libc_mb()

static bool wc_ispunct_libc_mb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 243 of file pg_locale_libc.c.

244{
245 return iswpunct_l((wint_t) wc, locale->lt);
246}
#define iswpunct_l
Definition win32_port.h:449

References fb(), iswpunct_l, and pg_locale_struct::lt.

◆ wc_ispunct_libc_sb()

static bool wc_ispunct_libc_sb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 172 of file pg_locale_libc.c.

173{
174 return ispunct_l((unsigned char) wc, locale->lt);
175}
#define ispunct_l
Definition win32_port.h:448

References ispunct_l, and pg_locale_struct::lt.

◆ wc_isspace_libc_mb()

static bool wc_isspace_libc_mb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 249 of file pg_locale_libc.c.

250{
251 return iswspace_l((wint_t) wc, locale->lt);
252}
#define iswspace_l
Definition win32_port.h:451

References fb(), iswspace_l, and pg_locale_struct::lt.

◆ wc_isspace_libc_sb()

static bool wc_isspace_libc_sb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 178 of file pg_locale_libc.c.

179{
180 return isspace_l((unsigned char) wc, locale->lt);
181}
#define isspace_l
Definition win32_port.h:450

References isspace_l, and pg_locale_struct::lt.

◆ wc_isupper_libc_mb()

static bool wc_isupper_libc_mb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 219 of file pg_locale_libc.c.

220{
221 return iswupper_l((wint_t) wc, locale->lt);
222}

References fb(), iswupper_l, and pg_locale_struct::lt.

◆ wc_isupper_libc_sb()

static bool wc_isupper_libc_sb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 148 of file pg_locale_libc.c.

149{
150 return isupper_l((unsigned char) wc, locale->lt);
151}

References isupper_l, and pg_locale_struct::lt.

◆ wc_isxdigit_libc_mb()

static bool wc_isxdigit_libc_mb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 255 of file pg_locale_libc.c.

256{
257#ifndef WIN32
258 return iswxdigit_l((wint_t) wc, locale->lt);
259#else
260 return _iswxdigit_l((wint_t) wc, locale->lt);
261#endif
262}

References fb(), and pg_locale_struct::lt.

◆ wc_isxdigit_libc_sb()

static bool wc_isxdigit_libc_sb ( pg_wchar  wc,
pg_locale_t  locale 
)
static

Definition at line 184 of file pg_locale_libc.c.

185{
186#ifndef WIN32
187 return isxdigit_l((unsigned char) wc, locale->lt);
188#else
189 return _isxdigit_l((unsigned char) wc, locale->lt);
190#endif
191}

References fb(), and pg_locale_struct::lt.

◆ wchar2char()

size_t wchar2char ( char to,
const wchar_t from,
size_t  tolen,
locale_t  loc 
)

Definition at line 1204 of file pg_locale_libc.c.

1205{
1206 size_t result;
1207
1208 if (tolen == 0)
1209 return 0;
1210
1211#ifdef WIN32
1212
1213 /*
1214 * On Windows, the "Unicode" locales assume UTF16 not UTF8 encoding, and
1215 * for some reason mbstowcs and wcstombs won't do this for us, so we use
1216 * MultiByteToWideChar().
1217 */
1219 {
1220 result = WideCharToMultiByte(CP_UTF8, 0, from, -1, to, tolen,
1221 NULL, NULL);
1222 /* A zero return is failure */
1223 if (result <= 0)
1224 result = -1;
1225 else
1226 {
1227 Assert(result <= tolen);
1228 /* Microsoft counts the zero terminator in the result */
1229 result--;
1230 }
1231 }
1232 else
1233#endif /* WIN32 */
1234 if (loc == (locale_t) 0)
1235 {
1236 /* Use wcstombs directly for the default locale */
1237 result = wcstombs(to, from, tolen);
1238 }
1239 else
1240 {
1241 /* Use wcstombs_l for nondefault locales */
1242 result = wcstombs_l(to, from, tolen, loc);
1243 }
1244
1245 return result;
1246}
static size_t wcstombs_l(char *dest, const wchar_t *src, size_t n, locale_t loc)

References Assert, fb(), GetDatabaseEncoding(), locale_t, PG_UTF8, result, and wcstombs_l().

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

◆ wcstombs_l()

static size_t wcstombs_l ( char dest,
const wchar_t src,
size_t  n,
locale_t  loc 
)
static

Definition at line 1176 of file pg_locale_libc.c.

1177{
1178#ifdef WIN32
1179 return _wcstombs_l(dest, src, n, loc);
1180#else
1181 size_t result;
1183
1184 result = wcstombs(dest, src, n);
1186 return result;
1187#endif
1188}

References fb(), locale_t, and result.

Referenced by wchar2char().

Variable Documentation

◆ collate_methods_libc

const struct collate_methods collate_methods_libc
static
Initial value:
= {
.strncoll = strncoll_libc,
.strcoll = strcoll_libc,
.strnxfrm = strnxfrm_libc,
.strxfrm = strxfrm_libc,
.strnxfrm_prefix = NULL,
.strxfrm_prefix = NULL,
.strxfrm_is_safe = false,
}
static int strncoll_libc(const char *arg1, size_t len1, const char *arg2, size_t len2, pg_locale_t locale)
static size_t strxfrm_libc(char *dest, size_t destsize, const char *src, pg_locale_t locale)
static size_t strnxfrm_libc(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
static int strcoll_libc(const char *arg1, const char *arg2, pg_locale_t locale)

Definition at line 427 of file pg_locale_libc.c.

427 {
428 .strncoll = strncoll_libc,
429 .strcoll = strcoll_libc,
430 .strnxfrm = strnxfrm_libc,
431 .strxfrm = strxfrm_libc,
432 .strnxfrm_prefix = NULL,
433 .strxfrm_prefix = NULL,
434
435 /*
436 * Unfortunately, it seems that strxfrm() for non-C collations is broken
437 * on many common platforms; testing of multiple versions of glibc reveals
438 * that, for many locales, strcoll() and strxfrm() do not return
439 * consistent results. While no other libc other than Cygwin has so far
440 * been shown to have a problem, we take the conservative course of action
441 * for right now and disable this categorically. (Users who are certain
442 * this isn't a problem on their system can define TRUST_STRXFRM.)
443 */
444#ifdef TRUST_STRXFRM
445 .strxfrm_is_safe = true,
446#else
447 .strxfrm_is_safe = false,
448#endif
449};

Referenced by create_pg_locale_libc().

◆ ctype_methods_libc_other_mb

const struct ctype_methods ctype_methods_libc_other_mb
static
Initial value:
= {
.strlower = strlower_libc_mb,
.strtitle = strtitle_libc_mb,
.strupper = strupper_libc_mb,
.strfold = strlower_libc_mb,
.downcase_ident = NULL,
.wc_isdigit = wc_isdigit_libc_sb,
.wc_isalpha = wc_isalpha_libc_sb,
.wc_isalnum = wc_isalnum_libc_sb,
.wc_isupper = wc_isupper_libc_sb,
.wc_islower = wc_islower_libc_sb,
.wc_isgraph = wc_isgraph_libc_sb,
.wc_isprint = wc_isprint_libc_sb,
.wc_ispunct = wc_ispunct_libc_sb,
.wc_isspace = wc_isspace_libc_sb,
.wc_isxdigit = wc_isxdigit_libc_sb,
.wc_iscased = wc_iscased_libc_sb,
.wc_toupper = toupper_libc_sb,
.wc_tolower = tolower_libc_sb,
}
static bool wc_ispunct_libc_sb(pg_wchar wc, pg_locale_t locale)
static bool wc_iscased_libc_sb(pg_wchar wc, pg_locale_t locale)
static bool wc_isdigit_libc_sb(pg_wchar wc, pg_locale_t locale)
static bool wc_isspace_libc_sb(pg_wchar wc, pg_locale_t locale)
static bool wc_islower_libc_sb(pg_wchar wc, pg_locale_t locale)
static pg_wchar toupper_libc_sb(pg_wchar wc, pg_locale_t locale)
static bool wc_isalnum_libc_sb(pg_wchar wc, pg_locale_t locale)
static size_t strtitle_libc_mb(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
static bool wc_isalpha_libc_sb(pg_wchar wc, pg_locale_t locale)
static bool wc_isprint_libc_sb(pg_wchar wc, pg_locale_t locale)
static bool wc_isupper_libc_sb(pg_wchar wc, pg_locale_t locale)
static bool wc_isgraph_libc_sb(pg_wchar wc, pg_locale_t locale)
static pg_wchar tolower_libc_sb(pg_wchar wc, pg_locale_t locale)
static bool wc_isxdigit_libc_sb(pg_wchar wc, pg_locale_t locale)
static size_t strupper_libc_mb(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
static size_t strlower_libc_mb(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)

Definition at line 381 of file pg_locale_libc.c.

381 {
382 .strlower = strlower_libc_mb,
383 .strtitle = strtitle_libc_mb,
384 .strupper = strupper_libc_mb,
385 /* in libc, casefolding is the same as lowercasing */
386 .strfold = strlower_libc_mb,
387 /* uses plain ASCII semantics for historical reasons */
388 .downcase_ident = NULL,
389 .wc_isdigit = wc_isdigit_libc_sb,
390 .wc_isalpha = wc_isalpha_libc_sb,
391 .wc_isalnum = wc_isalnum_libc_sb,
392 .wc_isupper = wc_isupper_libc_sb,
393 .wc_islower = wc_islower_libc_sb,
394 .wc_isgraph = wc_isgraph_libc_sb,
395 .wc_isprint = wc_isprint_libc_sb,
396 .wc_ispunct = wc_ispunct_libc_sb,
397 .wc_isspace = wc_isspace_libc_sb,
398 .wc_isxdigit = wc_isxdigit_libc_sb,
399 .wc_iscased = wc_iscased_libc_sb,
400 .wc_toupper = toupper_libc_sb,
401 .wc_tolower = tolower_libc_sb,
402};

Referenced by create_pg_locale_libc().

◆ ctype_methods_libc_sb

const struct ctype_methods ctype_methods_libc_sb
static
Initial value:
= {
.strlower = strlower_libc_sb,
.strtitle = strtitle_libc_sb,
.strupper = strupper_libc_sb,
.strfold = strlower_libc_sb,
.downcase_ident = downcase_ident_libc_sb,
.wc_isdigit = wc_isdigit_libc_sb,
.wc_isalpha = wc_isalpha_libc_sb,
.wc_isalnum = wc_isalnum_libc_sb,
.wc_isupper = wc_isupper_libc_sb,
.wc_islower = wc_islower_libc_sb,
.wc_isgraph = wc_isgraph_libc_sb,
.wc_isprint = wc_isprint_libc_sb,
.wc_ispunct = wc_ispunct_libc_sb,
.wc_isspace = wc_isspace_libc_sb,
.wc_isxdigit = wc_isxdigit_libc_sb,
.wc_iscased = wc_iscased_libc_sb,
.wc_toupper = toupper_libc_sb,
.wc_tolower = tolower_libc_sb,
}
static size_t strupper_libc_sb(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
static size_t strtitle_libc_sb(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)
static size_t downcase_ident_libc_sb(char *dst, size_t dstsize, const char *src, size_t srclen, pg_locale_t locale)
static size_t strlower_libc_sb(char *dest, size_t destsize, const char *src, size_t srclen, pg_locale_t locale)

Definition at line 355 of file pg_locale_libc.c.

355 {
356 .strlower = strlower_libc_sb,
357 .strtitle = strtitle_libc_sb,
358 .strupper = strupper_libc_sb,
359 /* in libc, casefolding is the same as lowercasing */
360 .strfold = strlower_libc_sb,
361 .downcase_ident = downcase_ident_libc_sb,
362 .wc_isdigit = wc_isdigit_libc_sb,
363 .wc_isalpha = wc_isalpha_libc_sb,
364 .wc_isalnum = wc_isalnum_libc_sb,
365 .wc_isupper = wc_isupper_libc_sb,
366 .wc_islower = wc_islower_libc_sb,
367 .wc_isgraph = wc_isgraph_libc_sb,
368 .wc_isprint = wc_isprint_libc_sb,
369 .wc_ispunct = wc_ispunct_libc_sb,
370 .wc_isspace = wc_isspace_libc_sb,
371 .wc_isxdigit = wc_isxdigit_libc_sb,
372 .wc_iscased = wc_iscased_libc_sb,
373 .wc_toupper = toupper_libc_sb,
374 .wc_tolower = tolower_libc_sb,
375};

Referenced by create_pg_locale_libc().

◆ ctype_methods_libc_utf8

const struct ctype_methods ctype_methods_libc_utf8
static
Initial value:
= {
.strlower = strlower_libc_mb,
.strtitle = strtitle_libc_mb,
.strupper = strupper_libc_mb,
.strfold = strlower_libc_mb,
.downcase_ident = NULL,
.wc_isdigit = wc_isdigit_libc_mb,
.wc_isalpha = wc_isalpha_libc_mb,
.wc_isalnum = wc_isalnum_libc_mb,
.wc_isupper = wc_isupper_libc_mb,
.wc_islower = wc_islower_libc_mb,
.wc_isgraph = wc_isgraph_libc_mb,
.wc_isprint = wc_isprint_libc_mb,
.wc_ispunct = wc_ispunct_libc_mb,
.wc_isspace = wc_isspace_libc_mb,
.wc_isxdigit = wc_isxdigit_libc_mb,
.wc_iscased = wc_iscased_libc_mb,
.wc_toupper = toupper_libc_mb,
.wc_tolower = tolower_libc_mb,
}
static bool wc_isalpha_libc_mb(pg_wchar wc, pg_locale_t locale)
static pg_wchar toupper_libc_mb(pg_wchar wc, pg_locale_t locale)
static bool wc_isprint_libc_mb(pg_wchar wc, pg_locale_t locale)
static bool wc_isupper_libc_mb(pg_wchar wc, pg_locale_t locale)
static bool wc_isgraph_libc_mb(pg_wchar wc, pg_locale_t locale)
static bool wc_isalnum_libc_mb(pg_wchar wc, pg_locale_t locale)
static bool wc_iscased_libc_mb(pg_wchar wc, pg_locale_t locale)
static bool wc_ispunct_libc_mb(pg_wchar wc, pg_locale_t locale)
static bool wc_islower_libc_mb(pg_wchar wc, pg_locale_t locale)
static pg_wchar tolower_libc_mb(pg_wchar wc, pg_locale_t locale)
static bool wc_isdigit_libc_mb(pg_wchar wc, pg_locale_t locale)
static bool wc_isspace_libc_mb(pg_wchar wc, pg_locale_t locale)
static bool wc_isxdigit_libc_mb(pg_wchar wc, pg_locale_t locale)

Definition at line 404 of file pg_locale_libc.c.

404 {
405 .strlower = strlower_libc_mb,
406 .strtitle = strtitle_libc_mb,
407 .strupper = strupper_libc_mb,
408 /* in libc, casefolding is the same as lowercasing */
409 .strfold = strlower_libc_mb,
410 /* uses plain ASCII semantics for historical reasons */
411 .downcase_ident = NULL,
412 .wc_isdigit = wc_isdigit_libc_mb,
413 .wc_isalpha = wc_isalpha_libc_mb,
414 .wc_isalnum = wc_isalnum_libc_mb,
415 .wc_isupper = wc_isupper_libc_mb,
416 .wc_islower = wc_islower_libc_mb,
417 .wc_isgraph = wc_isgraph_libc_mb,
418 .wc_isprint = wc_isprint_libc_mb,
419 .wc_ispunct = wc_ispunct_libc_mb,
420 .wc_isspace = wc_isspace_libc_mb,
421 .wc_isxdigit = wc_isxdigit_libc_mb,
422 .wc_iscased = wc_iscased_libc_mb,
423 .wc_toupper = toupper_libc_mb,
424 .wc_tolower = tolower_libc_mb,
425};

Referenced by create_pg_locale_libc().