From 52aee80c874801c37df9346ab3fed8e7c280a2e6 Mon Sep 17 00:00:00 2001 From: Ray Lai Date: Sun, 28 May 2006 04:21:14 +0000 Subject: o KNF o Remove unnecessary casts o Add __dead o Remove /* NOTREACHED */ o Remove cases '?' and '-' o Use more conventional getopt(3) syntax (argc -= optind; argv += optind; right after while loop) OK deraadt@ --- usr.bin/env/env.1 | 6 +----- usr.bin/env/env.c | 33 +++++++++++++++++---------------- 2 files changed, 18 insertions(+), 21 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/env/env.1 b/usr.bin/env/env.1 index 51574c8d447..0c2a0d50be7 100644 --- a/usr.bin/env/env.1 +++ b/usr.bin/env/env.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: env.1,v 1.11 2004/01/23 23:08:46 jmc Exp $ +.\" $OpenBSD: env.1,v 1.12 2006/05/28 04:21:13 ray Exp $ .\" Copyright (c) 1980, 1990 The Regents of the University of California. .\" All rights reserved. .\" @@ -107,10 +107,6 @@ could not be found. .Xr execvp 3 , .Xr environ 7 .Sh STANDARDS -The historic -.Fl -option has been deprecated but is still supported in this implementation. -.Pp The .Nm utility conforms to diff --git a/usr.bin/env/env.c b/usr.bin/env/env.c index 445b50c20b4..db5d70f7f6c 100644 --- a/usr.bin/env/env.c +++ b/usr.bin/env/env.c @@ -1,4 +1,4 @@ -/* $OpenBSD: env.c,v 1.10 2003/06/10 22:20:46 deraadt Exp $ */ +/* $OpenBSD: env.c,v 1.11 2006/05/28 04:21:13 ray Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -37,18 +37,18 @@ static char copyright[] = #ifndef lint /*static char sccsid[] = "@(#)env.c 8.3 (Berkeley) 4/2/94";*/ -static char rcsid[] = "$OpenBSD: env.c,v 1.10 2003/06/10 22:20:46 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: env.c,v 1.11 2006/05/28 04:21:13 ray Exp $"; #endif /* not lint */ #include +#include +#include #include -#include #include +#include #include -#include -#include -void usage(void); +__dead void usage(void); int main(int argc, char *argv[]) @@ -60,19 +60,19 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "i-")) != -1) - switch((char)ch) { - case '-': /* obsolete */ + while ((ch = getopt(argc, argv, "i")) != -1) + switch(ch) { case 'i': - if ((environ = (char **)calloc(1, sizeof(char *))) == NULL) + if ((environ = calloc(1, sizeof(char *))) == NULL) err(126, "calloc"); break; - case '?': default: usage(); } + argc -= optind; + argv += optind; - for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) + for (; *argv && (p = strchr(*argv, '=')); ++argv) if (setenv(*argv, ++p, 1) == -1) { /* reuse 126, it matches the problem most */ exit(126); @@ -86,7 +86,6 @@ main(int argc, char *argv[]) */ execvp(*argv, argv); err((errno == ENOENT) ? 127 : 126, "%s", *argv); - /* NOTREACHED */ } for (ep = environ; *ep; ep++) @@ -98,7 +97,9 @@ main(int argc, char *argv[]) void usage(void) { - (void)fprintf(stderr, "usage: env [-i] [name=value ...] " - "[utility [argument ...]]\n"); - exit (1); + extern char *__progname; + + (void)fprintf(stderr, "usage: %s [-i] [name=value ...] " + "[utility [argument ...]]\n", __progname); + exit(1); } -- cgit v1.2.3