#include "getopt.h"
-char *optarg;
-int optind, opterr, optopt;
+char *optarg = NULL;
+int optind = 0, opterr = 0, optopt = 0;
+
static struct getopt_private_state {
const char *optptr;
const char *last_optstring;
const char *osptr;
int opt;
+ optarg = NULL;
+
/* getopt() relies on a number of different global state
variables, which can make this really confusing if there is
more than one use of getopt() in the same program. This
} else {
/* Argument-taking option with non-attached
argument */
- if (argv[optind + 1]) {
+ if (osptr[2] == ':') {
+ if (argv[optind + 1]) {
+ optarg = (char *)argv[optind+1];
+ optind += 2;
+ } else {
+ optarg = NULL;
+ optind++;
+ }
+ return opt;
+ } else if (argv[optind + 1]) {
optarg = (char *)argv[optind+1];
optind += 2;
} else {