Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d66dcb4

Browse files
committed
Refine win32env.c cosmetics.
Replace use of plain 0 as a null pointer constant. In comments, update terminology and lessen redundancy. Back-patch to 9.2 (all supported versions) for the convenience of back-patching the next two commits. Christian Ullrich and Noah Misch, reviewed (in earlier versions) by Michael Paquier.
1 parent 4e01eca commit d66dcb4

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

src/port/win32env.c

+21-29
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/*-------------------------------------------------------------------------
22
*
33
* win32env.c
4-
* putenv() and unsetenv() for win32, that updates both process
5-
* environment and the cached versions in (potentially multiple)
6-
* MSVCRT.
4+
* putenv() and unsetenv() for win32, which update both process environment
5+
* and caches in (potentially multiple) C run-time library (CRT) versions.
76
*
87
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
98
* Portions Copyright (c) 1994, Regents of the University of California
@@ -24,17 +23,10 @@ pgwin32_putenv(const char *envval)
2423
char *cp;
2524

2625
/*
27-
* Each version of MSVCRT has its own _putenv() call in the runtime
28-
* library.
29-
*
30-
* mingw always uses MSVCRT.DLL, but if we are in a Visual C++
31-
* environment, attempt to update the environment in all MSVCRT modules
32-
* that are currently loaded, to work properly with any third party
33-
* libraries linked against a different MSVCRT but still relying on
34-
* environment variables.
35-
*
36-
* Also separately update the system environment that gets inherited by
37-
* subprocesses.
26+
* Each CRT has its own _putenv() symbol and copy of the environment.
27+
* Update the environment in each CRT module currently loaded, so every
28+
* third-party library sees this change regardless of the CRT it links
29+
* against.
3830
*/
3931
#ifdef _MSC_VER
4032
typedef int (_cdecl * PUTENVPROC) (const char *);
@@ -46,34 +38,34 @@ pgwin32_putenv(const char *envval)
4638
} rtmodules[] =
4739
{
4840
{
49-
"msvcrt", 0, NULL
50-
}, /* Visual Studio 6.0 / mingw */
41+
"msvcrt", NULL, NULL
42+
}, /* Visual Studio 6.0 / MinGW */
5143
{
52-
"msvcr70", 0, NULL
44+
"msvcr70", NULL, NULL
5345
}, /* Visual Studio 2002 */
5446
{
55-
"msvcr71", 0, NULL
47+
"msvcr71", NULL, NULL
5648
}, /* Visual Studio 2003 */
5749
{
58-
"msvcr80", 0, NULL
50+
"msvcr80", NULL, NULL
5951
}, /* Visual Studio 2005 */
6052
{
61-
"msvcr90", 0, NULL
53+
"msvcr90", NULL, NULL
6254
}, /* Visual Studio 2008 */
6355
{
64-
"msvcr100", 0, NULL
56+
"msvcr100", NULL, NULL
6557
}, /* Visual Studio 2010 */
6658
{
67-
"msvcr110", 0, NULL
59+
"msvcr110", NULL, NULL
6860
}, /* Visual Studio 2012 */
6961
{
70-
"msvcr120", 0, NULL
62+
"msvcr120", NULL, NULL
7163
}, /* Visual Studio 2013 */
7264
{
73-
"ucrtbase", 0, NULL
65+
"ucrtbase", NULL, NULL
7466
}, /* Visual Studio 2015 and later */
7567
{
76-
NULL, 0, NULL
68+
NULL, NULL, NULL
7769
}
7870
};
7971
int i;
@@ -82,7 +74,7 @@ pgwin32_putenv(const char *envval)
8274
{
8375
if (rtmodules[i].putenvFunc == NULL)
8476
{
85-
if (rtmodules[i].hmodule == 0)
77+
if (rtmodules[i].hmodule == NULL)
8678
{
8779
/* Not attempted before, so try to find this DLL */
8880
rtmodules[i].hmodule = GetModuleHandle(rtmodules[i].modulename);
@@ -121,8 +113,8 @@ pgwin32_putenv(const char *envval)
121113
#endif /* _MSC_VER */
122114

123115
/*
124-
* Update the process environment - to make modifications visible to child
125-
* processes.
116+
* Update process environment, making this change visible to child
117+
* processes and to CRTs initializing in the future.
126118
*
127119
* Need a copy of the string so we can modify it.
128120
*/
@@ -142,7 +134,7 @@ pgwin32_putenv(const char *envval)
142134
/*
143135
* Only call SetEnvironmentVariable() when we are adding a variable,
144136
* not when removing it. Calling it on both crashes on at least
145-
* certain versions of MingW.
137+
* certain versions of MinGW.
146138
*/
147139
if (!SetEnvironmentVariable(envcpy, cp))
148140
{

0 commit comments

Comments
 (0)