]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: env.c: remove unnecessary use of strchr
authorJim Meyering <meyering@redhat.com>
Wed, 25 May 2011 20:27:53 +0000 (22:27 +0200)
committerJim Meyering <meyering@redhat.com>
Thu, 26 May 2011 20:10:46 +0000 (22:10 +0200)
* src/env.c (main): Remove excess (and confusing to static analyzers)
use of strchr.

src/env.c

index 1eb39a110a858c59f67e7f8e816ed8750b9bba3c..9f7a8528bfae74300c799d771198d44482c2da8f 100644 (file)
--- a/src/env.c
+++ b/src/env.c
@@ -123,13 +123,17 @@ main (int argc, char **argv)
   if (optind < argc && STREQ (argv[optind], "-"))
     ++optind;
 
-  while (optind < argc && strchr (argv[optind], '='))
-    if (putenv (argv[optind++]))
-      {
-        char *name = argv[optind - 1];
-        *(strchr (name, '=')) = '\0';
-        error (EXIT_CANCELED, errno, _("cannot set %s"), quote (name));
-      }
+  char *eq;
+  while (optind < argc && (eq = strchr (argv[optind], '=')))
+    {
+      if (putenv (argv[optind]))
+        {
+          *eq = '\0';
+          error (EXIT_CANCELED, errno, _("cannot set %s"),
+                 quote (argv[optind]));
+        }
+      optind++;
+    }
 
   /* If no program is specified, print the environment and exit. */
   if (argc <= optind)