summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKiyoshi Aman <kiyoshi.aman+adelie@gmail.com>2019-05-29 22:37:29 -0500
committerKiyoshi Aman <kiyoshi.aman+adelie@gmail.com>2019-05-29 22:37:29 -0500
commit581fc205166c171f794eab4e8d98962cdd1d4e0c (patch)
tree2a7f69bbff951438e9ddb5e06b5357dcb5c2d6da
parent49985d6dab23172573beb37984a45eb61282395f (diff)
downloaduserland-581fc205166c171f794eab4e8d98962cdd1d4e0c.tar.gz
userland-581fc205166c171f794eab4e8d98962cdd1d4e0c.tar.bz2
userland-581fc205166c171f794eab4e8d98962cdd1d4e0c.tar.xz
userland-581fc205166c171f794eab4e8d98962cdd1d4e0c.zip
usr.bin/env: make buildable
-rw-r--r--usr.bin/env/env.c53
1 files 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 <sys/cdefs.h>
-#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 <err.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <bsd/stdlib.h>
#include <unistd.h>
#include <locale.h>
#include <errno.h>
@@ -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);
}