getopt_long.c: initialize optarg and optreset to avoid symbol clashes.

this has been happening to me eg. with amiga clib2 like:
/opt/cross_amigaos4/ppc-amigaos/SDK/clib2/lib/libc.a(unistd_getopt.o)(.text+0x0): In function `getopt':
: multiple definition of `getopt'
getopt_long.o(.text+0xc1c):/work/xmp-cli/src/getopt_long.c:481: first defined here
/opt/cross_amigaos4/lib/gcc/ppc-amigaos/4.2.4/../../../../ppc-amigaos/bin/ld: Warning: size of symbol `getopt' changed from 16 in getopt_long.o to 672 in /opt/cross_amigaos4/ppc-amigaos/SDK/clib2/lib/libc.a(unistd_getopt.o)
/opt/cross_amigaos4/ppc-amigaos/SDK/clib2/lib/libc.a(unistd_getopt.o)(.sdata+0x4): multiple definition of `optind'
getopt_long.o(.sdata+0x4):/work/xmp-cli/src/getopt_long.c:133: first defined here
/opt/cross_amigaos4/ppc-amigaos/SDK/clib2/lib/libc.a(unistd_getopt.o)(.sbss+0x0): multiple definition of `optopt'
getopt_long.o(.sdata+0x8):/work/xmp-cli/src/getopt_long.c:126: first defined here
/opt/cross_amigaos4/ppc-amigaos/SDK/clib2/lib/libc.a(unistd_getopt.o)(.sdata+0x0): multiple definition of `opterr'
getopt_long.o(.sdata+0x0):/work/xmp-cli/src/getopt_long.c:126: first defined here
master
Ozkan Sezer 5 years ago
parent da8a4c5a56
commit adadca1d93
  1. 5
      src/getopt_long.c

@ -60,8 +60,9 @@
int opterr = 1; /* if error message should be printed */
int optind = 1; /* index into parent argv vector */
int optopt = '?'; /* character checked for validity */
int optreset; /* reset getopt */
char *optarg; /* argument associated with option */
/* initialize these two too to avoid symbol clashes from system libc: */
int optreset = 0; /* reset getopt */
char *optarg = NULL; /* argument associated with option */
#define PRINT_ERROR ((opterr) && (*options != ':'))

Loading…
Cancel
Save