Re: Thread-safe nl_langinfo() and localeconv()
Heikki Linnakangas <hlinnaka@iki.fi>
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2024-08-15T11:11:07Z
Lists: pgsql-hackers
On 15/08/2024 11:03, Thomas Munro wrote: > Here's a new patch to add to this pile, this time for check_locale(). > I also improved the error handling and comments in the other patches. There's a similar function in initdb, check_locale_name. I wonder if that could reuse the same code. I wonder if it would be more clear to split this into three functions: /* * Get the name of the locale in "native environment", * like setlocale(category, NULL) does */ char *get_native_locale(int category); /* * Return true if 'locale' is valid locale name for 'category */ bool check_locale(int category, const char *locale); /* * Return a canonical name of given locale */ char *canonicalize_locale(int category, const char *locale); > result = malloc(strlen(canonical) + 1); > if (!result) > goto exit; > strcpy(result, canonical); Could use "result = strdup(canonical)" here. Or even better, could we use palloc()/pstrdup() here, and save the caller the trouble to copy it? -- Heikki Linnakangas Neon (https://neon.tech)
Commits
-
Fix "‘static’ is not at beginning of declaration" warning
- 116e851db5b3 18.0 landed
-
Use thread-safe strftime_l() instead of strftime().
- 890fc826c91f 18.0 landed
-
Provide thread-safe pg_localeconv_r().
- b98be8a2a2a6 18.0 landed
-
Harmonize MinGW CODESET lookup with MSVC.
- bf3401fe813a 18.0 landed
-
Include <xlocale.h> for macOS, take II.
- 2488058dc356 18.0 landed
-
Use thread-safe nl_langinfo_l(), not nl_langinfo().
- 35eeea623022 18.0 landed
-
All POSIX systems have langinfo.h and CODESET.
- 14c648ff0094 18.0 landed