aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/pg_locale.c
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2021-02-22 23:03:27 +1300
committerThomas Munro <tmunro@postgresql.org>2021-02-22 23:32:16 +1300
commitbeb4480c853a60ec43bd3f1a71252890dd234f10 (patch)
treeea3c7ddcb1b9a5a5e44c6f867a9846ad79fd19c2 /src/backend/utils/adt/pg_locale.c
parent9cf184cc0599b6e65e7e5ecd9d91cd42e278bcd8 (diff)
downloadpostgresql-beb4480c853a60ec43bd3f1a71252890dd234f10.tar.gz
postgresql-beb4480c853a60ec43bd3f1a71252890dd234f10.zip
Refactor get_collation_current_version().
The code paths for three different OSes finished up with three different ways of excluding C[.xxx] and POSIX from consideration. Merge them. Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/20210117215940.GE8560%40telsasoft.com
Diffstat (limited to 'src/backend/utils/adt/pg_locale.c')
-rw-r--r--src/backend/utils/adt/pg_locale.c34
1 files changed, 4 insertions, 30 deletions
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index 2e4c6e9a263..df1f36132d3 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -1636,37 +1636,17 @@ get_collation_current_version(char collprovider, const char *collcollate)
}
else
#endif
- if (collprovider == COLLPROVIDER_LIBC)
+ if (collprovider == COLLPROVIDER_LIBC &&
+ pg_strcasecmp("C", collcollate) != 0 &&
+ pg_strncasecmp("C.", collcollate, 2) != 0 &&
+ pg_strcasecmp("POSIX", collcollate) != 0)
{
#if defined(__GLIBC__)
- char *copy = pstrdup(collcollate);
- char *copy_suffix = strstr(copy, ".");
- bool need_version = true;
-
- /*
- * Check for names like C.UTF-8 by chopping off the encoding suffix on
- * our temporary copy, so we can skip the version.
- */
- if (copy_suffix)
- *copy_suffix = '\0';
- if (pg_strcasecmp("c", copy) == 0 ||
- pg_strcasecmp("posix", copy) == 0)
- need_version = false;
- pfree(copy);
- if (!need_version)
- return NULL;
-
/* Use the glibc version because we don't have anything better. */
collversion = pstrdup(gnu_get_libc_version());
#elif defined(LC_VERSION_MASK)
locale_t loc;
- /* C[.encoding] and POSIX never change. */
- if (strcmp("C", collcollate) == 0 ||
- strncmp("C.", collcollate, 2) == 0 ||
- strcmp("POSIX", collcollate) == 0)
- return NULL;
-
/* Look up FreeBSD collation version. */
loc = newlocale(LC_COLLATE, collcollate, NULL);
if (loc)
@@ -1687,12 +1667,6 @@ get_collation_current_version(char collprovider, const char *collcollate)
NLSVERSIONINFOEX version = {sizeof(NLSVERSIONINFOEX)};
WCHAR wide_collcollate[LOCALE_NAME_MAX_LENGTH];
- /* These would be invalid arguments, but have no version. */
- if (pg_strcasecmp("c", collcollate) == 0 ||
- pg_strcasecmp("posix", collcollate) == 0)
- return NULL;
-
- /* For all other names, ask the OS. */
MultiByteToWideChar(CP_ACP, 0, collcollate, -1, wide_collcollate,
LOCALE_NAME_MAX_LENGTH);
if (!GetNLSVersionEx(COMPARE_STRING, wide_collcollate, &version))