On 03/21/2010 01:45 PM, Matthias Bolte wrote: > 2010/3/20 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. Therefore, unistd.h >> cannot replace gethostname until winsock2.h is complete, also >> fixing things if a .c includes <unistd.h> (or even <winsock2.h>) >> prior to <sys/socket.h>. >> > > If I apply the attached diff on top of this patch the problem is > fixed. It compiles without errors, I can include <unistd.h> before > <sys/socket.h> and I can include <winsock2.h> before <sys/socket.h> as > long as the <winsock2.h> include is wrapped in #define/#undef > _GL_INCLUDING_WINSOCK2_H. > > The important part is > > -# if @UNISTD_H_HAVE_WINSOCK2_H@ > +# if @UNISTD_H_HAVE_WINSOCK2_H@ && !defined _GL_INCLUDING_WINSOCK2_H > > This stops the <winsock2.h>-includes-<unistd.h>-case from undefining > _GL_INCLUDING_WINSOCK2_H too early.
Well, we're getting closer. But I'd really like to avoid making all clients of <winsock2.h> make an adjustment; it seems like it should still be possible to make _just_ <unistd.h> have the smarts necessary. Here's some pseudocode I'm currently thinking about (patch to come up later...) #if [_WINSOCK2_H and !witness] /* Someone has included <winsock2.h> prior to <unistd.h> - let it run to completion, without declaring any of our overrides; to be portable, the user will have to later include <unistd.h> if they plan on using gethostname. */ # include_next <unistd.h> # define witness #else /* Normal invocation */ # if !defined _GL_UNISTD_H # include_next <unistd.h> /* Include everything that declares something that we might want to override */ # define _GL_INCLUDING_WINSOCK2_H # include <winsock2.h> # undef _GL_INCLUDING_WINSOCK2_H /* Split include guard. */ # if !defined _GL_UNISTD_H && !defined _GL_INCLUDING_WINSOCK2_H # define _GL_UNISTD_H /* Declare our overrides. */ # endif /* _GL_UNISTD_H/_GL_INCLUDING_WINSOCK2_H */ # endif /* _GL_UNISTD_H */ #endif /*_WINSOCK2_H */ -- Eric Blake ebl...@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature