From: Bruno Haible Date: Sun, 18 Dec 2016 12:07:43 +0000 (+0100) Subject: getopt: Fix link error for users of getopt() in . X-Git-Tag: v1.0~6456 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=571d60e6f9b53acd386d0cfe73e5c4fbf3a2c9da;p=gnulib.git getopt: Fix link error for users of getopt() in . * lib/getopt.in.h (getopt etc.): Do the macro definitions also when __need_getopt is defined. Undefine all macros before defining them. * modules/getopt (Include): Clarify that including is also OK. * tests/test-getopt.c: Add comment. --- diff --git a/ChangeLog b/ChangeLog index fdf61ab0ff..d9834b5b1e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2016-12-18 Bruno Haible + + getopt: Fix link error for users of getopt() in . + * lib/getopt.in.h (getopt etc.): Do the macro definitions also when + __need_getopt is defined. Undefine all macros before defining them. + * modules/getopt (Include): Clarify that including is also + OK. + * tests/test-getopt.c: Add comment. + 2016-12-17 Bruno Haible getaddrinfo tests: Avoid compilation error on MSVC. diff --git a/lib/getopt.in.h b/lib/getopt.in.h index 0f7218278f..64469b7c6b 100644 --- a/lib/getopt.in.h +++ b/lib/getopt.in.h @@ -47,15 +47,20 @@ identifiers so that they do not collide with the system functions and variables. Renaming avoids problems with some compilers and linkers. */ -#if defined __GETOPT_PREFIX && !defined __need_getopt -# if !@HAVE_GETOPT_H@ -# define __need_system_stdlib_h -# include -# undef __need_system_stdlib_h -# include -# include +#if defined __GETOPT_PREFIX +# if !defined __need_getopt +# if !@HAVE_GETOPT_H@ +# define __need_system_stdlib_h +# include +# undef __need_system_stdlib_h +# include +# include +# endif +# undef __need_getopt # endif -# undef __need_getopt +# undef __GETOPT_CONCAT +# undef __GETOPT_XCONCAT +# undef __GETOPT_ID # undef getopt # undef getopt_long # undef getopt_long_only @@ -64,6 +69,7 @@ # undef optind # undef optopt # undef option +# undef _getopt_internal # define __GETOPT_CONCAT(x, y) x ## y # define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y) # define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y) diff --git a/modules/getopt b/modules/getopt index 5d4f3c4989..53c844d8b0 100644 --- a/modules/getopt +++ b/modules/getopt @@ -17,7 +17,7 @@ configure.ac: Makefile.am: Include: - + or License: LGPL diff --git a/tests/test-getopt.c b/tests/test-getopt.c index 505cb2a994..04e1ae674b 100644 --- a/tests/test-getopt.c +++ b/tests/test-getopt.c @@ -38,7 +38,17 @@ SIGNATURE_CHECK (getopt_long_only, int, (int, char *__getopt_argv_const *, #endif -#include +/* POSIX and glibc provide the getopt() function in , see + http://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html + https://www.gnu.org/software/libc/manual/html_node/Using-Getopt.html + But gnulib provides the getopt() function in , not in . + Nevertheless the getopt() function should also be found in . + We can test it either way. */ +#if 0 +# include +#else +# include +#endif #include "signature.h" SIGNATURE_CHECK (getopt, int, (int, char * const[], char const *));