bug-gnulib
[Top][All Lists]
Advanced

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

(x)gethostname


From: Simon Josefsson
Subject: (x)gethostname
Date: Wed, 16 Jan 2008 14:55:51 +0100
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.1 (gnu/linux)

Building shishi on mingw leads to:

../../../src/shishi-0.0.34/gl/xgethostname.c: In function 'xgethostname':
../../../src/shishi-0.0.34/gl/xgethostname.c:61: warning: implicit declaration 
of function 'gethostname'

According to

http://www.opengroup.org/onlinepubs/009695399/functions/gethostname.html

gethostname is declared in unistd.h, but gnulib's unistd.h doesn't.

MinGW declare gethostname in winsock.h/winsock2.h, so if gnulib's
unistd.h would pull either of those in, I believe it would work.

According to m4/sys_socket_h.m4, just checking for winsock2.h and
including that file would break cygwin.  It is claimed that cygwin never
wants winsock2.h to be included, instead things should go via
sys/socket.h.  (Is this still relevant?)

If I understand correctly, unistd-h could either duplicate the logic in
sys_socket_h to make sure winsock2.h isn't pulled in on cygwin, or
unistd could simply depend on sys_socket_h and #include <sys/socket.h>
in unistd.in.h.  The sys_socket module seems rather light-weight now.
So how about the patch below?  It probably needs to be revisited if the
sys_socket module grows significantly.

/Simon

2008-01-16  Simon Josefsson  <address@hidden>

        * lib/unistd.in.h: Include sys/socket.h, to get to winsock2.h,
        which declares gethostname on MinGW.

        * modules/unistd (Depends-on): Add sys_socket.

diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index 5400c86..7220908 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -1,5 +1,5 @@
 /* Substitute for and wrapper around <unistd.h>.
-   Copyright (C) 2004-2007 Free Software Foundation, Inc.
+   Copyright (C) 2004-2008 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -33,6 +33,11 @@
 /* mingw fails to declare _exit in <unistd.h>.  */
 #include <stdlib.h>
 
+/* mingw fails to declare gethostname in <unistd.h>, but declare it in
+   winsock2.h.  Cygwin should not include winsock2.h, instead
+   winsock2.h access needs to go via sys/socket.h, so we do that. */
+#include <sys/socket.h>
+
 /* The definition of GL_LINK_WARNING is copied here.  */
 
 
diff --git a/modules/unistd b/modules/unistd
index 4d16cf3..b81ce90 100644
--- a/modules/unistd
+++ b/modules/unistd
@@ -8,6 +8,7 @@ lib/unistd.in.h
 Depends-on:
 include_next
 link-warning
+sys_socket
 
 configure.ac:
 gl_UNISTD_H




reply via email to

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