summaryrefslogtreecommitdiff
path: root/lib/getopt.in.h
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2016-12-18 13:07:43 +0100
committerBruno Haible <bruno@clisp.org>2016-12-18 13:08:25 +0100
commit571d60e6f9b53acd386d0cfe73e5c4fbf3a2c9da (patch)
treea72fbc3f7953731d5b705582d30e00e844497084 /lib/getopt.in.h
parent2ebd13d97452e41fbd2d1068b38f22a4b714fec3 (diff)
downloadgnulib-571d60e6f9b53acd386d0cfe73e5c4fbf3a2c9da.tar.gz
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.
Diffstat (limited to 'lib/getopt.in.h')
-rw-r--r--lib/getopt.in.h22
1 files changed, 14 insertions, 8 deletions
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 <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
@@ -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)