Skip to content

Commit fae7ce8

Browse files
committed
Make locale_messages_assign() really work on Windows; the prior hack
only covered the case of assigning "", and failed to recognize that actually setlocale(LC_MESSAGES,...) does not work at all on this platform. Magnus Hagander, some code prettification by Tom Lane.
1 parent cc6a90e commit fae7ce8

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

src/backend/utils/adt/pg_locale.c

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Portions Copyright (c) 2002-2004, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/backend/utils/adt/pg_locale.c,v 1.28 2004/08/29 05:06:49 momjian Exp $
7+
* $PostgreSQL: pgsql/src/backend/utils/adt/pg_locale.c,v 1.29 2004/10/17 20:02:26 tgl Exp $
88
*
99
*-----------------------------------------------------------------------
1010
*/
@@ -123,6 +123,7 @@ locale_time_assign(const char *value, bool doit, GucSource source)
123123
const char *
124124
locale_messages_assign(const char *value, bool doit, GucSource source)
125125
{
126+
#ifndef WIN32
126127
/*
127128
* LC_MESSAGES category does not exist everywhere, but accept it
128129
* anyway
@@ -131,25 +132,40 @@ locale_messages_assign(const char *value, bool doit, GucSource source)
131132
if (doit)
132133
{
133134
if (!setlocale(LC_MESSAGES, value))
134-
{
135-
#ifdef WIN32
136-
137-
/*
138-
* Win32 returns NULL when you set LC_MESSAGES to "". So
139-
* don't complain unless we're trying to set it to something
140-
* else.
141-
*/
142-
if (value[0])
143-
return NULL;
144-
#else
145135
return NULL;
146-
#endif
147-
}
148136
}
149137
else
150138
value = locale_xxx_assign(LC_MESSAGES, value, false, source);
151139
#endif /* LC_MESSAGES */
152140
return value;
141+
142+
#else /* WIN32 */
143+
144+
/*
145+
* Win32 does not have working setlocale() for LC_MESSAGES. We can only
146+
* use environment variables to change it (per gettext FAQ). This
147+
* means we can't actually check the supplied value, so always assume
148+
* it's good. Also, ignore attempts to set to "", which really means
149+
* "keep using the old value". (Actually it means "use the environment
150+
* value", but we are too lazy to try to implement that exactly.)
151+
*/
152+
if (doit && value[0])
153+
{
154+
/*
155+
* We need to modify both the process environment and the cached
156+
* version in msvcrt
157+
*/
158+
static char env[128];
159+
160+
if (!SetEnvironmentVariable("LC_MESSAGES", value))
161+
return NULL;
162+
163+
snprintf(env, sizeof(env)-1, "LC_MESSAGES=%s", value);
164+
if (_putenv(env))
165+
return NULL;
166+
}
167+
return value;
168+
#endif /* WIN32 */
153169
}
154170

155171

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy