4
4
*
5
5
* Portions Copyright (c) 2002-2004, PostgreSQL Global Development Group
6
6
*
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 $
8
8
*
9
9
*-----------------------------------------------------------------------
10
10
*/
@@ -123,6 +123,7 @@ locale_time_assign(const char *value, bool doit, GucSource source)
123
123
const char *
124
124
locale_messages_assign (const char * value , bool doit , GucSource source )
125
125
{
126
+ #ifndef WIN32
126
127
/*
127
128
* LC_MESSAGES category does not exist everywhere, but accept it
128
129
* anyway
@@ -131,25 +132,40 @@ locale_messages_assign(const char *value, bool doit, GucSource source)
131
132
if (doit )
132
133
{
133
134
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
145
135
return NULL ;
146
- #endif
147
- }
148
136
}
149
137
else
150
138
value = locale_xxx_assign (LC_MESSAGES , value , false, source );
151
139
#endif /* LC_MESSAGES */
152
140
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 */
153
169
}
154
170
155
171
0 commit comments