31 #define TEXTBUFLEN 1024
36 const char *arg2, ssize_t len2,
39 const char *src, ssize_t srclen,
46 static int strncoll_libc_win32_utf8(
const char *arg1, ssize_t len1,
47 const char *arg2, ssize_t len2,
59 if (
collid == DEFAULT_COLLATION_OID)
68 Anum_pg_database_datcollate);
71 Anum_pg_database_datctype);
86 Anum_pg_collation_collcollate);
89 Anum_pg_collation_collctype);
99 result->
provider = COLLPROVIDER_LIBC;
102 (strcmp(collate,
"POSIX") == 0);
103 result->
ctype_is_c = (strcmp(ctype,
"C") == 0) ||
104 (strcmp(ctype,
"POSIX") == 0);
123 if (strcmp(collate, ctype) == 0)
125 if (strcmp(ctype,
"C") != 0 && strcmp(ctype,
"POSIX") != 0)
130 loc = newlocale(LC_COLLATE_MASK | LC_CTYPE_MASK, collate,
133 loc = _create_locale(LC_ALL, collate);
145 if (strcmp(collate,
"C") != 0 && strcmp(collate,
"POSIX") != 0)
148 loc1 = newlocale(LC_COLLATE_MASK, collate, NULL);
153 if (strcmp(ctype,
"C") != 0 && strcmp(ctype,
"POSIX") != 0)
156 loc = newlocale(LC_CTYPE_MASK, ctype, loc1);
174 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
175 errmsg(
"collations with different collate and ctype values are not supported on this platform")));
190 strncoll_libc(
const char *arg1, ssize_t len1,
const char *arg2, ssize_t len2,
195 size_t bufsize1 = (len1 == -1) ? 0 : len1 + 1;
196 size_t bufsize2 = (len2 == -1) ? 0 : len2 + 1;
206 return strncoll_libc_win32_utf8(arg1, len1, arg2, len2,
locale);
221 memcpy(buf1, arg1, len1);
232 char *buf2 =
buf + bufsize1;
234 memcpy(buf2, arg2, len2);
272 memcpy(
buf, src, srclen);
281 Assert(result >= destsize ||
dest[result] ==
'\0');
296 strncoll_libc_win32_utf8(
const char *arg1, ssize_t len1,
const char *arg2,
316 a1len = len1 * 2 + 2;
317 a2len = len2 * 2 + 2;
330 r = MultiByteToWideChar(CP_UTF8, 0, arg1, len1,
331 (LPWSTR) a1p, a1len / 2);
334 (
errmsg(
"could not convert string to UTF-16: error code %lu",
337 ((LPWSTR) a1p)[r] = 0;
343 r = MultiByteToWideChar(CP_UTF8, 0, arg2, len2,
344 (LPWSTR) a2p, a2len / 2);
347 (
errmsg(
"could not convert string to UTF-16: error code %lu",
350 ((LPWSTR) a2p)[r] = 0;
354 if (result == 2147483647)
356 (
errmsg(
"could not compare Unicode strings: %m")));
387 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
388 errmsg(
"could not create locale \"%s\": %m",
390 (save_errno == ENOENT ?
391 errdetail(
"The operating system could not find any locale data for the locale name \"%s\".",
399 #ifndef HAVE_MBSTOWCS_L
404 return _mbstowcs_l(
dest, src, n, loc);
407 locale_t save_locale = uselocale(loc);
409 result = mbstowcs(
dest, src, n);
410 uselocale(save_locale);
415 #ifndef HAVE_WCSTOMBS_L
420 return _wcstombs_l(
dest, src, n, loc);
423 locale_t save_locale = uselocale(loc);
425 result = wcstombs(
dest, src, n);
426 uselocale(save_locale);
461 result = WideCharToMultiByte(CP_UTF8, 0, from, -1, to, tolen,
478 result = wcstombs(to, from, tolen);
499 char2wchar(
wchar_t *to,
size_t tolen,
const char *from,
size_t fromlen,
516 result = MultiByteToWideChar(CP_UTF8, 0, from, fromlen, to, tolen - 1);
538 result = mbstowcs(to,
str, tolen);
562 (
errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
563 errmsg(
"invalid multibyte character for locale"),
564 errhint(
"The server's LC_CTYPE locale is probably incompatible with the database encoding.")));
#define TextDatumGetCString(d)
#define Assert(condition)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define HeapTupleIsValid(tuple)
int GetDatabaseEncoding(void)
bool pg_verifymbstr(const char *mbstr, int len, bool noError)
char * pnstrdup(const char *in, Size len)
void pfree(void *pointer)
void * MemoryContextAllocZero(MemoryContext context, Size size)
size_t wchar2char(char *to, const wchar_t *from, size_t tolen, pg_locale_t locale)
pg_locale_t create_pg_locale_libc(Oid collid, MemoryContext context)
static locale_t make_libc_collator(const char *collate, const char *ctype)
static size_t wcstombs_l(char *dest, const wchar_t *src, size_t n, locale_t loc)
int strncoll_libc(const char *arg1, ssize_t len1, const char *arg2, ssize_t len2, pg_locale_t locale)
static void report_newlocale_failure(const char *localename)
size_t strnxfrm_libc(char *dest, size_t destsize, const char *src, ssize_t srclen, pg_locale_t locale)
size_t char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen, pg_locale_t locale)
static size_t mbstowcs_l(wchar_t *dest, const char *src, size_t n, locale_t loc)
static Datum ObjectIdGetDatum(Oid X)
union pg_locale_struct::@156 info
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)