From 581fc205166c171f794eab4e8d98962cdd1d4e0c Mon Sep 17 00:00:00 2001 From: Kiyoshi Aman Date: Wed, 29 May 2019 22:37:29 -0500 Subject: usr.bin/env: make buildable --- usr.bin/env/env.c | 53 ++++++++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/usr.bin/env/env.c b/usr.bin/env/env.c index bf2430d..84567fd 100644 --- a/usr.bin/env/env.c +++ b/usr.bin/env/env.c @@ -27,21 +27,11 @@ * SUCH DAMAGE. */ -#include -#ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994\ - The Regents of the University of California. All rights reserved."); -#endif /* not lint */ - -#ifndef lint -/*static char sccsid[] = "@(#)env.c 8.3 (Berkeley) 4/2/94";*/ -__RCSID("$NetBSD: env.c,v 1.20 2010/11/16 02:53:49 christos Exp $"); -#endif /* not lint */ - #include #include #include #include +#include #include #include #include @@ -59,34 +49,31 @@ main(int argc, char **argv) setprogname(*argv); (void)setlocale(LC_ALL, ""); + *argv++; - while ((ch = getopt(argc, argv, "-i")) != -1) - switch((char)ch) { - case '-': /* obsolete */ - case 'i': - environ = cleanenv; - cleanenv[0] = NULL; - break; - case '?': - default: - usage(); - } + if (*argv && (!strcmp(*argv, "-i"))) { + environ = cleanenv; + cleanenv[0] = NULL; + *argv++; + } - for (argv += optind; *argv && strchr(*argv, '=') != NULL; ++argv) - (void)putenv(*argv); + if (*argv != NULL) { + for (; *argv && strchr(*argv, '=') != NULL; ++argv) + (void)putenv(*argv); - if (*argv) { - /* return 127 if the command to be run could not be found; 126 - if the command was found but could not be invoked */ + if (*argv) { + /* return 127 if the command to be run could not be found; 126 + if the command was found but could not be invoked */ - (void)execvp(*argv, argv); - err((errno == ENOENT) ? 127 : 126, "%s", *argv); - /* NOTREACHED */ + (void)execvp(*argv, argv); + err((errno == ENOENT) ? 127 : 126, "%s", *argv); + /* NOTREACHED */ + } + } else { + for (ep = environ; *ep; ep++) + (void)printf("%s\n", *ep); } - for (ep = environ; *ep; ep++) - (void)printf("%s\n", *ep); - exit(0); } -- cgit v1.2.3-70-g09d2