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-2016, 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,34 +38,34 @@ 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
- "msvcr120" , 0 , NULL
62
+ "msvcr120" , NULL , NULL
71
63
}, /* Visual Studio 2013 */
72
64
{
73
- "ucrtbase" , 0 , NULL
65
+ "ucrtbase" , NULL , NULL
74
66
}, /* Visual Studio 2015 and later */
75
67
{
76
- NULL , 0 , NULL
68
+ NULL , NULL , NULL
77
69
}
78
70
};
79
71
int i ;
@@ -82,7 +74,7 @@ pgwin32_putenv(const char *envval)
82
74
{
83
75
if (rtmodules [i ].putenvFunc == NULL )
84
76
{
85
- if (rtmodules [i ].hmodule == 0 )
77
+ if (rtmodules [i ].hmodule == NULL )
86
78
{
87
79
/* Not attempted before, so try to find this DLL */
88
80
rtmodules [i ].hmodule = GetModuleHandle (rtmodules [i ].modulename );
@@ -121,8 +113,8 @@ pgwin32_putenv(const char *envval)
121
113
#endif /* _MSC_VER */
122
114
123
115
/*
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 .
126
118
*
127
119
* Need a copy of the string so we can modify it.
128
120
*/
@@ -142,7 +134,7 @@ pgwin32_putenv(const char *envval)
142
134
/*
143
135
* Only call SetEnvironmentVariable() when we are adding a variable,
144
136
* not when removing it. Calling it on both crashes on at least
145
- * certain versions of MingW .
137
+ * certain versions of MinGW .
146
138
*/
147
139
if (!SetEnvironmentVariable (envcpy , cp ))
148
140
{
0 commit comments