* sysdeps/generic/dl-environ.c (unsetenv): Redo last fix without
authorRoland McGrath <roland@gnu.org>
Wed, 11 Sep 2002 22:16:50 +0000 (22:16 +0000)
committerRoland McGrath <roland@gnu.org>
Wed, 11 Sep 2002 22:16:50 +0000 (22:16 +0000)
strncmp, keeps the code smaller for a non-performance-critical case.

ChangeLog
sysdeps/generic/dl-environ.c

index 828b537..5d6a1cb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2002-09-11  Roland McGrath  <roland@redhat.com>
 
+       * sysdeps/generic/dl-environ.c (unsetenv): Redo last fix without
+       strncmp, keeps the code smaller for a non-performance-critical case.
+
        * sysdeps/generic/dl-environ.c (unsetenv): Rewritten using strncmp,
        no longer wrongly matches arbitrary prefixes of NAME.
        Reported by Jakub Jelinek <jakub@redhat.com>.
index 30fe565..089e89e 100644 (file)
@@ -57,23 +57,30 @@ extern char **__environ attribute_hidden;
 int
 unsetenv (const char *name)
 {
-  const size_t len = strlen (name);
   char **ep;
 
   ep = __environ;
   while (*ep != NULL)
-    if (!strncmp (*ep, name, len) && (*ep)[len] == '=')
-      {
-       /* Found it.  Remove this pointer by moving later ones back.  */
-       char **dp = ep;
-
-       do
-         dp[0] = dp[1];
-       while (*dp++);
-       /* Continue the loop in case NAME appears again.  */
-      }
-    else
-      ++ep;
+    {
+      size_t cnt = 0;
+
+      while ((*ep)[cnt] == name[cnt] && name[cnt] != '\0')
+       ++cnt;
+
+      if (name[cnt] == '\0' && (*ep)[cnt] == '=')
+       {
+         /* Found it.  Remove this pointer by moving later ones to
+            the front.  */
+         char **dp = ep;
+
+         do
+           dp[0] = dp[1];
+         while (*dp++);
+         /* Continue the loop in case NAME appears again.  */
+       }
+      else
+       ++ep;
+    }
 
   return 0;
 }