Thread

  1. Re: Remaining dependency on setlocale()

    Jeff Davis <pgsql@j-davis.com> — 2025-10-30T20:53:43Z

    On Thu, 2025-10-30 at 21:41 +0100, Daniel Verite wrote:
    > What about code in extensions? AFAIU a user can control the 
    > locale in effect by setting the LC_CTYPE argument of
    > CREATE DATABASE, which ends up in the environment
    > of backends serving that database.
    > If it's forced to "C", how can an extension use locale-aware
    > libc functions?
    
    Extensions often need to be updated for a new major version.
    
    The extension should call pg_database_locale(), and pass that to a
    function exposed in pg_locale.h. A recent commit exposed pg_iswalpha(),
    etc., so there's a reasonable set of functions that should be suitable
    for most purposes.
    
    If it's not available in pg_locale.h, or the extension really needs to
    use a different LC_CTYPE for some reason, it can use an _l() variant of
    the function.
    
    Regards,
    	Jeff Davis