/*-------------------------------------------------------------------------
*
* win32env.c
- * putenv() and unsetenv() for win32, that updates both process
- * environment and the cached versions in (potentially multiple)
- * MSVCRT.
+ * putenv() and unsetenv() for win32, which update both process environment
+ * and caches in (potentially multiple) C run-time library (CRT) versions.
*
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
char *cp;
/*
- * Each version of MSVCRT has its own _putenv() call in the runtime
- * library.
- *
- * mingw always uses MSVCRT.DLL, but if we are in a Visual C++
- * environment, attempt to update the environment in all MSVCRT modules
- * that are currently loaded, to work properly with any third party
- * libraries linked against a different MSVCRT but still relying on
- * environment variables.
- *
- * Also separately update the system environment that gets inherited by
- * subprocesses.
+ * Each CRT has its own _putenv() symbol and copy of the environment.
+ * Update the environment in each CRT module currently loaded, so every
+ * third-party library sees this change regardless of the CRT it links
+ * against.
*/
#ifdef _MSC_VER
typedef int (_cdecl * PUTENVPROC) (const char *);
} rtmodules[] =
{
{
- "msvcrt", 0, NULL
- }, /* Visual Studio 6.0 / mingw */
+ "msvcrt", NULL, NULL
+ }, /* Visual Studio 6.0 / MinGW */
{
- "msvcr70", 0, NULL
+ "msvcr70", NULL, NULL
}, /* Visual Studio 2002 */
{
- "msvcr71", 0, NULL
+ "msvcr71", NULL, NULL
}, /* Visual Studio 2003 */
{
- "msvcr80", 0, NULL
+ "msvcr80", NULL, NULL
}, /* Visual Studio 2005 */
{
- "msvcr90", 0, NULL
+ "msvcr90", NULL, NULL
}, /* Visual Studio 2008 */
{
- "msvcr100", 0, NULL
+ "msvcr100", NULL, NULL
}, /* Visual Studio 2010 */
{
- "msvcr110", 0, NULL
+ "msvcr110", NULL, NULL
}, /* Visual Studio 2012 */
{
- "msvcr120", 0, NULL
+ "msvcr120", NULL, NULL
}, /* Visual Studio 2013 */
{
- "ucrtbase", 0, NULL
+ "ucrtbase", NULL, NULL
}, /* Visual Studio 2015 and later */
{
- NULL, 0, NULL
+ NULL, NULL, NULL
}
};
int i;
{
if (rtmodules[i].putenvFunc == NULL)
{
- if (rtmodules[i].hmodule == 0)
+ if (rtmodules[i].hmodule == NULL)
{
/* Not attempted before, so try to find this DLL */
rtmodules[i].hmodule = GetModuleHandle(rtmodules[i].modulename);
#endif /* _MSC_VER */
/*
- * Update the process environment - to make modifications visible to child
- * processes.
+ * Update process environment, making this change visible to child
+ * processes and to CRTs initializing in the future.
*
* Need a copy of the string so we can modify it.
*/
/*
* Only call SetEnvironmentVariable() when we are adding a variable,
* not when removing it. Calling it on both crashes on at least
- * certain versions of MingW.
+ * certain versions of MinGW.
*/
if (!SetEnvironmentVariable(envcpy, cp))
{