diff options
author | Greg Hudson <ghudson@mit.edu> | 2018-05-15 21:52:08 -0700 |
---|---|---|
committer | Greg Hudson <ghudson@mit.edu> | 2018-10-29 12:42:42 -0400 |
commit | bbd9f7e7237d27ff7bad6e6587b35aae882c3125 (patch) | |
tree | c8f24a7d0aac5ecadc5b7353de8d0aff15f4e486 /src/util | |
parent | 0155aa1220a850ee9d8d0ec387cd8c7f76790c9e (diff) | |
download | krb5-bbd9f7e7237d27ff7bad6e6587b35aae882c3125.zip krb5-bbd9f7e7237d27ff7bad6e6587b35aae882c3125.tar.gz krb5-bbd9f7e7237d27ff7bad6e6587b35aae882c3125.tar.bz2 |
Fix option parsing on Windows
Commit 8f9ade8ec50cde1176411085294f85ecfb2820a4 (ticket 8391) moved
the built-in getopt() and getopt_long() implementations from a static
library in util/windows to util/support, where (on Windows) it is
built into k5sprt32.dll or k5sprt64.dll. The getopt() interface uses
global variables opterr, optind, optopt, and optarg, each renamed via
macro to have a k5_ prefix when we use the built-in implementation.
Data objects exported from DLLs need special handling in Windows; they
must be marked as DATA in the DLL .def file, and they must be declared
with "__declspec(dllimport)" in calling code. Without this handling,
optind begins with a garbage value and getopt_long() returns -1
immediately, so client programs always behave as if they have no
arguments.
Stop unnecessarily declaring optind and optarg in client programs.
Declare the getopt() global variables with __declspec(dllimport) on
Windows, except when compiling getopt.c itself. When creating
libkrb5support.exports on Windows (this file is later used by
lib/Makefile.in to create k5sprt32.def), add a DATA tag to the data
objects.
(cherry picked from commit 63246cf3513a0e8bdfc734db985af14c8c5170c5)
ticket: 8684
version_fixed: 1.16.2
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/support/Makefile.in | 4 | ||||
-rw-r--r-- | src/util/support/getopt.c | 2 |
2 files changed, 5 insertions, 1 deletions
diff --git a/src/util/support/Makefile.in b/src/util/support/Makefile.in index 0bf0b7a..f3f7eec 100644 --- a/src/util/support/Makefile.in +++ b/src/util/support/Makefile.in @@ -173,8 +173,9 @@ 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## k5_getopt k5_getopt_long \ ##DOS## krb5int_vasprintf krb5int_asprintf krb5int_gettimeofday $(IPC_SYMS) +##DOS##DATA_SUPPORT_SYMS= k5_opterr k5_optind k5_optopt k5_optarg ##DOS##!if 0 libkrb5support.exports: $(srcdir)/libkrb5support-fixed.exports Makefile @@ -187,6 +188,7 @@ libkrb5support.exports: $(srcdir)/libkrb5support-fixed.exports Makefile ##DOS##libkrb5support.exports: libkrb5support-fixed.exports Makefile ##DOS## $(CP) libkrb5support-fixed.exports new-exports ##DOS## for %%x in ($(EXTRA_SUPPORT_SYMS) .) do if not %%x==. echo %%x >> new-exports +##DOS## for %%x in ($(DATA_SUPPORT_SYMS) .) do if not %x==. echo %%x DATA >> new-exports ##DOS## $(RM) libkrb5support.exports ##DOS## $(MV) new-exports libkrb5support.exports diff --git a/src/util/support/getopt.c b/src/util/support/getopt.c index 44cda68..ae8cb10 100644 --- a/src/util/support/getopt.c +++ b/src/util/support/getopt.c @@ -39,6 +39,8 @@ static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95"; #endif +#define K5_GETOPT_C + #include <assert.h> #include <errno.h> #include <stdio.h> |