From: Jeff Davis Date: Fri, 26 May 2023 18:26:11 +0000 (-0700) Subject: ICU: use uloc_getDefault() for initdb. X-Git-Tag: REL_16_BETA2~100 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=ec1264f01e374c48707cc7dc18928b4ace0530fb;p=postgresql.git ICU: use uloc_getDefault() for initdb. Simpler, and better preserves the locale name as read from the environment. Author: Daniel Verite Discussion: https://postgr.es/m/a6204a46-c077-451b-8f9d-8965d95bb57c@manitou-mail.org --- diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 31156e863ba..09a5c98cc04 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -2354,42 +2354,13 @@ icu_validate_locale(const char *loc_str) } /* - * Determine default ICU locale by opening the default collator and reading - * its locale. - * - * NB: The default collator (opened using NULL) is different from the collator - * for the root locale (opened with "", "und", or "root"). The former depends - * on the environment (useful at initdb time) and the latter does not. + * Determine the default ICU locale */ static char * default_icu_locale(void) { #ifdef USE_ICU - UCollator *collator; - UErrorCode status; - const char *valid_locale; - char *default_locale; - - status = U_ZERO_ERROR; - collator = ucol_open(NULL, &status); - if (U_FAILURE(status)) - pg_fatal("could not open collator for default locale: %s", - u_errorName(status)); - - status = U_ZERO_ERROR; - valid_locale = ucol_getLocaleByType(collator, ULOC_VALID_LOCALE, - &status); - if (U_FAILURE(status)) - { - ucol_close(collator); - pg_fatal("could not determine default ICU locale"); - } - - default_locale = pg_strdup(valid_locale); - - ucol_close(collator); - - return default_locale; + return pg_strdup(uloc_getDefault()); #else pg_fatal("ICU is not supported in this build"); #endif