+2016-12-18 Bruno Haible <bruno@clisp.org>
+
+ getopt: Fix link error for users of getopt() in <unistd.h>.
+ * 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 <unistd.h> is also
+ OK.
+ * tests/test-getopt.c: Add comment.
+
2016-12-17 Bruno Haible <bruno@clisp.org>
getaddrinfo tests: Avoid compilation error on MSVC.
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 <stdlib.h>
-# undef __need_system_stdlib_h
-# include <stdio.h>
-# include <unistd.h>
+#if defined __GETOPT_PREFIX
+# if !defined __need_getopt
+# if !@HAVE_GETOPT_H@
+# define __need_system_stdlib_h
+# include <stdlib.h>
+# undef __need_system_stdlib_h
+# include <stdio.h>
+# include <unistd.h>
+# 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
# 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)
Makefile.am:
Include:
-<getopt.h>
+<getopt.h> or <unistd.h>
License:
LGPL
#endif
-#include <unistd.h>
+/* POSIX and glibc provide the getopt() function in <unistd.h>, 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 <getopt.h>, not in <unistd.h>.
+ Nevertheless the getopt() function should also be found in <unistd.h>.
+ We can test it either way. */
+#if 0
+# include <getopt.h>
+#else
+# include <unistd.h>
+#endif
#include "signature.h"
SIGNATURE_CHECK (getopt, int, (int, char * const[], char const *));