setlocale

Lists: pgsql-hackerspgsql-hackers-win32
From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Postgresql Hackers <pgsql-hackers(at)postgresql(dot)org>, pgsql-hackers-win32 <pgsql-hackers-win32(at)postgresql(dot)org>
Subject: setlocale
Date: 2003-10-08 16:56:24
Message-ID: 3F8441B8.4030605@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-hackers-win32

The MS runtime docs on setlocale() contaiun the following statement:

At program startup, the equivalent of the following statement is executed:

setlocale( LC_ALL, "C" );

Does this have any effect on us? Does it mean, as it appears to, that the locale will not be inherited from the parent?

If so, I guess it could be got around by passing LC_COLLATE and LC_CTYPE arguments to postgres when running the bootstrap code.

Of course, if I'm right, initdb would not pick up the locale from its caller, which might be ugly if that was what you expected.

(I'm new to this locale stuff - I know we have some experts out there).

Another question - will we want to internationalize initdb (I'm new to that, too :-) )

cheers

andrew


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Postgresql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: setlocale
Date: 2003-10-08 17:38:30
Message-ID: Pine.LNX.4.44.0310081929570.26413-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-hackers-win32

Andrew Dunstan writes:

> At program startup, the equivalent of the following statement is executed:
> setlocale( LC_ALL, "C" );
> Does this have any effect on us?

No, that is just a peculiar way to express that by default nothing
happens.

> Does it mean, as it appears to, that the locale will not be inherited
> from the parent?

A process never inherits the locale from the parent. It only inherits
environment variables, among which may be LC_ALL, etc. To activate any
kind of locale in a program you need to call

setlocale(LC_xxx, "something");

where "something" may be the name of the actual locale you want, or -- as
a special case -- it may be "", in which case it takes the value of the
respective environment variable LC_xxx.

There is an appearance of inheritance in shell scripts, but only because
the shell takes care of some of these things automatically.

> If so, I guess it could be got around by passing LC_COLLATE and LC_CTYPE
> arguments to postgres when running the bootstrap code.

The easiest solution would be to stick LC_COLLATE and LC_CTYPE into the
environment of the postgres process when you call it the first time (in
bootstrap mode). If no --lc-* options were given, you don't need to do
anything, because "postgres" will just take what's in the environment. If
--lc-* options where given, you could use putenv().

> Another question - will we want to internationalize initdb

Yes, but that should really wait until we have a working C version first.

--
Peter Eisentraut peter_e(at)gmx(dot)net