diff options
author | B. Watson <urchlay@slackware.uk> | 2024-12-23 04:29:07 -0500 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2024-12-23 04:29:07 -0500 |
commit | 1ca75efcaa18be049070220a40f921d7023c790e (patch) | |
tree | dc060a6cfa1cb577fc867e98c857cf46d8f3f336 /getopt.c | |
parent | 393c2d3eb63e3df852208eb217a2dc578d09a1dd (diff) | |
download | uxd-1ca75efcaa18be049070220a40f921d7023c790e.tar.gz |
rename optarg, optind to avoid possible link issues
Diffstat (limited to 'getopt.c')
-rw-r--r-- | getopt.c | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -47,9 +47,9 @@ static char *index (char *s, int c) { * get option letter from argument vector */ int opterr = 1, /* useless, never set or used */ - optind = 1, /* index into parent argv vector */ + my_optind = 1, /* index into parent argv vector */ optopt; /* character checked for validity */ -char *optarg; /* argument associated with option */ +char *my_optarg; /* argument associated with option */ #define tell(s) fprintf(stderr, "%s: %s", self, s); \ fputc(optopt,stderr);fputs(" (use -h for help)\n",stderr);return(BADCH); @@ -60,29 +60,29 @@ int my_getopt(int nargc, char **nargv, char *ostr) { char *oli; /* option letter list index */ if(!*place) { /* update scanning pointer */ - if(optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) return(EOF); + if(my_optind >= nargc || *(place = nargv[my_optind]) != '-' || !*++place) return(EOF); if (*place == '-') { /* found "--" */ - ++optind; + ++my_optind; return(EOF); } } /* option letter okay? */ if ((optopt = (int)*place++) == ARGCH || !(oli = index(ostr,optopt))) { - if(!*place) ++optind; + if(!*place) ++my_optind; tell("illegal option: -"); } if (*++oli != ARGCH) { /* don't need argument */ - optarg = NULL; - if (!*place) ++optind; + my_optarg = NULL; + if (!*place) ++my_optind; } else { /* need an argument */ - if (*place) optarg = place; /* no white space */ - else if (nargc <= ++optind) { /* no arg */ + if (*place) my_optarg = place; /* no white space */ + else if (nargc <= ++my_optind) { /* no arg */ place = EMSG; tell("option requires an argument: -"); } - else optarg = nargv[optind]; /* white space */ + else my_optarg = nargv[my_optind]; /* white space */ place = EMSG; - ++optind; + ++my_optind; } return(optopt); /* dump back option letter */ } |