Re: Thread-safe nl_langinfo() and localeconv()

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Thread-safe nl_langinfo() and localeconv()
Date: 2024-08-15 11:11:07
Message-ID: 0b413ed8-5766-43b5-aba8-d5b1196c45da@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Etsuro Fujita 2024-08-15 11:45:44 Re: Skip adding row-marks for non target tables when result relation is foreign table.
Previous Message Aleksander Alekseev 2024-08-15 10:58:03 Re: [PATCH] Add get_bytes() and set_bytes() functions