From: Matt Rogers Date: Wed, 24 Feb 2016 21:06:53 +0000 (-0500) Subject: Move the util/windows getopt to libkrb5support X-Git-Tag: krb5-1.15-beta1~228 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f9ade8ec50cde1176411085294f85ecfb2820a4;p=thirdparty%2Fkrb5.git Move the util/windows getopt to libkrb5support Relocate the internal getopt() and getopt_long() code to util/support, and build conditionally. Put declarations in k5-platform.h. Adjust Windows build directives for src/clients. Remove getopt-related #defines from kinit.c, allowing kinit to use getopt_long() on all platforms. [ghudson@mit.edu: fix some Windows build issues] ticket: 8391 --- diff --git a/src/Makefile.in b/src/Makefile.in index 6c5e93989f..8b9e790f01 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -511,7 +511,6 @@ install-windows:: copy windows\kfwlogon\$(OUTPRE)*.exe "$(KRB_INSTALL_DIR)\bin\." copy windows\kfwlogon\$(OUTPRE)*.dll "$(KRB_INSTALL_DIR)\bin\." $(INSTALLDBGSYMS) windows\kfwlogon\$(OUTPRE)*.pdb "$(KRB_INSTALL_DIR)\bin\." - copy util\windows\$(OUTPRE)*.lib $(KRB_INSTALL_DIR)\lib\." copy util\wshelper\$(OUTPRE)$(DLIB).lib "$(KRB_INSTALL_DIR)\lib\." copy util\wshelper\$(OUTPRE)$(DLIB).dll "$(KRB_INSTALL_DIR)\bin\." $(INSTALLDBGSYMS) util\wshelper\$(OUTPRE)$(DLIB).pdb "$(KRB_INSTALL_DIR)\bin\." @@ -635,11 +634,10 @@ BSDFILES = \ lib/krb5/krb/strftime.c \ lib/krb5/krb/strptime.c \ slave/kpropd_rpc.c \ + util/support/getopt.c \ + util/support/getopt_long.c \ util/support/mkstemp.c \ - util/support/strlcpy.c \ - util/windows/getopt.c \ - util/windows/getopt.h \ - util/windows/getopt_long.c + util/support/strlcpy.c OTHEREXCLUDES = \ include/iprop.h \ diff --git a/src/clients/kcpytkt/Makefile.in b/src/clients/kcpytkt/Makefile.in index ea73514993..8b702010a9 100644 --- a/src/clients/kcpytkt/Makefile.in +++ b/src/clients/kcpytkt/Makefile.in @@ -18,7 +18,7 @@ all-mac:: kcpytkt: kcpytkt.o $(KRB5_BASE_DEPLIBS) $(CC_LINK) -o $@ kcpytkt.o $(KRB5_BASE_LIBS) -##WIN32##$(KCPYTKT): $(OUTPRE)kcpytkt.obj $(BUILDTOP)\util\windows\$(OUTPRE)getopt.obj $(KLIB) $(CLIB) $(EXERES) +##WIN32##$(KCPYTKT): $(OUTPRE)kcpytkt.obj $(SLIB) $(KLIB) $(CLIB) $(EXERES) ##WIN32## link $(EXE_LINKOPTS) /out:$@ $** ##WIN32## $(_VC_MANIFEST_EMBED_EXE) diff --git a/src/clients/kcpytkt/kcpytkt.c b/src/clients/kcpytkt/kcpytkt.c index 90b260be1e..47147cdc32 100644 --- a/src/clients/kcpytkt/kcpytkt.c +++ b/src/clients/kcpytkt/kcpytkt.c @@ -2,14 +2,9 @@ #include #include -#ifdef HAVE_UNISTD_H -#include -#endif #include #include - -extern int optind; -extern char *optarg; +#include "k5-platform.h" static char *prog; diff --git a/src/clients/kdeltkt/Makefile.in b/src/clients/kdeltkt/Makefile.in index e140b7b41a..529592a9be 100644 --- a/src/clients/kdeltkt/Makefile.in +++ b/src/clients/kdeltkt/Makefile.in @@ -18,7 +18,7 @@ all-mac:: kdeltkt: kdeltkt.o $(KRB5_BASE_DEPLIBS) $(CC_LINK) -o $@ kdeltkt.o $(KRB5_BASE_LIBS) -##WIN32##$(KDELTKT): $(OUTPRE)kdeltkt.obj $(BUILDTOP)\util\windows\$(OUTPRE)getopt.obj $(KLIB) $(CLIB) $(EXERES) +##WIN32##$(KDELTKT): $(OUTPRE)kdeltkt.obj $(SLIB) $(KLIB) $(CLIB) $(EXERES) ##WIN32## link $(EXE_LINKOPTS) /out:$@ $** ##WIN32## $(_VC_MANIFEST_EMBED_EXE) diff --git a/src/clients/kdeltkt/kdeltkt.c b/src/clients/kdeltkt/kdeltkt.c index 2f09c9dc1e..9c7a549f97 100644 --- a/src/clients/kdeltkt/kdeltkt.c +++ b/src/clients/kdeltkt/kdeltkt.c @@ -2,14 +2,9 @@ #include #include -#ifdef HAVE_UNISTD_H -#include -#endif #include #include - -extern int optind; -extern char *optarg; +#include "k5-platform.h" static char *prog; diff --git a/src/clients/kdestroy/Makefile.in b/src/clients/kdestroy/Makefile.in index f29935277a..05f0a44ce9 100644 --- a/src/clients/kdestroy/Makefile.in +++ b/src/clients/kdestroy/Makefile.in @@ -21,7 +21,7 @@ all-unix:: kdestroy kdestroy: kdestroy.o $(KRB5_BASE_DEPLIBS) $(CC_LINK) -o $@ kdestroy.o $(KRB5_BASE_LIBS) -##WIN32##$(KDESTROY): $(OUTPRE)kdestroy.obj $(BUILDTOP)\util\windows\$(OUTPRE)getopt.obj $(KLIB) $(CLIB) $(EXERES) +##WIN32##$(KDESTROY): $(OUTPRE)kdestroy.obj $(SLIB) $(KLIB) $(CLIB) $(EXERES) ##WIN32## link $(EXE_LINKOPTS) -out:$@ $** ##WIN32## $(_VC_MANIFEST_EMBED_EXE) diff --git a/src/clients/kdestroy/kdestroy.c b/src/clients/kdestroy/kdestroy.c index 299838ff55..410d6cf4cb 100644 --- a/src/clients/kdestroy/kdestroy.c +++ b/src/clients/kdestroy/kdestroy.c @@ -30,12 +30,6 @@ #include #include #include -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef _WIN32 -#include -#endif #ifdef __STDC__ #define BELL_CHAR '\a' diff --git a/src/clients/kinit/Makefile.in b/src/clients/kinit/Makefile.in index b1cd278a53..c7975c9883 100644 --- a/src/clients/kinit/Makefile.in +++ b/src/clients/kinit/Makefile.in @@ -2,9 +2,7 @@ mydir=clients$(S)kinit BUILDTOP=$(REL)..$(S).. SRCS=kinit.c kinit_kdb.c - -##WIN32##LOCALINCLUDES=-I$(BUILDTOP)\util\windows -##WIN32##DEFINES=-DGETOPT_LONG +##WIN32##LOCALINCLUDES=-I$(BUILDTOP)\util\windows -I$(BUILDTOP)\util\support ##WIN32##VERSIONRC = $(BUILDTOP)\windows\version.rc ##WIN32##RCFLAGS=$(CPPFLAGS) -I$(top_srcdir) -D_WIN32 -DRES_ONLY @@ -22,7 +20,7 @@ all-unix:: kinit kinit: kinit.o kinit_kdb.o $(KRB5_BASE_DEPLIBS) $(KADMSRV_DEPLIBS) $(CC_LINK) -o $@ kinit.o kinit_kdb.o $(KADMSRV_LIBS) $(KRB5_BASE_LIBS) -##WIN32##$(KINIT): $(OUTPRE)kinit.obj $(BUILDTOP)\util\windows\$(OUTPRE)getopt.lib $(KLIB) $(CLIB) $(EXERES) +##WIN32##$(KINIT): $(OUTPRE)kinit.obj $(SLIB) $(KLIB) $(CLIB) $(EXERES) ##WIN32## link $(EXE_LINKOPTS) -out:$@ $** advapi32.lib ##WIN32## $(_VC_MANIFEST_EMBED_EXE) diff --git a/src/clients/kinit/kinit.c b/src/clients/kinit/kinit.c index c442c5371b..3653960b2d 100644 --- a/src/clients/kinit/kinit.c +++ b/src/clients/kinit/kinit.c @@ -26,7 +26,7 @@ #include "autoconf.h" #include -#include "k5-platform.h" /* for asprintf */ +#include "k5-platform.h" /* for asprintf and getopt */ #include #include "extern.h" #include @@ -36,23 +36,6 @@ #include #include -#ifdef GETOPT_LONG -#include -#else -#ifdef HAVE_UNISTD_H -#include -#ifdef sun -/* SunOS4 unistd didn't declare these; okay to make unconditional? */ -extern int optind; -extern char *optarg; -#endif /* sun */ -#else -extern int optind; -extern char *optarg; -extern int getopt(); -#endif /* HAVE_UNISTD_H */ -#endif /* GETOPT_LONG */ - #ifndef _WIN32 #define GET_PROGNAME(x) (strrchr((x), '/') ? strrchr((x), '/')+1 : (x)) #else @@ -140,7 +123,6 @@ struct k5_data krb5_boolean switch_to_cache; }; -#ifdef GETOPT_LONG /* if struct[2] == NULL, then long_getopt acts as if the short flag struct[3] was specified. If struct[2] != NULL, then struct[3] is stored in *(struct[2]), the array index which was specified is @@ -158,31 +140,19 @@ struct option long_options[] = { { NULL, 0, NULL, 0 } }; -#define GETOPT(argc, argv, str) getopt_long(argc, argv, str, long_options, 0) -#else -#define GETOPT(argc, argv, str) getopt(argc, argv, str) -#endif +const char *shopts = "r:fpFPn54aAVl:s:c:kit:T:RS:vX:CEI:"; static void usage() { #define USAGE_BREAK "\n\t" -#ifdef GETOPT_LONG #define USAGE_LONG_FORWARDABLE " | --forwardable | --noforwardable" #define USAGE_LONG_PROXIABLE " | --proxiable | --noproxiable" #define USAGE_LONG_ADDRESSES " | --addresses | --noaddresses" #define USAGE_LONG_CANONICALIZE " | --canonicalize" #define USAGE_LONG_ENTERPRISE " | --enterprise" #define USAGE_BREAK_LONG USAGE_BREAK -#else -#define USAGE_LONG_FORWARDABLE "" -#define USAGE_LONG_PROXIABLE "" -#define USAGE_LONG_ADDRESSES "" -#define USAGE_LONG_CANONICALIZE "" -#define USAGE_LONG_ENTERPRISE "" -#define USAGE_BREAK_LONG "" -#endif fprintf(stderr, "Usage: %s [-V] " "[-l lifetime] [-s start_time] " @@ -288,8 +258,7 @@ parse_options(argc, argv, opts) int errflg = 0; int i; - while ((i = GETOPT(argc, argv, - "r:fpFPn54aAVl:s:c:kit:T:RS:vX:CEI:")) != -1) { + while ((i = getopt_long(argc, argv, shopts, long_options, 0)) != -1) { switch (i) { case 'V': opts->verbose = 1; diff --git a/src/clients/klist/Makefile.in b/src/clients/klist/Makefile.in index 3cdbb86ddf..79255f234d 100644 --- a/src/clients/klist/Makefile.in +++ b/src/clients/klist/Makefile.in @@ -21,7 +21,7 @@ all-unix:: klist klist: klist.o $(KRB5_BASE_DEPLIBS) $(CC_LINK) -o $@ klist.o $(KRB5_BASE_LIBS) -##WIN32##$(KLIST): $(OUTPRE)klist.obj $(BUILDTOP)\util\windows\$(OUTPRE)getopt.lib $(SLIB) $(KLIB) $(CLIB) $(EXERES) +##WIN32##$(KLIST): $(OUTPRE)klist.obj $(SLIB) $(KLIB) $(CLIB) $(EXERES) ##WIN32## link $(EXE_LINKOPTS) -out:$@ $** ws2_32.lib $(SCLIB) ##WIN32## $(_VC_MANIFEST_EMBED_EXE) diff --git a/src/clients/klist/klist.c b/src/clients/klist/klist.c index 0f6ca8a9b4..f8183dd10e 100644 --- a/src/clients/klist/klist.c +++ b/src/clients/klist/klist.c @@ -29,12 +29,6 @@ #include #include #include -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef _WIN32 -#include -#endif #include #include #include diff --git a/src/clients/kswitch/Makefile.in b/src/clients/kswitch/Makefile.in index b46fec6224..e2a58dc891 100644 --- a/src/clients/kswitch/Makefile.in +++ b/src/clients/kswitch/Makefile.in @@ -19,7 +19,7 @@ all-unix:: kswitch kswitch: kswitch.o $(KRB5_BASE_DEPLIBS) $(CC_LINK) -o $@ kswitch.o $(KRB5_BASE_LIBS) -##WIN32##$(KSWITCH): $(OUTPRE)kswitch.obj $(BUILDTOP)\util\windows\$(OUTPRE)getopt.obj $(KLIB) $(CLIB) $(EXERES) +##WIN32##$(KSWITCH): $(OUTPRE)kswitch.obj $(SLIB) $(KLIB) $(CLIB) $(EXERES) ##WIN32## link $(EXE_LINKOPTS) -out:$@ $** ##WIN32## $(_VC_MANIFEST_EMBED_EXE) diff --git a/src/clients/kvno/Makefile.in b/src/clients/kvno/Makefile.in index 58519ae36e..649508068b 100644 --- a/src/clients/kvno/Makefile.in +++ b/src/clients/kvno/Makefile.in @@ -22,7 +22,7 @@ all-unix:: kvno kvno: kvno.o $(KRB5_BASE_DEPLIBS) $(CC_LINK) -o $@ kvno.o $(KRB5_BASE_LIBS) -##WIN32##$(KVNO): $(OUTPRE)kvno.obj $(BUILDTOP)\util\windows\$(OUTPRE)getopt.obj $(KLIB) $(CLIB) $(EXERES) +##WIN32##$(KVNO): $(OUTPRE)kvno.obj $(SLIB) $(KLIB) $(CLIB) $(EXERES) ##WIN32## link $(EXE_LINKOPTS) /out:$@ $** ##WIN32## $(_VC_MANIFEST_EMBED_EXE) diff --git a/src/clients/kvno/kvno.c b/src/clients/kvno/kvno.c index 377d4f3451..80bee59e23 100644 --- a/src/clients/kvno/kvno.c +++ b/src/clients/kvno/kvno.c @@ -30,10 +30,6 @@ #ifdef HAVE_UNISTD_H #include #endif -#ifdef _WIN32 -#include -#endif - #include extern int optind; diff --git a/src/configure.in b/src/configure.in index 605b0c0417..8216045a1f 100644 --- a/src/configure.in +++ b/src/configure.in @@ -145,6 +145,26 @@ EXTRA_SUPPORT_SYMS="$EXTRA_SUPPORT_SYMS krb5int_strlcpy krb5int_strlcat"]) AC_SUBST(STRLCPY_OBJ) AC_SUBST(STRLCPY_ST_OBJ) +AC_CHECK_FUNC(getopt, +[GETOPT_ST_OBJ= +GETOPT_OBJ= +AC_DEFINE(HAVE_GETOPT, 1, [Define if system getopt should be used.])], +[GETOPT_ST_OBJ='getopt.o' +GETOPT_OBJ='$(OUTPRE)getopt.$(OBJEXT)' +EXTRA_SUPPORT_SYMS="$EXTRA_SUPPORT_SYMS k5_optind k5_optarg k5_opterr k5_optopt k5_getopt"]) +AC_SUBST(GETOPT_OBJ) +AC_SUBST(GETOPT_ST_OBJ) + +AC_CHECK_FUNC(getopt_long, +[GETOPT_LONG_ST_OBJ= +GETOPT_LONG_OBJ= +AC_DEFINE(HAVE_GETOPT_LONG, 1, [Define if system getopt_long should be used.])], +[GETOPT_LONG_ST_OBJ='getopt_long.o' +GETOPT_LONG_OBJ='$(OUTPRE)getopt_long.$(OBJEXT)' +EXTRA_SUPPORT_SYMS="$EXTRA_SUPPORT_SYMS k5_getopt_long"]) +AC_SUBST(GETOPT_LONG_OBJ) +AC_SUBST(GETOPT_LONG_ST_OBJ) + AC_CHECK_FUNC(fnmatch, [FNMATCH_ST_OBJ= FNMATCH_OBJ=], diff --git a/src/include/k5-platform.h b/src/include/k5-platform.h index cff7dc32b8..994f46323c 100644 --- a/src/include/k5-platform.h +++ b/src/include/k5-platform.h @@ -63,6 +63,10 @@ #include #endif +#ifdef HAVE_UNISTD_H +#include +#endif + #ifdef _WIN32 #define CAN_COPY_VA_LIST #endif @@ -1060,4 +1064,39 @@ int k5_path_isabs(const char *path); #endif #define N_(s) s +#if !defined(HAVE_GETOPT) || !defined(HAVE_UNISTD_H) +extern int k5_opterr; +extern int k5_optind; +extern int k5_optopt; +extern char *k5_optarg; +#define opterr k5_opterr +#define optind k5_optind +#define optopt k5_optopt +#define optarg k5_optarg + +extern int k5_getopt(int nargc, char * const nargv[], const char *ostr); +#define getopt k5_getopt +#endif /* HAVE_GETOPT */ + +#ifdef HAVE_GETOPT_LONG +#include +#else + +struct option +{ + const char *name; + int has_arg; + int *flag; + int val; +}; + +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +extern int k5_getopt_long(int nargc, char **nargv, char *options, + struct option *long_options, int *index); +#define getopt_long k5_getopt_long +#endif /* HAVE_GETOPT_LONG */ + #endif /* K5_PLATFORM_H */ diff --git a/src/util/support/Makefile.in b/src/util/support/Makefile.in index 5d38b0326b..d5da898f79 100644 --- a/src/util/support/Makefile.in +++ b/src/util/support/Makefile.in @@ -43,6 +43,16 @@ PRINTF_OBJ= @PRINTF_OBJ@ ##DOS##PRINTF_ST_OBJ= printf.o ##DOS##PRINTF_OBJ= $(OUTPRE)printf.$(OBJEXT) +GETOPT_ST_OBJ= @GETOPT_ST_OBJ@ +GETOPT_OBJ= @GETOPT_OBJ@ +##DOS##GETOPT_ST_OBJ= getopt.o +##DOS##GETOPT_OBJ= $(OUTPRE)getopt.$(OBJEXT) + +GETOPT_LONG_ST_OBJ= @GETOPT_LONG_ST_OBJ@ +GETOPT_LONG_OBJ= @GETOPT_LONG_OBJ@ +##DOS##GETOPT_LONG_ST_OBJ= getopt_long.o +##DOS##GETOPT_LONG_OBJ= $(OUTPRE)getopt_long.$(OBJEXT) + IPC_ST_OBJ= IPC_OBJ= ##DOS##IPC_ST_OBJ= ipc_stream.o @@ -78,7 +88,9 @@ STLIBOBJS= \ $(STRLCPY_ST_OBJ) \ $(FNMATCH_ST_OBJ) \ $(PRINTF_ST_OBJ) \ - $(MKSTEMP_ST_OBJ) + $(MKSTEMP_ST_OBJ) \ + $(GETOPT_ST_OBJ) \ + $(GETOPT_LONG_ST_OBJ) LIBOBJS= \ $(OUTPRE)threads.$(OBJEXT) \ @@ -101,7 +113,9 @@ LIBOBJS= \ $(STRLCPY_OBJ) \ $(FNMATCH_OBJ) \ $(PRINTF_OBJ) \ - $(MKSTEMP_OBJ) + $(MKSTEMP_OBJ) \ + $(GETOPT_OBJ) \ + $(GETOPT_LONG_OBJ) SRCS=\ $(srcdir)/threads.c \ @@ -128,7 +142,9 @@ SRCS=\ $(srcdir)/json.c \ $(srcdir)/bcmp.c \ $(srcdir)/strerror_r.c \ - $(srcdir)/t_utf8.c + $(srcdir)/t_utf8.c \ + $(srcdir)/getopt.c \ + $(srcdir)/getopt_long.c SHLIB_EXPDEPS = # Add -lm if dumping thread stats, for sqrt. @@ -156,6 +172,7 @@ SHLIB_EXPORT_FILE=libkrb5support.exports EXTRA_SUPPORT_SYMS= @EXTRA_SUPPORT_SYMS@ ##DOS##EXTRA_SUPPORT_SYMS= krb5int_mkstemp krb5int_strlcpy krb5int_strlcat \ +##DOS## k5_optind k5_optarg k5_opterr k5_optopt k5_getopt k5_getopt_long \ ##DOS## krb5int_vasprintf krb5int_asprintf krb5int_gettimeofday $(IPC_SYMS) ##DOS##!if 0 diff --git a/src/util/support/deps b/src/util/support/deps index b27c97daf0..4dff014f46 100644 --- a/src/util/support/deps +++ b/src/util/support/deps @@ -84,3 +84,9 @@ strerror_r.so strerror_r.po $(OUTPRE)strerror_r.$(OBJEXT): \ t_utf8.so t_utf8.po $(OUTPRE)t_utf8.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \ $(top_srcdir)/include/k5-platform.h $(top_srcdir)/include/k5-thread.h \ $(top_srcdir)/include/k5-utf8.h t_utf8.c +getopt.so getopt.po $(OUTPRE)getopt.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \ + $(top_srcdir)/include/k5-platform.h $(top_srcdir)/include/k5-thread.h \ + getopt.c +getopt_long.so getopt_long.po $(OUTPRE)getopt_long.$(OBJEXT): \ + $(BUILDTOP)/include/autoconf.h $(top_srcdir)/include/k5-platform.h \ + $(top_srcdir)/include/k5-thread.h getopt_long.c diff --git a/src/util/windows/getopt.c b/src/util/support/getopt.c similarity index 94% rename from src/util/windows/getopt.c rename to src/util/support/getopt.c index 4f9f0627ef..44cda68de5 100644 --- a/src/util/windows/getopt.c +++ b/src/util/support/getopt.c @@ -34,6 +34,7 @@ * SUCH DAMAGE. */ +#if !defined(HAVE_GETOPT) || !defined(HAVE_UNISTD_H) #if 0 static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95"; #endif @@ -42,19 +43,14 @@ static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95"; #include #include #include +#include "k5-platform.h" #define __P(x) x #define _DIAGASSERT(x) assert(x) -#ifdef __weak_alias -__weak_alias(getopt,_getopt); -#endif - - int opterr = 1, /* if error message should be printed */ optind = 1, /* index into parent argv vector */ - optopt, /* character checked for validity */ - optreset; /* reset getopt */ + optopt; /* character checked for validity */ char *optarg; /* argument associated with option */ static char * _progname __P((char *)); @@ -98,8 +94,7 @@ getopt(nargc, nargv, ostr) _DIAGASSERT(nargv != NULL); _DIAGASSERT(ostr != NULL); - if (optreset || !*place) { /* update scanning pointer */ - optreset = 0; + if (!*place) { /* update scanning pointer */ if (optind >= nargc || *(place = nargv[optind]) != '-') { place = EMSG; return (-1); @@ -151,3 +146,4 @@ getopt(nargc, nargv, ostr) } return (optopt); /* dump back option letter */ } +#endif /* !defined(HAVE_GETOPT) || !defined(HAVE_UNISTD_H) */ diff --git a/src/util/windows/getopt_long.c b/src/util/support/getopt_long.c similarity index 94% rename from src/util/windows/getopt_long.c rename to src/util/support/getopt_long.c index 5002804c39..1b508a1495 100644 --- a/src/util/windows/getopt_long.c +++ b/src/util/support/getopt_long.c @@ -31,18 +31,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ +#ifndef HAVE_GETOPT_LONG #include #include #include #include #include -#include "getopt.h" - -extern int opterr; /* if error message should be printed */ -extern int optind; /* index into parent argv vector */ -extern int optopt; /* character checked for validity */ -extern int optreset; /* reset getopt */ -extern char *optarg; /* argument associated with option */ +#include "k5-platform.h" #define __P(x) x #define _DIAGASSERT(x) assert(x) @@ -86,8 +81,7 @@ getopt_internal(nargc, nargv, ostr) _DIAGASSERT(nargv != NULL); _DIAGASSERT(ostr != NULL); - if (optreset || !*place) { /* update scanning pointer */ - optreset = 0; + if (!*place) { /* update scanning pointer */ if (optind >= nargc || *(place = nargv[optind]) != '-') { place = EMSG; return (-1); @@ -235,3 +229,4 @@ getopt_long(nargc, nargv, options, long_options, index) } return(retval); } +#endif /* not HAVE_GETOPT_LONG */ diff --git a/src/util/windows/Makefile.in b/src/util/windows/Makefile.in index f857c46679..65b323c5fd 100644 --- a/src/util/windows/Makefile.in +++ b/src/util/windows/Makefile.in @@ -1,15 +1,11 @@ BUILDTOP = ..\.. -all-windows:: $(OUTPRE)libecho.exe $(OUTPRE)getopt.lib +all-windows:: $(OUTPRE)libecho.exe $(OUTPRE)libecho.exe: $(OUTPRE)libecho.obj link -out:$@ $** $(SCLIB) $(_VC_MANIFEST_EMBED_EXE) - -$(OUTPRE)getopt.lib: $(OUTPRE)getopt.obj $(OUTPRE)getopt_long.obj - lib -out:$@ $** - install-windows:: clean-windows:: diff --git a/src/util/windows/getopt.h b/src/util/windows/getopt.h deleted file mode 100644 index 8832dbc00b..0000000000 --- a/src/util/windows/getopt.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -*- mode: c; c-file-style: "bsd"; indent-tabs-mode: t -*- */ -#ifndef __GETOPT_H__ -#define __GETOPT_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -extern int opterr; /* if error message should be printed */ -extern int optind; /* index into parent argv vector */ -extern int optopt; /* character checked for validity */ -extern int optreset; /* reset getopt */ -extern char *optarg; /* argument associated with option */ - -struct option -{ - const char *name; - int has_arg; - int *flag; - int val; -}; - -#define no_argument 0 -#define required_argument 1 -#define optional_argument 2 - -int getopt(int, char**, char*); -int getopt_long(int, char**, char*, struct option*, int*); - -#ifdef __cplusplus -} -#endif - -#endif /* __GETOPT_H__ */ diff --git a/src/windows/installer/wix/files.wxi b/src/windows/installer/wix/files.wxi index ee1825199f..9194caf7bb 100644 --- a/src/windows/installer/wix/files.wxi +++ b/src/windows/installer/wix/files.wxi @@ -418,7 +418,6 @@ - @@ -432,7 +431,6 @@ - diff --git a/src/windows/ms2mit/Makefile.in b/src/windows/ms2mit/Makefile.in index 59d5e7f21b..9af69ce28f 100644 --- a/src/windows/ms2mit/Makefile.in +++ b/src/windows/ms2mit/Makefile.in @@ -24,11 +24,11 @@ $(MIT2MSRES): $(VERSIONRC) all-windows:: $(MS2MIT) $(MIT2MS) $(MS2MIT): $(OUTPRE)ms2mit.obj $(MS2MITRES) - link $(EXE_LINKOPTS) -out:$@ $(OUTPRE)ms2mit.obj $(BUILDTOP)\util\windows\$(OUTPRE)getopt.obj user32.lib advapi32.lib $(KLIB) $(CLIB) $(MS2MITRES) + link $(EXE_LINKOPTS) -out:$@ $(OUTPRE)ms2mit.obj $(SLIB) user32.lib advapi32.lib $(KLIB) $(CLIB) $(MS2MITRES) $(_VC_MANIFEST_EMBED_EXE) $(MIT2MS): $(OUTPRE)mit2ms.obj $(MIT2MSRES) - link $(EXE_LINKOPTS) -out:$@ $(OUTPRE)mit2ms.obj $(BUILDTOP)\util\windows\$(OUTPRE)getopt.obj user32.lib advapi32.lib $(KLIB) $(CLIB) $(MIT2MSRES) + link $(EXE_LINKOPTS) -out:$@ $(OUTPRE)mit2ms.obj $(SLIB) user32.lib advapi32.lib $(KLIB) $(CLIB) $(MIT2MSRES) $(_VC_MANIFEST_EMBED_EXE) install:: diff --git a/src/windows/ms2mit/mit2ms.c b/src/windows/ms2mit/mit2ms.c index 5dc057eb5e..24153cec99 100644 --- a/src/windows/ms2mit/mit2ms.c +++ b/src/windows/ms2mit/mit2ms.c @@ -26,9 +26,7 @@ #include "krb5.h" #include #include - -extern int optind; -extern char *optarg; +#include "k5-platform.h" static char *prog; diff --git a/src/windows/ms2mit/ms2mit.c b/src/windows/ms2mit/ms2mit.c index ebc9abd2e7..c3325034ad 100644 --- a/src/windows/ms2mit/ms2mit.c +++ b/src/windows/ms2mit/ms2mit.c @@ -29,9 +29,6 @@ #include #include -extern int optind; -extern char *optarg; - static char *prog; static void