Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfae7ce8

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

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
constchar*
124124
locale_messages_assign(constchar*value,booldoit,GucSourcesource)
125125
{
126+
#ifndefWIN32
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-
#ifdefWIN32
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-
returnNULL;
144-
#else
145135
returnNULL;
146-
#endif
147-
}
148136
}
149137
else
150138
value=locale_xxx_assign(LC_MESSAGES,value, false,source);
151139
#endif/* LC_MESSAGES */
152140
returnvalue;
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+
staticcharenv[128];
159+
160+
if (!SetEnvironmentVariable("LC_MESSAGES",value))
161+
returnNULL;
162+
163+
snprintf(env,sizeof(env)-1,"LC_MESSAGES=%s",value);
164+
if (_putenv(env))
165+
returnNULL;
166+
}
167+
returnvalue;
168+
#endif/* WIN32 */
153169
}
154170

155171

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp