2010/3/22 Eric Blake <ebl...@redhat.com>: > 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 > <winsock2.h> re-includes <unistd.h>, by avoiding any > redeclarations if we are being included by <winsock2.h>. > Reported by Matthias Bolte. > > Signed-off-by: Eric Blake <ebl...@redhat.com> > --- > > Try 4. This time, try localizing all the changes to just our > replacement <unistd.h>. Detect whether we are being indirectly > included by <winsock2.h>, so that clients should not have to > adjust their calling patterns (although they DO need to explcitly > include <unistd.h> if they plan on using gethostname, rather > than relying on the nonstandard <winsock2.h> to provide it). > > ChangeLog | 8 ++++++++ > lib/unistd.in.h | 28 +++++++++++++++++++++++++--- > 2 files changed, 33 insertions(+), 3 deletions(-) > > diff --git a/ChangeLog b/ChangeLog > index cc3ef5a..22dfca0 100644 > --- a/ChangeLog > +++ b/ChangeLog > @@ -1,3 +1,11 @@ > +2010-03-22 Eric Blake <ebl...@redhat.com> > + > + gethostname: fix build on mingw > + * lib/unistd.in.h (includes): Work around fact that mingw > + <winsock2.h> re-includes <unistd.h>, by avoiding any > + redeclarations if we are being included by <winsock2.h>. > + Reported by Matthias Bolte. > + > 2010-03-20 Bruno Haible <br...@clisp.org> > > * m4/unlink.m4 (gl_FUNC_UNLINK): Fix last commit. > diff --git a/lib/unistd.in.h b/lib/unistd.in.h > index b74484a..b2b92c8 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 <winsock2.h>, include <unistd.h>, > + but we need to ensure that both the system <unistd.h> and <winsock2.h> > + are completely included before we replace gethostname. */ > +#if @UNISTD_H_HAVE_WINSOCK2_H@ && !defined _GL_WINSOCK2_H_WITNESS \ > + && defined _WINSOCK2_H > +/* <unistd.h> is being indirectly included for the first time from > + <winsock2.h>; avoid declaring any overrides. */ > +# if @HAVE_UNISTD_H
An @ is missing here. > +# �...@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 <winsock2.h> > +# 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 <winsock2.h> > # if !defined _GL_SYS_SOCKET_H > # undef socket > # define socket socket_used_without_including_sys_socket_h > -- > 1.6.6.1 > ACK. This one fixes the issue. Matthias