Skip to content

Commit ec1264f

Browse files
committed
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
1 parent 7a844c7 commit ec1264f

File tree

1 file changed

+2
-31
lines changed

1 file changed

+2
-31
lines changed

src/bin/initdb/initdb.c

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,42 +2354,13 @@ icu_validate_locale(const char *loc_str)
23542354
}
23552355

23562356
/*
2357-
* Determine default ICU locale by opening the default collator and reading
2358-
* its locale.
2359-
*
2360-
* NB: The default collator (opened using NULL) is different from the collator
2361-
* for the root locale (opened with "", "und", or "root"). The former depends
2362-
* on the environment (useful at initdb time) and the latter does not.
2357+
* Determine the default ICU locale
23632358
*/
23642359
static char *
23652360
default_icu_locale(void)
23662361
{
23672362
#ifdef USE_ICU
2368-
UCollator *collator;
2369-
UErrorCode status;
2370-
const char *valid_locale;
2371-
char *default_locale;
2372-
2373-
status = U_ZERO_ERROR;
2374-
collator = ucol_open(NULL, &status);
2375-
if (U_FAILURE(status))
2376-
pg_fatal("could not open collator for default locale: %s",
2377-
u_errorName(status));
2378-
2379-
status = U_ZERO_ERROR;
2380-
valid_locale = ucol_getLocaleByType(collator, ULOC_VALID_LOCALE,
2381-
&status);
2382-
if (U_FAILURE(status))
2383-
{
2384-
ucol_close(collator);
2385-
pg_fatal("could not determine default ICU locale");
2386-
}
2387-
2388-
default_locale = pg_strdup(valid_locale);
2389-
2390-
ucol_close(collator);
2391-
2392-
return default_locale;
2363+
return pg_strdup(uloc_getDefault());
23932364
#else
23942365
pg_fatal("ICU is not supported in this build");
23952366
#endif

0 commit comments

Comments
 (0)