25 #define TEXTBUFLEN 1024
30 const char *arg2, ssize_t len2,
33 const char *src, ssize_t srclen,
39 static int strncoll_libc_win32_utf8(
const char *arg1, ssize_t len1,
40 const char *arg2, ssize_t len2,
57 if (strcmp(collate, ctype) == 0)
59 if (strcmp(ctype,
"C") != 0 && strcmp(ctype,
"POSIX") != 0)
64 loc = newlocale(LC_COLLATE_MASK | LC_CTYPE_MASK, collate,
67 loc = _create_locale(LC_ALL, collate);
79 if (strcmp(collate,
"C") != 0 && strcmp(collate,
"POSIX") != 0)
82 loc1 = newlocale(LC_COLLATE_MASK, collate, NULL);
87 if (strcmp(ctype,
"C") != 0 && strcmp(ctype,
"POSIX") != 0)
90 loc = newlocale(LC_CTYPE_MASK, ctype, loc1);
108 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
109 errmsg(
"collations with different collate and ctype values are not supported on this platform")));
124 strncoll_libc(
const char *arg1, ssize_t len1,
const char *arg2, ssize_t len2,
129 size_t bufsize1 = (len1 == -1) ? 0 : len1 + 1;
130 size_t bufsize2 = (len2 == -1) ? 0 : len2 + 1;
140 return strncoll_libc_win32_utf8(arg1, len1, arg2, len2,
locale);
155 memcpy(buf1, arg1, len1);
166 char *buf2 =
buf + bufsize1;
168 memcpy(buf2, arg2, len2);
206 memcpy(
buf, src, srclen);
215 Assert(result >= destsize ||
dest[result] ==
'\0');
230 strncoll_libc_win32_utf8(
const char *arg1, ssize_t len1,
const char *arg2,
250 a1len = len1 * 2 + 2;
251 a2len = len2 * 2 + 2;
264 r = MultiByteToWideChar(CP_UTF8, 0, arg1, len1,
265 (LPWSTR) a1p, a1len / 2);
268 (
errmsg(
"could not convert string to UTF-16: error code %lu",
271 ((LPWSTR) a1p)[r] = 0;
277 r = MultiByteToWideChar(CP_UTF8, 0, arg2, len2,
278 (LPWSTR) a2p, a2len / 2);
281 (
errmsg(
"could not convert string to UTF-16: error code %lu",
284 ((LPWSTR) a2p)[r] = 0;
288 if (result == 2147483647)
290 (
errmsg(
"could not compare Unicode strings: %m")));
321 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
322 errmsg(
"could not create locale \"%s\": %m",
324 (save_errno == ENOENT ?
325 errdetail(
"The operating system could not find any locale data for the locale name \"%s\".",
333 #ifndef HAVE_MBSTOWCS_L
338 return _mbstowcs_l(
dest, src, n, loc);
341 locale_t save_locale = uselocale(loc);
343 result = mbstowcs(
dest, src, n);
344 uselocale(save_locale);
349 #ifndef HAVE_WCSTOMBS_L
354 return _wcstombs_l(
dest, src, n, loc);
357 locale_t save_locale = uselocale(loc);
359 result = wcstombs(
dest, src, n);
360 uselocale(save_locale);
395 result = WideCharToMultiByte(CP_UTF8, 0, from, -1, to, tolen,
412 result = wcstombs(to, from, tolen);
433 char2wchar(
wchar_t *to,
size_t tolen,
const char *from,
size_t fromlen,
450 result = MultiByteToWideChar(CP_UTF8, 0, from, fromlen, to, tolen - 1);
472 result = mbstowcs(to,
str, tolen);
496 (
errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
497 errmsg(
"invalid multibyte character for locale"),
498 errhint(
"The server's LC_CTYPE locale is probably incompatible with the database encoding.")));
#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,...)
int GetDatabaseEncoding(void)
bool pg_verifymbstr(const char *mbstr, int len, bool noError)
char * pnstrdup(const char *in, Size len)
void pfree(void *pointer)
size_t wchar2char(char *to, const wchar_t *from, size_t tolen, pg_locale_t locale)
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)