]> granicus.if.org Git - postgresql/commitdiff
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:46:42 +0000 (15:46 -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 e64065ca29529acbfa541e04886e6e50bb104bc4..621ec8d67f2e7e84152182f9181c60f7577ef393 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-2016, 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,34 +38,34 @@ 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 */
                {
-                       "ucrtbase", 0, NULL
+                       "ucrtbase", NULL, NULL
                },                                              /* Visual Studio 2015 and later */
                {
-                       NULL, 0, NULL
+                       NULL, NULL, NULL
                }
        };
        int                     i;
@@ -82,7 +74,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);
@@ -121,8 +113,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.
         */
@@ -142,7 +134,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))
                {