multiple definition of `optind'
Ben Lindstrom
mouring at etoh.eviladmin.org
Mon Jun 17 03:17:15 EST 2002
On Sun, 16 Jun 2002, Phil Howard wrote:
> Any ideas of the best way around this problem? Should I just hack the
> source code, or is there a magic switch somewhere I'm missing? I'm
> assuming I can't just dismiss that function as OpenSSH is probably
> based on the OpenBSD semantics.
>
No the issue is that your platform lacks a usable getopts with a optreset.
Plus you are trying to compile staticly.
Try the attach patch. Let me know if it fixes it. It was presented as
part of the Mint platform patches.
- Ben
-------------- next part --------------
diff -u -r openssh-3.2.3p1.orig/defines.h openssh-3.2.3p1/defines.h
--- openssh-3.2.3p1.orig/defines.h Thu Apr 25 19:56:06 2002
+++ openssh-3.2.3p1/defines.h Sun Jun 2 18:25:20 2002
@@ -417,7 +417,18 @@
#endif
#ifndef HAVE_GETOPT_OPTRESET
-#define getopt(ac, av, o) BSDgetopt(ac, av, o)
+# undef getopt
+# undef opterr
+# undef optind
+# undef optopt
+# undef optreset
+# undef optarg
+# define getopt(ac, av, o) BSDgetopt(ac, av, o)
+# define opterr BSDopterr
+# define optind BSDoptind
+# define optopt BSDoptopt
+# define optreset BSDoptreset
+# define optarg BSDoptarg
#endif
/* In older versions of libpam, pam_strerror takes a single argument */
diff -u -r openssh-3.2.3p1.orig/openbsd-compat/getopt.c openssh-3.2.3p1/openbsd-compat/getopt.c
--- openssh-3.2.3p1.orig/openbsd-compat/getopt.c Mon Sep 17 23:34:34 2001
+++ openssh-3.2.3p1/openbsd-compat/getopt.c Sun Jun 2 17:37:10 2002
@@ -42,11 +42,11 @@
#include <stdlib.h>
#include <string.h>
-int opterr = 1, /* if error message should be printed */
- optind = 1, /* index into parent argv vector */
- optopt, /* character checked for validity */
- optreset; /* reset getopt */
-char *optarg; /* argument associated with option */
+int BSDopterr = 1, /* if error message should be printed */
+ BSDoptind = 1, /* index into parent argv vector */
+ BSDoptopt, /* character checked for validity */
+ BSDoptreset; /* reset getopt */
+char *BSDoptarg; /* argument associated with option */
#define BADCH (int)'?'
#define BADARG (int)':'
@@ -66,57 +66,57 @@
static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
- if (optreset || !*place) { /* update scanning pointer */
- optreset = 0;
- if (optind >= nargc || *(place = nargv[optind]) != '-') {
+ if (BSDoptreset || !*place) { /* update scanning pointer */
+ BSDoptreset = 0;
+ if (BSDoptind >= nargc || *(place = nargv[BSDoptind]) != '-') {
place = EMSG;
return (-1);
}
if (place[1] && *++place == '-') { /* found "--" */
- ++optind;
+ ++BSDoptind;
place = EMSG;
return (-1);
}
} /* option letter okay? */
- if ((optopt = (int)*place++) == (int)':' ||
- !(oli = strchr(ostr, optopt))) {
+ if ((BSDoptopt = (int)*place++) == (int)':' ||
+ !(oli = strchr(ostr, BSDoptopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
- if (optopt == (int)'-')
+ if (BSDoptopt == (int)'-')
return (-1);
if (!*place)
- ++optind;
- if (opterr && *ostr != ':')
+ ++BSDoptind;
+ if (BSDopterr && *ostr != ':')
(void)fprintf(stderr,
- "%s: illegal option -- %c\n", __progname, optopt);
+ "%s: illegal option -- %c\n", __progname, BSDoptopt);
return (BADCH);
}
if (*++oli != ':') { /* don't need argument */
- optarg = NULL;
+ BSDoptarg = NULL;
if (!*place)
- ++optind;
+ ++BSDoptind;
}
else { /* need an argument */
if (*place) /* no white space */
- optarg = place;
- else if (nargc <= ++optind) { /* no arg */
+ BSDoptarg = place;
+ else if (nargc <= ++BSDoptind) { /* no arg */
place = EMSG;
if (*ostr == ':')
return (BADARG);
- if (opterr)
+ if (BSDopterr)
(void)fprintf(stderr,
"%s: option requires an argument -- %c\n",
- __progname, optopt);
+ __progname, BSDoptopt);
return (BADCH);
}
else /* white space */
- optarg = nargv[optind];
+ BSDoptarg = nargv[BSDoptind];
place = EMSG;
- ++optind;
+ ++BSDoptind;
}
- return (optopt); /* dump back option letter */
+ return (BSDoptopt); /* dump back option letter */
}
#endif /* !defined(HAVE_GETOPT) || !defined(HAVE_OPTRESET) */
More information about the openssh-unix-dev
mailing list