[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] gethostname: fix build on mingw

From: Eric Blake
Subject: Re: [PATCH] gethostname: fix build on mingw
Date: Mon, 22 Mar 2010 09:09:41 -0600
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20100301 Fedora/3.0.3-1.fc12 Lightning/1.0b1 Thunderbird/3.0.3

On 03/21/2010 01:45 PM, Matthias Bolte wrote:
> 2010/3/20 Eric Blake <address@hidden>:
>> 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
> The important part is
> This stops the <winsock2.h>-includes-<unistd.h>-case from undefining

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

#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
/* Normal invocation */
# if !defined _GL_UNISTD_H
# include_next <unistd.h>

/* Include everything that declares something that we might want to
override */
# include <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 */
#endif /*_WINSOCK2_H */

Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]