From 1ca75efcaa18be049070220a40f921d7023c790e Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Mon, 23 Dec 2024 04:29:07 -0500 Subject: rename optarg, optind to avoid possible link issues --- getopt.c | 22 +++++++++++----------- uxd.c | 20 ++++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/getopt.c b/getopt.c index 0c0057e..8a23548 100644 --- a/getopt.c +++ b/getopt.c @@ -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 */ } diff --git a/uxd.c b/uxd.c index 7f518e0..b1adaef 100644 --- a/uxd.c +++ b/uxd.c @@ -35,8 +35,8 @@ on stderr. /* from getopt.c */ extern int my_getopt(int, char **, char *); -extern char *optarg; -extern int optind; +extern char *my_optarg; +extern int my_optind; #ifndef VERSION #define VERSION "(unknown version)" @@ -293,19 +293,19 @@ void parse_args(int argc, char **argv) { fprintf(stderr, "%s: multiple -d options not supported.\n", self); exit(1); } - dump_data_arg = optarg; break; + dump_data_arg = my_optarg; break; case '1': alternate_colors = 0; break; case 'i': print_info_opt = 1; break; case 'c': - mono = 0; parse_colors(optarg); break; + mono = 0; parse_colors(my_optarg); break; case 'n': break; /* already handled in parse_options() */ case 'b': bold = 1; break; case 'l': - limit = parse_number(opt, optarg); + limit = parse_number(opt, my_optarg); if(limit < 0) { fprintf(stderr, "%s: negative limit for -l not allowed.\n", self); exit(1); @@ -316,12 +316,12 @@ void parse_args(int argc, char **argv) { case 'm': mono = 1; break; case 'o': - display_offset = parse_number(opt, optarg); break; + display_offset = parse_number(opt, my_optarg); break; case 'S': seek_offset_zero = 1; /* fall thru */ case 's': - seekpos = parse_number(opt, optarg); + seekpos = parse_number(opt, my_optarg); break; case 'u': hex_byte_fmt = UC_BYTE_FMT; hex_addr_fmt = UC_ADDR_FMT; break; @@ -335,16 +335,16 @@ void parse_args(int argc, char **argv) { } if(dump_data_arg) { - if(optind != argc) { + if(my_optind != argc) { fprintf(stderr, "%s: cannot give a filename when -d is used.\n", self); exit(1); } } else { /* filename (if present) must come after all -options, and there can only be one filename. */ - if(optind < (argc - 1)) usage(); + if(my_optind < (argc - 1)) usage(); - open_input(argv[optind]); + open_input(argv[my_optind]); } } -- cgit v1.2.3