summaryrefslogtreecommitdiff
path: root/libc/unistd/gnu_getopt.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-03-05 06:18:33 +0000
committerEric Andersen <andersen@codepoet.org>2001-03-05 06:18:33 +0000
commitd7839f55b4d4f73d4d40baafc792382b8cd0dace (patch)
tree9795065832e97f0a8142cf796c257bf31f711f03 /libc/unistd/gnu_getopt.c
parent2d858d53fdc3a40c52e83ce6c58f37ba485a1828 (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/gnu_getopt.c')
-rw-r--r--libc/unistd/gnu_getopt.c37
1 files changed, 5 insertions, 32 deletions
diff --git a/libc/unistd/gnu_getopt.c b/libc/unistd/gnu_getopt.c
index 05f97a09c..0b1c68b8f 100644
--- a/libc/unistd/gnu_getopt.c
+++ b/libc/unistd/gnu_getopt.c
@@ -52,28 +52,12 @@ extern int _getopt_internal (int argc, char *const *argv,
#ifdef L__gnu_getopt_internal
-/* For communication from `getopt' to the caller.
- When `getopt' finds an option that takes an argument,
- the argument value is returned here.
- Also, when `ordering' is RETURN_IN_ORDER,
- each non-option ARGV-element is returned here. */
+/* external getopt vars */
-char *optarg = NULL;
-
-/* Index in ARGV of the next element to be scanned.
- This is used for communication to and from the caller
- and for communication between successive calls to `getopt'.
-
- On entry to `getopt', zero means this is the first call; initialize.
-
- When `getopt' returns EOF, this is the index of the first of the
- non-option elements that the caller should itself scan.
-
- Otherwise, `optind' communicates from one call to the next
- how much of ARGV has been scanned so far. */
-
-/* XXX 1003.2 says this must be 1 before any call. */
-int optind = 0;
+extern int optind;
+extern int opterr;
+extern int optopt;
+extern char *optarg;
/* The next char to be scanned in the option-element
in which the last option character we returned was found.
@@ -84,17 +68,6 @@ int optind = 0;
static char *nextchar;
-/* Callers store zero here to inhibit the error message
- for unrecognized options. */
-
-int opterr = 1;
-
-/* Set to an option character which was unrecognized.
- This must be initialized on some systems to avoid linking in the
- system's own getopt implementation. */
-
-int optopt = '?';
-
/* Describe how to deal with options that follow non-option ARGV-elements.
If the caller did not specify anything,