bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] putenv: avoid compilation warning on mingw


From: Eric Blake
Subject: [PATCH] putenv: avoid compilation warning on mingw
Date: Mon, 11 Mar 2013 06:16:39 -0600

On mingw, I got:

../../tests/putenv.c: In function '_unsetenv':
../../tests/putenv.c:65:10: warning: unused variable 'ep'

* lib/putenv.c (_unsetenv): Protect variable declaration.
(putenv): Fix indentation.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog    |  6 +++++
 lib/putenv.c | 76 +++++++++++++++++++++++++++++++-----------------------------
 2 files changed, 45 insertions(+), 37 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4b936ea..6d8c2c7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-03-11  Eric Blake  <address@hidden>
+
+       putenv: avoid compilation warning on mingw
+       * lib/putenv.c (_unsetenv): Protect variable declaration.
+       (putenv): Fix indentation.
+
 2013-03-11  Gary V. Vaughan  <address@hidden>

        unistd: don't prevent Tru64 Unix from using gnulib strtod.
diff --git a/lib/putenv.c b/lib/putenv.c
index ed666af..3813a11 100644
--- a/lib/putenv.c
+++ b/lib/putenv.c
@@ -62,7 +62,9 @@ static int
 _unsetenv (const char *name)
 {
   size_t len;
+#if !HAVE__PUTENV
   char **ep;
+#endif

   if (name == NULL || *name == '\0' || strchr (name, '=') != NULL)
     {
@@ -126,45 +128,45 @@ putenv (char *string)
     }

 #if HAVE__PUTENV
-      /* Rely on _putenv to allocate the new environment.  If other
-         parts of the application use _putenv, the !HAVE__PUTENV code
-         would fight over who owns the environ vector, causing a crash.  */
-      if (name_end[1])
-        return _putenv (string);
-      else
-        {
-          /* _putenv ("NAME=") unsets NAME, so invoke _putenv ("NAME= ")
-             to allocate the environ vector and then replace the new
-             entry with "NAME=".  */
-          int putenv_result, putenv_errno;
-          char *name_x = malloc (name_end - string + sizeof "= ");
-          if (!name_x)
-            return -1;
-          memcpy (name_x, string, name_end - string + 1);
-          name_x[name_end - string + 1] = ' ';
-          name_x[name_end - string + 2] = 0;
-          putenv_result = _putenv (name_x);
-          putenv_errno = errno;
-          for (ep = environ; *ep; ep++)
-            if (strcmp (*ep, name_x) == 0)
-              {
-                *ep = string;
-                break;
-              }
+  /* Rely on _putenv to allocate the new environment.  If other
+     parts of the application use _putenv, the !HAVE__PUTENV code
+     would fight over who owns the environ vector, causing a crash.  */
+  if (name_end[1])
+    return _putenv (string);
+  else
+    {
+      /* _putenv ("NAME=") unsets NAME, so invoke _putenv ("NAME= ")
+         to allocate the environ vector and then replace the new
+         entry with "NAME=".  */
+      int putenv_result, putenv_errno;
+      char *name_x = malloc (name_end - string + sizeof "= ");
+      if (!name_x)
+        return -1;
+      memcpy (name_x, string, name_end - string + 1);
+      name_x[name_end - string + 1] = ' ';
+      name_x[name_end - string + 2] = 0;
+      putenv_result = _putenv (name_x);
+      putenv_errno = errno;
+      for (ep = environ; *ep; ep++)
+        if (strcmp (*ep, name_x) == 0)
+          {
+            *ep = string;
+            break;
+          }
 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-          if (putenv_result == 0)
-            {
-              /* _putenv propagated "NAME= " into the subprocess environment;
-                 fix that by calling SetEnvironmentVariable directly.  */
-              name_x[name_end - string] = 0;
-              putenv_result = SetEnvironmentVariable (name_x, "") ? 0 : -1;
-              putenv_errno = ENOMEM; /* ENOMEM is the only way to fail.  */
-            }
-# endif
-          free (name_x);
-          __set_errno (putenv_errno);
-          return putenv_result;
+      if (putenv_result == 0)
+        {
+          /* _putenv propagated "NAME= " into the subprocess environment;
+             fix that by calling SetEnvironmentVariable directly.  */
+          name_x[name_end - string] = 0;
+          putenv_result = SetEnvironmentVariable (name_x, "") ? 0 : -1;
+          putenv_errno = ENOMEM; /* ENOMEM is the only way to fail.  */
         }
+# endif
+      free (name_x);
+      __set_errno (putenv_errno);
+      return putenv_result;
+    }
 #else
   for (ep = environ; *ep; ep++)
     if (strncmp (*ep, string, name_end - string) == 0
-- 
1.8.1.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]