diff options
author | Ben Lindstrom <mouring@eviladmin.org> | 2002-06-22 00:26:59 +0000 |
---|---|---|
committer | Ben Lindstrom <mouring@eviladmin.org> | 2002-06-22 00:26:59 +0000 |
commit | ee9ac35fc20294e2950f811f1998a72b1aa20254 (patch) | |
tree | 16f6d37494ff6ac8d60297fcfb1e88117bfb1cdf | |
parent | f102bf6e50325f9c94143569c4f0241de08424f8 (diff) |
- (bal) getopt now can be staticly compiled on those platforms missing
optreset. Patch by binder@arago.de
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | defines.h | 15 | ||||
-rw-r--r-- | openbsd-compat/getopt.c | 48 |
3 files changed, 40 insertions, 27 deletions
@@ -1,6 +1,8 @@ | |||
1 | 20020622 | 1 | 20020622 |
2 | - (djm) Update README.privsep; spotted by fries@ | 2 | - (djm) Update README.privsep; spotted by fries@ |
3 | - (djm) Release 3.3p1 | 3 | - (djm) Release 3.3p1 |
4 | - (bal) getopt now can be staticly compiled on those platforms missing | ||
5 | optreset. Patch by binder@arago.de | ||
4 | 6 | ||
5 | 20020621 | 7 | 20020621 |
6 | - (djm) Sync: | 8 | - (djm) Sync: |
@@ -1004,4 +1006,4 @@ | |||
1004 | - (stevesk) entropy.c: typo in debug message | 1006 | - (stevesk) entropy.c: typo in debug message |
1005 | - (djm) ssh-keygen -i needs seeded RNG; report from markus@ | 1007 | - (djm) ssh-keygen -i needs seeded RNG; report from markus@ |
1006 | 1008 | ||
1007 | $Id: ChangeLog,v 1.2240 2002/06/21 15:44:45 djm Exp $ | 1009 | $Id: ChangeLog,v 1.2241 2002/06/22 00:26:59 mouring Exp $ |
@@ -1,7 +1,7 @@ | |||
1 | #ifndef _DEFINES_H | 1 | #ifndef _DEFINES_H |
2 | #define _DEFINES_H | 2 | #define _DEFINES_H |
3 | 3 | ||
4 | /* $Id: defines.h,v 1.90 2002/06/07 03:19:36 mouring Exp $ */ | 4 | /* $Id: defines.h,v 1.91 2002/06/22 00:27:00 mouring Exp $ */ |
5 | 5 | ||
6 | 6 | ||
7 | /* Constants */ | 7 | /* Constants */ |
@@ -417,7 +417,18 @@ struct winsize { | |||
417 | #endif | 417 | #endif |
418 | 418 | ||
419 | #ifndef HAVE_GETOPT_OPTRESET | 419 | #ifndef HAVE_GETOPT_OPTRESET |
420 | #define getopt(ac, av, o) BSDgetopt(ac, av, o) | 420 | # undef getopt |
421 | # undef opterr | ||
422 | # undef optind | ||
423 | # undef optopt | ||
424 | # undef optreset | ||
425 | # undef optarg | ||
426 | # define getopt(ac, av, o) BSDgetopt(ac, av, o) | ||
427 | # define opterr BSDopterr | ||
428 | # define optind BSDoptind | ||
429 | # define optopt BSDoptopt | ||
430 | # define optreset BSDoptreset | ||
431 | # define optarg BSDoptarg | ||
421 | #endif | 432 | #endif |
422 | 433 | ||
423 | /* In older versions of libpam, pam_strerror takes a single argument */ | 434 | /* In older versions of libpam, pam_strerror takes a single argument */ |
diff --git a/openbsd-compat/getopt.c b/openbsd-compat/getopt.c index 9e13504a0..f4fbc9bac 100644 --- a/openbsd-compat/getopt.c +++ b/openbsd-compat/getopt.c | |||
@@ -42,11 +42,11 @@ static char *rcsid = "$OpenBSD: getopt.c,v 1.2 1996/08/19 08:33:32 tholo Exp $"; | |||
42 | #include <stdlib.h> | 42 | #include <stdlib.h> |
43 | #include <string.h> | 43 | #include <string.h> |
44 | 44 | ||
45 | int opterr = 1, /* if error message should be printed */ | 45 | int BSDopterr = 1, /* if error message should be printed */ |
46 | optind = 1, /* index into parent argv vector */ | 46 | BSDoptind = 1, /* index into parent argv vector */ |
47 | optopt, /* character checked for validity */ | 47 | BSDoptopt, /* character checked for validity */ |
48 | optreset; /* reset getopt */ | 48 | BSDoptreset; /* reset getopt */ |
49 | char *optarg; /* argument associated with option */ | 49 | char *BSDoptarg; /* argument associated with option */ |
50 | 50 | ||
51 | #define BADCH (int)'?' | 51 | #define BADCH (int)'?' |
52 | #define BADARG (int)':' | 52 | #define BADARG (int)':' |
@@ -66,57 +66,57 @@ BSDgetopt(nargc, nargv, ostr) | |||
66 | static char *place = EMSG; /* option letter processing */ | 66 | static char *place = EMSG; /* option letter processing */ |
67 | char *oli; /* option letter list index */ | 67 | char *oli; /* option letter list index */ |
68 | 68 | ||
69 | if (optreset || !*place) { /* update scanning pointer */ | 69 | if (BSDoptreset || !*place) { /* update scanning pointer */ |
70 | optreset = 0; | 70 | BSDoptreset = 0; |
71 | if (optind >= nargc || *(place = nargv[optind]) != '-') { | 71 | if (BSDoptind >= nargc || *(place = nargv[BSDoptind]) != '-') { |
72 | place = EMSG; | 72 | place = EMSG; |
73 | return (-1); | 73 | return (-1); |
74 | } | 74 | } |
75 | if (place[1] && *++place == '-') { /* found "--" */ | 75 | if (place[1] && *++place == '-') { /* found "--" */ |
76 | ++optind; | 76 | ++BSDoptind; |
77 | place = EMSG; | 77 | place = EMSG; |
78 | return (-1); | 78 | return (-1); |
79 | } | 79 | } |
80 | } /* option letter okay? */ | 80 | } /* option letter okay? */ |
81 | if ((optopt = (int)*place++) == (int)':' || | 81 | if ((BSDoptopt = (int)*place++) == (int)':' || |
82 | !(oli = strchr(ostr, optopt))) { | 82 | !(oli = strchr(ostr, BSDoptopt))) { |
83 | /* | 83 | /* |
84 | * if the user didn't specify '-' as an option, | 84 | * if the user didn't specify '-' as an option, |
85 | * assume it means -1. | 85 | * assume it means -1. |
86 | */ | 86 | */ |
87 | if (optopt == (int)'-') | 87 | if (BSDoptopt == (int)'-') |
88 | return (-1); | 88 | return (-1); |
89 | if (!*place) | 89 | if (!*place) |
90 | ++optind; | 90 | ++BSDoptind; |
91 | if (opterr && *ostr != ':') | 91 | if (BSDopterr && *ostr != ':') |
92 | (void)fprintf(stderr, | 92 | (void)fprintf(stderr, |
93 | "%s: illegal option -- %c\n", __progname, optopt); | 93 | "%s: illegal option -- %c\n", __progname, BSDoptopt); |
94 | return (BADCH); | 94 | return (BADCH); |
95 | } | 95 | } |
96 | if (*++oli != ':') { /* don't need argument */ | 96 | if (*++oli != ':') { /* don't need argument */ |
97 | optarg = NULL; | 97 | BSDoptarg = NULL; |
98 | if (!*place) | 98 | if (!*place) |
99 | ++optind; | 99 | ++BSDoptind; |
100 | } | 100 | } |
101 | else { /* need an argument */ | 101 | else { /* need an argument */ |
102 | if (*place) /* no white space */ | 102 | if (*place) /* no white space */ |
103 | optarg = place; | 103 | BSDoptarg = place; |
104 | else if (nargc <= ++optind) { /* no arg */ | 104 | else if (nargc <= ++BSDoptind) { /* no arg */ |
105 | place = EMSG; | 105 | place = EMSG; |
106 | if (*ostr == ':') | 106 | if (*ostr == ':') |
107 | return (BADARG); | 107 | return (BADARG); |
108 | if (opterr) | 108 | if (BSDopterr) |
109 | (void)fprintf(stderr, | 109 | (void)fprintf(stderr, |
110 | "%s: option requires an argument -- %c\n", | 110 | "%s: option requires an argument -- %c\n", |
111 | __progname, optopt); | 111 | __progname, BSDoptopt); |
112 | return (BADCH); | 112 | return (BADCH); |
113 | } | 113 | } |
114 | else /* white space */ | 114 | else /* white space */ |
115 | optarg = nargv[optind]; | 115 | BSDoptarg = nargv[BSDoptind]; |
116 | place = EMSG; | 116 | place = EMSG; |
117 | ++optind; | 117 | ++BSDoptind; |
118 | } | 118 | } |
119 | return (optopt); /* dump back option letter */ | 119 | return (BSDoptopt); /* dump back option letter */ |
120 | } | 120 | } |
121 | 121 | ||
122 | #endif /* !defined(HAVE_GETOPT) || !defined(HAVE_OPTRESET) */ | 122 | #endif /* !defined(HAVE_GETOPT) || !defined(HAVE_OPTRESET) */ |