Refine win32env.c cosmetics.
authorNoah Misch <noah@leadboat.com>
Sat, 3 Dec 2016 20:46:35 +0000 (15:46 -0500)
committerNoah Misch <noah@leadboat.com>
Sat, 3 Dec 2016 20:47:06 +0000 (15:47 -0500)
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.

src/port/win32env.c

index 789d9725b516f13d702ab5480a2f5763fe39fd66..9d056917a1285116045b479d69bade2a9c8fbe79 100644 (file)
@@ -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))
        {