aboutsummaryrefslogtreecommitdiff
path: root/missing
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-09-14 17:24:04 -0700
committerGuy Harris <guy@alum.mit.edu>2018-09-14 17:24:04 -0700
commit9c87d9d5f086597ba064b2b0ac4b89644065b9f5 (patch)
tree3eae9d96c0dbfd23b432fa51d8d1edaeb5108272 /missing
parentdfce68d037bad5f57341db488392553cd479eaab (diff)
Clean up the code a bit.
This eliminates a warning from MSVC, and makes the flow a little clearer. (Yes, it duplicates some code, but compilers have been pretty good at merging common code sequences, so it might just turn it into the equivalent of if (optopt == (int)':') goto label2; oli = strchr(ostr, optopt); if (!oli) { /* * if the user didn't specify '-' as an option, * assume it means -1. */ if (optopt == (int)'-') return (-1); label2: if (!*place) ++optind; if (opterr && *ostr != ':') (void)fprintf(stderr, "%s: illegal option -- %c\n", __progname, optopt); return (BADCH); } although it does mean that the same C code exists in two places.)
Diffstat (limited to 'missing')
-rw-r--r--missing/getopt.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/missing/getopt.c b/missing/getopt.c
index 7c897c6f..a3d50cb3 100644
--- a/missing/getopt.c
+++ b/missing/getopt.c
@@ -80,9 +80,18 @@ getopt(int nargc, char * const *nargv, const char *ostr)
place = EMSG;
return (-1);
}
- } /* option letter okay? */
- if ((optopt = (int)*place++) == (int)':' ||
- !(oli = strchr(ostr, optopt))) {
+ }
+ optopt = (int)*place++;
+ if (optopt == (int)':') { /* option letter okay? */
+ if (!*place)
+ ++optind;
+ if (opterr && *ostr != ':')
+ (void)fprintf(stderr,
+ "%s: illegal option -- %c\n", __progname, optopt);
+ return (BADCH);
+ }
+ oli = strchr(ostr, optopt);
+ if (!oli) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.