1
1
/*-------------------------------------------------------------------------
2
2
*
3
3
* 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.
7
6
*
8
7
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
9
8
* Portions Copyright (c) 1994, Regents of the University of California
@@ -24,17 +23,10 @@ pgwin32_putenv(const char *envval)
24
23
char * cp ;
25
24
26
25
/*
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.
38
30
*/
39
31
#ifdef _MSC_VER
40
32
typedef int (_cdecl * PUTENVPROC ) (const char * );
@@ -46,28 +38,28 @@ pgwin32_putenv(const char *envval)
46
38
} rtmodules [] =
47
39
{
48
40
{
49
- "msvcrt" , 0 , NULL
50
- }, /* Visual Studio 6.0 / mingw */
41
+ "msvcrt" , NULL , NULL
42
+ }, /* Visual Studio 6.0 / MinGW */
51
43
{
52
- "msvcr70" , 0 , NULL
44
+ "msvcr70" , NULL , NULL
53
45
}, /* Visual Studio 2002 */
54
46
{
55
- "msvcr71" , 0 , NULL
47
+ "msvcr71" , NULL , NULL
56
48
}, /* Visual Studio 2003 */
57
49
{
58
- "msvcr80" , 0 , NULL
50
+ "msvcr80" , NULL , NULL
59
51
}, /* Visual Studio 2005 */
60
52
{
61
- "msvcr90" , 0 , NULL
53
+ "msvcr90" , NULL , NULL
62
54
}, /* Visual Studio 2008 */
63
55
{
64
- "msvcr100" , 0 , NULL
56
+ "msvcr100" , NULL , NULL
65
57
}, /* Visual Studio 2010 */
66
58
{
67
- "msvcr110" , 0 , NULL
59
+ "msvcr110" , NULL , NULL
68
60
}, /* Visual Studio 2012 */
69
61
{
70
- NULL , 0 , NULL
62
+ NULL , NULL , NULL
71
63
}
72
64
};
73
65
int i ;
@@ -76,7 +68,7 @@ pgwin32_putenv(const char *envval)
76
68
{
77
69
if (rtmodules [i ].putenvFunc == NULL )
78
70
{
79
- if (rtmodules [i ].hmodule == 0 )
71
+ if (rtmodules [i ].hmodule == NULL )
80
72
{
81
73
/* Not attempted before, so try to find this DLL */
82
74
rtmodules [i ].hmodule = GetModuleHandle (rtmodules [i ].modulename );
@@ -115,8 +107,8 @@ pgwin32_putenv(const char *envval)
115
107
#endif /* _MSC_VER */
116
108
117
109
/*
118
- * Update the process environment - to make modifications visible to child
119
- * processes.
110
+ * Update process environment, making this change visible to child
111
+ * processes and to CRTs initializing in the future .
120
112
*
121
113
* Need a copy of the string so we can modify it.
122
114
*/
@@ -136,7 +128,7 @@ pgwin32_putenv(const char *envval)
136
128
/*
137
129
* Only call SetEnvironmentVariable() when we are adding a variable,
138
130
* not when removing it. Calling it on both crashes on at least
139
- * certain versions of MingW .
131
+ * certain versions of MinGW .
140
132
*/
141
133
if (!SetEnvironmentVariable (envcpy , cp ))
142
134
{
0 commit comments