From d7839f55b4d4f73d4d40baafc792382b8cd0dace Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Mon, 5 Mar 2001 06:18:33 +0000 Subject: 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. --- libc/unistd/getopt.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'libc/unistd/getopt.c') 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 #include -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 */ -- cgit v1.2.3