From 339096647215cb4a675239020ec247b6031fce1f Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 19 Mar 2010 16:57:28 -0600 Subject: [PATCH] gethostname: fix build on mingw Since commit 4e86671a, gethostname failed to compile on mingw. Gnulib's sys/socket.h includes winsock2.h, which then includes unistd.h prior to declaring gethostname. The fix is to ensure that our replacement unistd.h does not declare any replacements until we are sure that winsock2.h is completely included. * lib/unistd.in.h (includes): Work around fact that mingw re-includes , by avoiding any redeclarations if we are being included by . Reported by Matthias Bolte. Signed-off-by: Eric Blake --- ChangeLog | 8 ++++++++ lib/unistd.in.h | 28 +++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 78de306a7..e9485793d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-03-22 Eric Blake + + gethostname: fix build on mingw + * lib/unistd.in.h (includes): Work around fact that mingw + re-includes , by avoiding any + redeclarations if we are being included by . + Reported by Matthias Bolte. + 2010-03-21 Bruno Haible forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris. diff --git a/lib/unistd.in.h b/lib/unistd.in.h index c1732b842..beef6b05c 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -15,7 +15,23 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef _GL_UNISTD_H +/* Special invocation convention: + - On mingw, several headers, including , include , + but we need to ensure that both the system and + are completely included before we replace gethostname. */ +#if @UNISTD_H_HAVE_WINSOCK2_H@ && !defined _GL_WINSOCK2_H_WITNESS \ + && defined _WINSOCK2_H +/* is being indirectly included for the first time from + ; avoid declaring any overrides. */ +# if @HAVE_UNISTD_H@ +# @INCLUDE_NEXT@ @NEXT_UNISTD_H@ +# else +# error unexpected; report this to bug-gnulib@gnu.org +# endif +# define _GL_WINSOCK2_H_WITNESS + +/* Normal invocation. */ +#elif !defined _GL_UNISTD_H #if __GNUC__ >= 3 @PRAGMA_SYSTEM_HEADER@ @@ -26,7 +42,14 @@ # @INCLUDE_NEXT@ @NEXT_UNISTD_H@ #endif -#ifndef _GL_UNISTD_H +/* Get all possible declarations of gethostname(). */ +#if @UNISTD_H_HAVE_WINSOCK2_H@ && !defined _GL_INCLUDING_WINSOCK2_H +# define _GL_INCLUDING_WINSOCK2_H +# include +# undef _GL_INCLUDING_WINSOCK2_H +#endif + +#if !defined _GL_UNISTD_H && !defined _GL_INCLUDING_WINSOCK2_H #define _GL_UNISTD_H /* NetBSD 5.0 mis-defines NULL. Also get size_t. */ @@ -76,7 +99,6 @@ #if @GNULIB_GETHOSTNAME@ /* Get all possible declarations of gethostname(). */ # if @UNISTD_H_HAVE_WINSOCK2_H@ -# include # if !defined _GL_SYS_SOCKET_H # undef socket # define socket socket_used_without_including_sys_socket_h -- 2.11.0