diff options
author | Jared Yanovich <jaredy@cvs.openbsd.org> | 2005-10-11 01:23:42 +0000 |
---|---|---|
committer | Jared Yanovich <jaredy@cvs.openbsd.org> | 2005-10-11 01:23:42 +0000 |
commit | 9de29a0a70540571c60f700b1d3f39da56d90198 (patch) | |
tree | 42b6347686636dacb8d679f0b2817f3978572f74 /lib/libc | |
parent | 84d65e93af5f549a6a231de6c1463310a43308c9 (diff) |
tidy up examples
- use err() for error handling
- add lint hints
- spacing nits and missing braces
ok otto
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/stdlib/getopt.3 | 11 | ||||
-rw-r--r-- | lib/libc/stdlib/getopt_long.3 | 10 | ||||
-rw-r--r-- | lib/libc/stdlib/getsubopt.3 | 12 |
3 files changed, 16 insertions, 17 deletions
diff --git a/lib/libc/stdlib/getopt.3 b/lib/libc/stdlib/getopt.3 index 9de8af3dcfb..f07f01dd7f3 100644 --- a/lib/libc/stdlib/getopt.3 +++ b/lib/libc/stdlib/getopt.3 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: getopt.3,v 1.36 2005/07/26 13:38:41 jmc Exp $ +.\" $OpenBSD: getopt.3,v 1.37 2005/10/11 01:23:41 jaredy Exp $ .\" .Dd December 17, 2002 .Dt GETOPT 3 @@ -187,15 +187,12 @@ while ((ch = getopt(argc, argv, "bf:")) != -1) { bflag = 1; break; case 'f': - if ((fd = open(optarg, O_RDONLY, 0)) < 0) { - (void)fprintf(stderr, - "myname: %s: %s\en", optarg, strerror(errno)); - exit(1); - } + if ((fd = open(optarg, O_RDONLY, 0)) == -1) + err(1, "%s", optarg); break; - case '?': default: usage(); + /* NOTREACHED */ } } argc -= optind; diff --git a/lib/libc/stdlib/getopt_long.3 b/lib/libc/stdlib/getopt_long.3 index 7899499cf7c..bf5ba22ece5 100644 --- a/lib/libc/stdlib/getopt_long.3 +++ b/lib/libc/stdlib/getopt_long.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: getopt_long.3,v 1.11 2005/07/26 04:17:44 jaredy Exp $ +.\" $OpenBSD: getopt_long.3,v 1.12 2005/10/11 01:23:41 jaredy Exp $ .\" $NetBSD: getopt_long.3,v 1.11 2002/10/02 10:54:19 wiz Exp $ .\" .\" Copyright (c) 1988, 1991, 1993 @@ -223,14 +223,14 @@ while ((ch = getopt_long(argc, argv, "bf:", longopts, NULL)) != -1) err(1, "unable to open %s", optarg); break; case 0: - if (daggerset) { - fprintf(stderr,"Buffy will use her dagger to " + if (daggerset) + fprintf(stderr, "Buffy will use her dagger to " "apply fluoride to dracula's teeth\en"); - } break; default: usage(); -} + /* NOTREACHED */ + } argc -= optind; argv += optind; .Ed diff --git a/lib/libc/stdlib/getsubopt.3 b/lib/libc/stdlib/getsubopt.3 index d0308e2d509..6a7c28ff4df 100644 --- a/lib/libc/stdlib/getsubopt.3 +++ b/lib/libc/stdlib/getsubopt.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: getsubopt.3,v 1.10 2005/07/26 04:20:23 jaredy Exp $ +.\" $OpenBSD: getsubopt.3,v 1.11 2005/10/11 01:23:41 jaredy Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -104,15 +104,15 @@ char *tokens[] = { extern char *optarg, *suboptarg; char *options, *value; -while ((ch = getopt(argc, argv, "ab:")) != \-1) { - switch(ch) { +while ((ch = getopt(argc, argv, "ab:")) != -1) { + switch (ch) { case 'a': /* process ``a'' option */ break; case 'b': options = optarg; while (*options) { - switch(getsubopt(&options, tokens, &value)) { + switch (getsubopt(&options, tokens, &value)) { case ONE: /* process ``one'' sub option */ break; @@ -122,16 +122,18 @@ while ((ch = getopt(argc, argv, "ab:")) != \-1) { error("no value for two"); i = atoi(value); break; - case \-1: + case -1: if (suboptarg) error("illegal sub option %s", suboptarg); else error("missing sub option"); break; + } } break; } +} .Ed .Sh SEE ALSO .Xr getopt 3 , |