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
|
||||
* 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-2014, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
@ -24,17 +23,10 @@ pgwin32_putenv(const char *envval)
|
||||
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 *);
|
||||
@ -46,31 +38,31 @@ pgwin32_putenv(const char *envval)
|
||||
} 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 */
|
||||
{
|
||||
NULL, 0, NULL
|
||||
NULL, NULL, NULL
|
||||
}
|
||||
};
|
||||
int i;
|
||||
@ -79,7 +71,7 @@ pgwin32_putenv(const char *envval)
|
||||
{
|
||||
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);
|
||||
@ -118,8 +110,8 @@ pgwin32_putenv(const char *envval)
|
||||
#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.
|
||||
*/
|
||||
@ -139,7 +131,7 @@ pgwin32_putenv(const char *envval)
|
||||
/*
|
||||
* 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))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user