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)
123123const char *
124124locale_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)
131132if (doit )
132133{
133134if (!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
145135return NULL ;
146- #endif
147- }
148136}
149137else
150138value = locale_xxx_assign (LC_MESSAGES ,value , false,source );
151139#endif /* LC_MESSAGES */
152140return 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