diff options
| author | jaredy <> | 2005-10-11 01:23:41 +0000 |
|---|---|---|
| committer | jaredy <> | 2005-10-11 01:23:41 +0000 |
| commit | e1d1b24354f52fc5c2530e9ea0bb3b597ad92fc5 (patch) | |
| tree | 95ce29f3d0d95146fb733032126b399636d5c963 /src/lib/libc/stdlib | |
| parent | 532c08f68e843a46a28fff0ae07e92866af2da42 (diff) | |
| download | openbsd-e1d1b24354f52fc5c2530e9ea0bb3b597ad92fc5.tar.gz openbsd-e1d1b24354f52fc5c2530e9ea0bb3b597ad92fc5.tar.bz2 openbsd-e1d1b24354f52fc5c2530e9ea0bb3b597ad92fc5.zip | |
tidy up examples
- use err() for error handling
- add lint hints
- spacing nits and missing braces
ok otto
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/stdlib/getopt.3 | 11 | ||||
| -rw-r--r-- | src/lib/libc/stdlib/getopt_long.3 | 10 | ||||
| -rw-r--r-- | src/lib/libc/stdlib/getsubopt.3 | 12 |
3 files changed, 16 insertions, 17 deletions
diff --git a/src/lib/libc/stdlib/getopt.3 b/src/lib/libc/stdlib/getopt.3 index 9de8af3dcf..f07f01dd7f 100644 --- a/src/lib/libc/stdlib/getopt.3 +++ b/src/lib/libc/stdlib/getopt.3 | |||
| @@ -25,7 +25,7 @@ | |||
| 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | .\" SUCH DAMAGE. | 26 | .\" SUCH DAMAGE. |
| 27 | .\" | 27 | .\" |
| 28 | .\" $OpenBSD: getopt.3,v 1.36 2005/07/26 13:38:41 jmc Exp $ | 28 | .\" $OpenBSD: getopt.3,v 1.37 2005/10/11 01:23:41 jaredy Exp $ |
| 29 | .\" | 29 | .\" |
| 30 | .Dd December 17, 2002 | 30 | .Dd December 17, 2002 |
| 31 | .Dt GETOPT 3 | 31 | .Dt GETOPT 3 |
| @@ -187,15 +187,12 @@ while ((ch = getopt(argc, argv, "bf:")) != -1) { | |||
| 187 | bflag = 1; | 187 | bflag = 1; |
| 188 | break; | 188 | break; |
| 189 | case 'f': | 189 | case 'f': |
| 190 | if ((fd = open(optarg, O_RDONLY, 0)) < 0) { | 190 | if ((fd = open(optarg, O_RDONLY, 0)) == -1) |
| 191 | (void)fprintf(stderr, | 191 | err(1, "%s", optarg); |
| 192 | "myname: %s: %s\en", optarg, strerror(errno)); | ||
| 193 | exit(1); | ||
| 194 | } | ||
| 195 | break; | 192 | break; |
| 196 | case '?': | ||
| 197 | default: | 193 | default: |
| 198 | usage(); | 194 | usage(); |
| 195 | /* NOTREACHED */ | ||
| 199 | } | 196 | } |
| 200 | } | 197 | } |
| 201 | argc -= optind; | 198 | argc -= optind; |
diff --git a/src/lib/libc/stdlib/getopt_long.3 b/src/lib/libc/stdlib/getopt_long.3 index 7899499cf7..bf5ba22ece 100644 --- a/src/lib/libc/stdlib/getopt_long.3 +++ b/src/lib/libc/stdlib/getopt_long.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: getopt_long.3,v 1.11 2005/07/26 04:17:44 jaredy Exp $ | 1 | .\" $OpenBSD: getopt_long.3,v 1.12 2005/10/11 01:23:41 jaredy Exp $ |
| 2 | .\" $NetBSD: getopt_long.3,v 1.11 2002/10/02 10:54:19 wiz Exp $ | 2 | .\" $NetBSD: getopt_long.3,v 1.11 2002/10/02 10:54:19 wiz Exp $ |
| 3 | .\" | 3 | .\" |
| 4 | .\" Copyright (c) 1988, 1991, 1993 | 4 | .\" Copyright (c) 1988, 1991, 1993 |
| @@ -223,14 +223,14 @@ while ((ch = getopt_long(argc, argv, "bf:", longopts, NULL)) != -1) | |||
| 223 | err(1, "unable to open %s", optarg); | 223 | err(1, "unable to open %s", optarg); |
| 224 | break; | 224 | break; |
| 225 | case 0: | 225 | case 0: |
| 226 | if (daggerset) { | 226 | if (daggerset) |
| 227 | fprintf(stderr,"Buffy will use her dagger to " | 227 | fprintf(stderr, "Buffy will use her dagger to " |
| 228 | "apply fluoride to dracula's teeth\en"); | 228 | "apply fluoride to dracula's teeth\en"); |
| 229 | } | ||
| 230 | break; | 229 | break; |
| 231 | default: | 230 | default: |
| 232 | usage(); | 231 | usage(); |
| 233 | } | 232 | /* NOTREACHED */ |
| 233 | } | ||
| 234 | argc -= optind; | 234 | argc -= optind; |
| 235 | argv += optind; | 235 | argv += optind; |
| 236 | .Ed | 236 | .Ed |
diff --git a/src/lib/libc/stdlib/getsubopt.3 b/src/lib/libc/stdlib/getsubopt.3 index d0308e2d50..6a7c28ff4d 100644 --- a/src/lib/libc/stdlib/getsubopt.3 +++ b/src/lib/libc/stdlib/getsubopt.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: getsubopt.3,v 1.10 2005/07/26 04:20:23 jaredy Exp $ | 1 | .\" $OpenBSD: getsubopt.3,v 1.11 2005/10/11 01:23:41 jaredy Exp $ |
| 2 | .\" | 2 | .\" |
| 3 | .\" Copyright (c) 1990, 1991, 1993 | 3 | .\" Copyright (c) 1990, 1991, 1993 |
| 4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
| @@ -104,15 +104,15 @@ char *tokens[] = { | |||
| 104 | extern char *optarg, *suboptarg; | 104 | extern char *optarg, *suboptarg; |
| 105 | char *options, *value; | 105 | char *options, *value; |
| 106 | 106 | ||
| 107 | while ((ch = getopt(argc, argv, "ab:")) != \-1) { | 107 | while ((ch = getopt(argc, argv, "ab:")) != -1) { |
| 108 | switch(ch) { | 108 | switch (ch) { |
| 109 | case 'a': | 109 | case 'a': |
| 110 | /* process ``a'' option */ | 110 | /* process ``a'' option */ |
| 111 | break; | 111 | break; |
| 112 | case 'b': | 112 | case 'b': |
| 113 | options = optarg; | 113 | options = optarg; |
| 114 | while (*options) { | 114 | while (*options) { |
| 115 | switch(getsubopt(&options, tokens, &value)) { | 115 | switch (getsubopt(&options, tokens, &value)) { |
| 116 | case ONE: | 116 | case ONE: |
| 117 | /* process ``one'' sub option */ | 117 | /* process ``one'' sub option */ |
| 118 | break; | 118 | break; |
| @@ -122,16 +122,18 @@ while ((ch = getopt(argc, argv, "ab:")) != \-1) { | |||
| 122 | error("no value for two"); | 122 | error("no value for two"); |
| 123 | i = atoi(value); | 123 | i = atoi(value); |
| 124 | break; | 124 | break; |
| 125 | case \-1: | 125 | case -1: |
| 126 | if (suboptarg) | 126 | if (suboptarg) |
| 127 | error("illegal sub option %s", | 127 | error("illegal sub option %s", |
| 128 | suboptarg); | 128 | suboptarg); |
| 129 | else | 129 | else |
| 130 | error("missing sub option"); | 130 | error("missing sub option"); |
| 131 | break; | 131 | break; |
| 132 | } | ||
| 132 | } | 133 | } |
| 133 | break; | 134 | break; |
| 134 | } | 135 | } |
| 136 | } | ||
| 135 | .Ed | 137 | .Ed |
| 136 | .Sh SEE ALSO | 138 | .Sh SEE ALSO |
| 137 | .Xr getopt 3 , | 139 | .Xr getopt 3 , |
