mirror of
https://github.com/postgres/postgres.git
synced 2025-05-01 01:04:50 +03:00
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.
This commit is contained in:
parent
523bb1de83
commit
bf5ecaae4a
@ -1,9 +1,8 @@
|
|||||||
/*-------------------------------------------------------------------------
|
/*-------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* win32env.c
|
* win32env.c
|
||||||
* putenv() and unsetenv() for win32, that updates both process
|
* putenv() and unsetenv() for win32, which update both process environment
|
||||||
* environment and the cached versions in (potentially multiple)
|
* and caches in (potentially multiple) C run-time library (CRT) versions.
|
||||||
* MSVCRT.
|
|
||||||
*
|
*
|
||||||
* Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
@ -24,17 +23,10 @@ pgwin32_putenv(const char *envval)
|
|||||||
char *cp;
|
char *cp;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Each version of MSVCRT has its own _putenv() call in the runtime
|
* Each CRT has its own _putenv() symbol and copy of the environment.
|
||||||
* library.
|
* Update the environment in each CRT module currently loaded, so every
|
||||||
*
|
* third-party library sees this change regardless of the CRT it links
|
||||||
* mingw always uses MSVCRT.DLL, but if we are in a Visual C++
|
* against.
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
typedef int (_cdecl * PUTENVPROC) (const char *);
|
typedef int (_cdecl * PUTENVPROC) (const char *);
|
||||||
@ -46,31 +38,31 @@ pgwin32_putenv(const char *envval)
|
|||||||
} rtmodules[] =
|
} rtmodules[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
"msvcrt", 0, NULL
|
"msvcrt", NULL, NULL
|
||||||
}, /* Visual Studio 6.0 / mingw */
|
}, /* Visual Studio 6.0 / MinGW */
|
||||||
{
|
{
|
||||||
"msvcr70", 0, NULL
|
"msvcr70", NULL, NULL
|
||||||
}, /* Visual Studio 2002 */
|
}, /* Visual Studio 2002 */
|
||||||
{
|
{
|
||||||
"msvcr71", 0, NULL
|
"msvcr71", NULL, NULL
|
||||||
}, /* Visual Studio 2003 */
|
}, /* Visual Studio 2003 */
|
||||||
{
|
{
|
||||||
"msvcr80", 0, NULL
|
"msvcr80", NULL, NULL
|
||||||
}, /* Visual Studio 2005 */
|
}, /* Visual Studio 2005 */
|
||||||
{
|
{
|
||||||
"msvcr90", 0, NULL
|
"msvcr90", NULL, NULL
|
||||||
}, /* Visual Studio 2008 */
|
}, /* Visual Studio 2008 */
|
||||||
{
|
{
|
||||||
"msvcr100", 0, NULL
|
"msvcr100", NULL, NULL
|
||||||
}, /* Visual Studio 2010 */
|
}, /* Visual Studio 2010 */
|
||||||
{
|
{
|
||||||
"msvcr110", 0, NULL
|
"msvcr110", NULL, NULL
|
||||||
}, /* Visual Studio 2012 */
|
}, /* Visual Studio 2012 */
|
||||||
{
|
{
|
||||||
"msvcr120", 0, NULL
|
"msvcr120", NULL, NULL
|
||||||
}, /* Visual Studio 2013 */
|
}, /* Visual Studio 2013 */
|
||||||
{
|
{
|
||||||
NULL, 0, NULL
|
NULL, NULL, NULL
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
int i;
|
int i;
|
||||||
@ -79,7 +71,7 @@ pgwin32_putenv(const char *envval)
|
|||||||
{
|
{
|
||||||
if (rtmodules[i].putenvFunc == NULL)
|
if (rtmodules[i].putenvFunc == NULL)
|
||||||
{
|
{
|
||||||
if (rtmodules[i].hmodule == 0)
|
if (rtmodules[i].hmodule == NULL)
|
||||||
{
|
{
|
||||||
/* Not attempted before, so try to find this DLL */
|
/* Not attempted before, so try to find this DLL */
|
||||||
rtmodules[i].hmodule = GetModuleHandle(rtmodules[i].modulename);
|
rtmodules[i].hmodule = GetModuleHandle(rtmodules[i].modulename);
|
||||||
@ -118,8 +110,8 @@ pgwin32_putenv(const char *envval)
|
|||||||
#endif /* _MSC_VER */
|
#endif /* _MSC_VER */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update the process environment - to make modifications visible to child
|
* Update process environment, making this change visible to child
|
||||||
* processes.
|
* processes and to CRTs initializing in the future.
|
||||||
*
|
*
|
||||||
* Need a copy of the string so we can modify it.
|
* Need a copy of the string so we can modify it.
|
||||||
*/
|
*/
|
||||||
@ -139,7 +131,7 @@ pgwin32_putenv(const char *envval)
|
|||||||
/*
|
/*
|
||||||
* Only call SetEnvironmentVariable() when we are adding a variable,
|
* Only call SetEnvironmentVariable() when we are adding a variable,
|
||||||
* not when removing it. Calling it on both crashes on at least
|
* not when removing it. Calling it on both crashes on at least
|
||||||
* certain versions of MingW.
|
* certain versions of MinGW.
|
||||||
*/
|
*/
|
||||||
if (!SetEnvironmentVariable(envcpy, cp))
|
if (!SetEnvironmentVariable(envcpy, cp))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user