bug-gnulib
[Top][All Lists]
Advanced

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

Re: unistd & sys/socket


From: Eric Blake
Subject: Re: unistd & sys/socket
Date: Thu, 14 Jul 2011 07:43:40 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110621 Fedora/3.1.11-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.11

On 07/14/2011 07:37 AM, Sam Steingold wrote:
> Hi,
> in what order do I include sys/socket and unistd?
> sys_socket.in.h:
> #if @HAVE_WINSOCK2_H@ && !defined _GL_UNISTD_H
> # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
> #  undef close
> #  define close close_used_without_including_unistd_h
> # else
>    _GL_WARN_ON_USE (close,
>                     "close() used without including <unistd.h>");
> # endif
> #endif
> 
> so, on windows, I must include unistd before sys/socket, otherwise close
> will not work.
> 
> otoh:
> unistd.in.h:
> #if @GNULIB_GETHOSTNAME@
> /* Get all possible declarations of gethostname().  */
> # if @UNISTD_H_HAVE_WINSOCK2_H@
> #  if !defined _GL_SYS_SOCKET_H
> #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
> #    undef socket
> #    define socket              socket_used_without_including_sys_socket_h
> 
> so I must include sys/socket before unistd, otherwise socket (and many
> others) will not work.
> 
> so, what is the right order?

Do you have an actual compilation error, or are you just trying to
understand the code?  Both orders should work, if you are using the
gnulib modules for both headers.

Note that in unistd.in.h, on mingw, <sys/socket.h> is included prior to
this snippet of @GNULIB_GETHOSTNAME@, such that _GL_SYS_SOCKET_H is
defined and you never get the
socket_used_without_including_sys_socket_h, if you were using both
gnulib modules.

-- 
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]