diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-03-05 06:18:33 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-03-05 06:18:33 +0000 |
commit | d7839f55b4d4f73d4d40baafc792382b8cd0dace (patch) | |
tree | 9795065832e97f0a8142cf796c257bf31f711f03 /libc/unistd/getopt.c | |
parent | 2d858d53fdc3a40c52e83ce6c58f37ba485a1828 (diff) |
Patch from Jean-Yves Avenard to move the getopt globals to their
own file, since at least on SH, weak variables with initial values
(.data stuff) were not working. Moving these to their own file
seems to be a good way to handle it.
Diffstat (limited to 'libc/unistd/getopt.c')
-rw-r--r-- | libc/unistd/getopt.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/libc/unistd/getopt.c b/libc/unistd/getopt.c index a850d9bde..ec5c988f5 100644 --- a/libc/unistd/getopt.c +++ b/libc/unistd/getopt.c @@ -21,10 +21,10 @@ #include <stdio.h> #include <string.h> -int opterr __attribute__ ((__weak__)) = 1; /* error => print message */ -int optind __attribute__ ((__weak__)) = 1; /* next argv[] index */ -int optopt __attribute__ ((__weak__)) = 1; /* Set for unknown arguments */ -char *optarg __attribute__ ((__weak__)) = NULL; /* option parameter if any */ +extern int opterr; /* error => print message */ +extern int optind; /* next argv[] index */ +extern int optopt; /* Set for unknown arguments */ +extern char *optarg; /* option parameter if any */ static int Err(name, mess, c) /* returns '?' */ char *name; /* program name argv[0] */ @@ -54,7 +54,16 @@ int getopt (int argc, char *const *argv, const char *optstring) register char *cp; /* -> option in `optstring' */ optarg = NULL; - + + /* initialise getopt vars */ + if (optind == 0) + { + optind = 1; + opterr = 1; + optopt = 1; + optarg = NULL; + } + if (sp == 1) { /* fresh argument */ if (optind >= argc /* no more arguments */ || argv[optind][0] != '-' /* no more options */ |