aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Vanderhoek <hoek@FreeBSD.org>2000-01-06 01:25:15 +0000
committerTim Vanderhoek <hoek@FreeBSD.org>2000-01-06 01:25:15 +0000
commit838fb327f23ccfbe32850a3c5e6f736d7045c5dd (patch)
tree8389ddf037a861b6a6fd8c2d51ebfd4816539519
parentdac2aaa459d6f4a14ff87ece3a3dcfabbb452586 (diff)
Notes
-rw-r--r--lib/libc/stdlib/getopt.317
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/libc/stdlib/getopt.3 b/lib/libc/stdlib/getopt.3
index 51f7ffbaadd2..7017c4fdaeec 100644
--- a/lib/libc/stdlib/getopt.3
+++ b/lib/libc/stdlib/getopt.3
@@ -243,10 +243,10 @@ as an option.
This practice is wrong, and should not be used in any current development.
It is provided for backward compatibility
.Em only .
-The following code fragment works in most cases.
+The following code fragment works in most (but not all) cases.
.Bd -literal -offset indent
int length;
-char *p;
+char *p, *ep;
while ((ch = getopt(argc, argv, "0123456789")) != -1)
switch (ch) {
@@ -254,9 +254,16 @@ while ((ch = getopt(argc, argv, "0123456789")) != -1)
case '5': case '6': case '7': case '8': case '9':
p = argv[optind - 1];
if (p[0] == '-' && p[1] == ch && !p[2])
- length = atoi(++p);
- else
- length = atoi(argv[optind] + 1);
+ length = strtol(++p, &ep, 10);
+ else if (argv[optind] && argv[optind][1] == ch) {
+ length = strtol((p = argv[optind] + 1),
+ &ep, 10);
+ optind++;
+ optreset = 1;
+ } else
+ usage();
+ if (*ep != '\0')
+ errx(EX_USAGE, "illegal number -- %s", p);
break;
}
.Ed