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

Commit0154345

Browse files
committed
Make win32 builds always do SetEnvironmentVariable() when doing putenv().
Also, if linked against other versions than the default MSVCRT library(for example the MSVC build which links against MSVCRT80), also updatethe cache in the default MSVCRT at the same time.This should fix the issues with setting LC_MESSAGES on the MSVC build.Original patch from Hiroshi Inoue and Hiroshi Saito, much rewrittenby me.
1 parentfa40ca4 commit0154345

File tree

6 files changed

+175
-20
lines changed

6 files changed

+175
-20
lines changed

‎configure

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17919,6 +17919,12 @@ case " $LIBOBJS " in
1791917919
;;
1792017920
esac
1792117921

17922+
case " $LIBOBJS " in
17923+
*" win32env.$ac_objext "* ) ;;
17924+
*) LIBOBJS="$LIBOBJS win32env.$ac_objext"
17925+
;;
17926+
esac
17927+
1792217928
case " $LIBOBJS " in
1792317929
*" win32error.$ac_objext "* ) ;;
1792417930
*) LIBOBJS="$LIBOBJS win32error.$ac_objext"

‎configure.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $PostgreSQL: pgsql/configure.in,v 1.587 2009/01/14 18:10:21 momjian Exp $
2+
dnl $PostgreSQL: pgsql/configure.in,v 1.588 2009/01/2110:30:02 mha Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -1274,6 +1274,7 @@ AC_REPLACE_FUNCS(gettimeofday)
12741274
AC_LIBOBJ(kill)
12751275
AC_LIBOBJ(open)
12761276
AC_LIBOBJ(rand)
1277+
AC_LIBOBJ(win32env)
12771278
AC_LIBOBJ(win32error)
12781279
AC_DEFINE([HAVE_SYMLINK], 1,
12791280
[Define to 1 if you have the `symlink' function.])

‎src/backend/utils/adt/pg_locale.c

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Portions Copyright (c) 2002-2009, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/backend/utils/adt/pg_locale.c,v 1.45 2009/01/09 14:07:00 mha Exp $
7+
* $PostgreSQL: pgsql/src/backend/utils/adt/pg_locale.c,v 1.46 2009/01/21 10:30:02 mha Exp $
88
*
99
*-----------------------------------------------------------------------
1010
*/
@@ -55,6 +55,9 @@
5555
#include"utils/memutils.h"
5656
#include"utils/pg_locale.h"
5757

58+
#ifdefWIN32
59+
#include<shlwapi.h>
60+
#endif
5861

5962
#defineMAX_L10N_DATA80
6063

@@ -89,6 +92,10 @@ static char lc_monetary_envbuf[LC_ENV_BUFSIZE];
8992
staticcharlc_numeric_envbuf[LC_ENV_BUFSIZE];
9093
staticcharlc_time_envbuf[LC_ENV_BUFSIZE];
9194

95+
#ifdefWIN32
96+
staticchar*IsoLocaleName(constchar*);/* MSVC specific */
97+
#endif
98+
9299

93100
/*
94101
* pg_perm_setlocale
@@ -148,8 +155,13 @@ pg_perm_setlocale(int category, const char *locale)
148155
caseLC_MESSAGES:
149156
envvar="LC_MESSAGES";
150157
envbuf=lc_messages_envbuf;
158+
#ifdefWIN32
159+
result=IsoLocaleName(locale);
160+
if (result==NULL)
161+
result=locale;
162+
#endif/* WIN32 */
151163
break;
152-
#endif
164+
#endif/* LC_MESSAGES */
153165
caseLC_MONETARY:
154166
envvar="LC_MONETARY";
155167
envbuf=lc_monetary_envbuf;
@@ -166,25 +178,13 @@ pg_perm_setlocale(int category, const char *locale)
166178
elog(FATAL,"unrecognized LC category: %d",category);
167179
envvar=NULL;/* keep compiler quiet */
168180
envbuf=NULL;
169-
break;
181+
returnNULL;
170182
}
171183

172184
snprintf(envbuf,LC_ENV_BUFSIZE-1,"%s=%s",envvar,result);
173185

174-
#ifndefWIN32
175186
if (putenv(envbuf))
176187
returnNULL;
177-
#else
178-
179-
/*
180-
* On Windows, we need to modify both the process environment and the
181-
* cached version in msvcrt
182-
*/
183-
if (!SetEnvironmentVariable(envvar,result))
184-
returnNULL;
185-
if (_putenv(envbuf))
186-
returnNULL;
187-
#endif
188188

189189
returnresult;
190190
}
@@ -599,3 +599,53 @@ cache_locale_time(void)
599599

600600
CurrentLCTimeValid= true;
601601
}
602+
603+
604+
#ifdefWIN32
605+
/*
606+
*Convert Windows locale name to the ISO formatted one
607+
*if possible.
608+
*
609+
*This function returns NULL if conversion is impossible,
610+
*otherwise returns the pointer to a static area which
611+
*contains the iso formatted locale name.
612+
*/
613+
static
614+
char*IsoLocaleName(constchar*winlocname)
615+
{
616+
#if (_MSC_VER >=1400)/* VC8.0 or later */
617+
staticchariso_lc_messages[32];
618+
_locale_tloct=NULL;
619+
620+
if (pg_strcasecmp("c",winlocname)==0||
621+
pg_strcasecmp("posix",winlocname)==0)
622+
{
623+
strcpy(iso_lc_messages,"C");
624+
returniso_lc_messages;
625+
}
626+
627+
loct=_create_locale(LC_CTYPE,winlocname);
628+
if (loct!=NULL)
629+
{
630+
charisolang[32],isocrty[32];
631+
LCIDlcid;
632+
633+
lcid=loct->locinfo->lc_handle[LC_CTYPE];
634+
if (lcid==0)
635+
lcid=MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
636+
_free_locale(loct);
637+
638+
if (!GetLocaleInfoA(lcid,LOCALE_SISO639LANGNAME,isolang,sizeof(isolang)))
639+
returnNULL;
640+
if (!GetLocaleInfoA(lcid,LOCALE_SISO3166CTRYNAME,isocrty,sizeof(isocrty)))'
641+
returnNULL;
642+
snprintf(iso_lc_messages,sizeof(iso_lc_messages)-1,"%s_%s",isolang,isocrty);
643+
returniso_lc_messages;
644+
}
645+
returnNULL;
646+
#else
647+
returnNULL;/* Not supported on this version of msvc/mingw */
648+
#endif/* _MSC_VER >= 1400 */
649+
}
650+
#endif/* WIN32 */
651+

‎src/include/port/win32.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.85 2009/01/07 03:39:33 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.86 2009/01/21 10:30:02 mha Exp $ */
22

33
#if defined(_MSC_VER)|| defined(__BORLANDC__)
44
#defineWIN32_ONLY_COMPILER
@@ -291,6 +291,11 @@ extern intpgwin32_is_service(void);
291291
/* in port/win32error.c */
292292
externvoid_dosmaperr(unsigned long);
293293

294+
/* in port/win32env.c */
295+
externintpgwin32_putenv(constchar*);
296+
externvoidpgwin32_unsetenv(constchar*);
297+
#defineputenv(x) pgwin32_putenv(x)
298+
#defineunsetenv(x) pgwin32_unsetenv(x)
294299

295300
/* Things that exist in MingW headers, but need to be added to MSVC */
296301
#ifdefWIN32_ONLY_COMPILER

‎src/port/win32env.c

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* win32env.c
4+
* putenv() and unsetenv() for win32, that updates both process
5+
* environment and the cached versions in (potentially multiple)
6+
* MSVCRT.
7+
*
8+
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
9+
* Portions Copyright (c) 1994, Regents of the University of California
10+
*
11+
*
12+
* IDENTIFICATION
13+
* $PostgreSQL: pgsql/src/port/win32env.c,v 1.1 2009/01/21 10:30:02 mha Exp $
14+
*
15+
*-------------------------------------------------------------------------
16+
*/
17+
18+
#include"c.h"
19+
20+
int
21+
pgwin32_putenv(constchar*envval)
22+
{
23+
char*envcpy;
24+
char*cp;
25+
26+
/*
27+
* Each version of MSVCRT has its own _putenv() call in the runtime
28+
* library.
29+
*
30+
* If we're in VC 7.0 or later (means != mingw), update in
31+
* the 6.0 MSVCRT.DLL environment as well, to work with third party
32+
* libraries linked against it (such as gnuwin32 libraries).
33+
*/
34+
#if defined(_MSC_VER)&& (_MSC_VER >=1300)
35+
typedefint (_cdecl*PUTENVPROC)(constchar*);
36+
HMODULEhmodule;
37+
staticPUTENVPROCputenvFunc=NULL;
38+
intret;
39+
40+
if (putenvFunc==NULL)
41+
{
42+
hmodule=GetModuleHandle("msvcrt");
43+
if (hmodule==NULL)
44+
return1;
45+
putenvFunc= (PUTENVPROC)GetProcAddress(hmodule,"_putenv");
46+
if (putenvFunc==NULL)
47+
return1;
48+
}
49+
ret=putenvFunc(envval);
50+
if (ret!=0)
51+
returnret;
52+
#endif/* _MSC_VER >= 1300 */
53+
54+
55+
/*
56+
* Update the process environment - to make modifications visible
57+
* to child processes.
58+
*
59+
* Need a copy of the string so we can modify it.
60+
*/
61+
envcpy=strdup(envval);
62+
cp=strchr(envcpy,'=');
63+
if (cp==NULL)
64+
return-1;
65+
*cp='\0';
66+
cp++;
67+
if (strlen(cp)==0)
68+
cp=NULL;
69+
if (!SetEnvironmentVariable(envcpy,cp))
70+
{
71+
free(envcpy);
72+
return-1;
73+
}
74+
free(envcpy);
75+
76+
/* Finally, update our "own" cache */
77+
return_putenv(envval);
78+
}
79+
80+
void
81+
pgwin32_unsetenv(constchar*name)
82+
{
83+
char*envbuf;
84+
85+
envbuf= (char*)malloc(strlen(name)+2);
86+
if (!envbuf)
87+
return;
88+
89+
sprintf(envbuf,"%s=",name);
90+
pgwin32_putenv(envbuf);
91+
free(envbuf);
92+
}
93+

‎src/tools/msvc/Mkvcbuild.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package Mkvcbuild;
33
#
44
# Package that generates build files for msvc build
55
#
6-
# $PostgreSQL: pgsql/src/tools/msvc/Mkvcbuild.pm,v 1.35 2008/12/20 22:04:02 mha Exp $
6+
# $PostgreSQL: pgsql/src/tools/msvc/Mkvcbuild.pm,v 1.36 2009/01/21 10:30:02 mha Exp $
77
#
88
use Carp;
99
use Win32;
@@ -44,10 +44,10 @@ sub mkvcbuild
4444

4545
our@pgportfiles =qw(
4646
chklocale.c crypt.c fseeko.c getrusage.c inet_aton.c random.c srandom.c
47-
unsetenv.cgetaddrinfo.c gettimeofday.c kill.c open.c rand.c
47+
getaddrinfo.c gettimeofday.c kill.c open.c rand.c
4848
snprintf.c strlcat.c strlcpy.c copydir.c dirmod.c exec.c noblock.c path.c pipe.c
4949
pgsleep.c pgstrcasecmp.c qsort.c qsort_arg.c sprompt.c thread.c
50-
getopt.c getopt_long.c dirent.c rint.c win32error.c);
50+
getopt.c getopt_long.c dirent.c rint.cwin32env.cwin32error.c);
5151

5252
$libpgport =$solution->AddProject('libpgport','lib','misc');
5353
$libpgport->AddDefine('FRONTEND');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp