1
1
/*-------------------------------------------------------------------------
4
* putenv() and unsetenv() for win32, that updates both process
5
* environment and the cached versions in (potentially multiple)
4
* putenv() and unsetenv() for win32, that updates both process
5
* environment and the cached versions in (potentially multiple)
8
8
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
9
9
* Portions Copyright (c) 1994, Regents of the University of California
13
* $PostgreSQL: pgsql/src/port/win32env.c,v 1.2 2009/02/12 12:53:34 mha Exp $
13
* $PostgreSQL: pgsql/src/port/win32env.c,v 1.3 2009/06/11 14:49:15 momjian Exp $
15
15
*-------------------------------------------------------------------------
21
21
pgwin32_putenv(const char *envval)
27
27
* Each version of MSVCRT has its own _putenv() call in the runtime
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).
30
* If we're in VC 7.0 or later (means != mingw), update in the 6.0
31
* MSVCRT.DLL environment as well, to work with third party libraries
32
* linked against it (such as gnuwin32 libraries).
34
34
#if defined(_MSC_VER) && (_MSC_VER >= 1300)
35
typedef int (_cdecl *PUTENVPROC)(const char *);
37
static PUTENVPROC putenvFunc = NULL;
35
typedef int (_cdecl * PUTENVPROC) (const char *);
37
static PUTENVPROC putenvFunc = NULL;
40
40
if (putenvFunc == NULL)
42
42
hmodule = GetModuleHandle("msvcrt");
43
43
if (hmodule == NULL)
45
putenvFunc = (PUTENVPROC)GetProcAddress(hmodule, "_putenv");
45
putenvFunc = (PUTENVPROC) GetProcAddress(hmodule, "_putenv");
46
46
if (putenvFunc == NULL)
49
49
ret = putenvFunc(envval);
52
#endif /* _MSC_VER >= 1300 */
52
#endif /* _MSC_VER >= 1300 */
56
* Update the process environment - to make modifications visible
56
* Update the process environment - to make modifications visible to child
59
59
* Need a copy of the string so we can modify it.
70
70
* Only call SetEnvironmentVariable() when we are adding a variable,
71
* not when removing it. Calling it on both crashes on at least certain
71
* not when removing it. Calling it on both crashes on at least
72
* certain versions of MingW.
74
74
if (!SetEnvironmentVariable(envcpy, cp))