Override the gethostname() declaration on native Windows systems.
authorBruno Haible <bruno@clisp.org>
Sat, 25 Oct 2008 21:13:43 +0000 (23:13 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 25 Oct 2008 21:13:43 +0000 (23:13 +0200)
ChangeLog
doc/posix-functions/gethostname.texi
lib/sys_socket.in.h
lib/unistd.in.h
m4/gethostname.m4
modules/gethostname

index e180e153a6c129cc505c86f0d35cca21c1c9c97d..8eb9366b9704e1a5b2f71ad8924ed7b0f6245728 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2008-10-25  Ben Pfaff  <blp@cs.stanford.edu>
+            Bruno Haible  <bruno@clisp.org>
+
+       * lib/unistd.in.h: Include <winsock2.h>.
+       (socket, connect,accept, bind, getpeername, getsockname, getsockopt,
+       listen, recv, send, recvfrom, sendto, setsockopt, shutdown, select):
+       Provide dummy declarations.
+       (gethostname): Override.
+       * lib/sys_socket.in.h (gethostname): Provide dummy declaration.
+       * m4/gethostname.m4 (gl_FUNC_GETHOSTNAME): Invoke
+       gl_PREREQ_SYS_H_WINSOCK2.
+       * modules/gethostname (Files): Add m4/sys_socket_h.m4.
+       * doc/posix-functions/gethostname.texi: More details.
+
 2008-10-25  Bruno Haible  <bruno@clisp.org>
 
        * m4/sys_socket_h.m4 (gl_PREREQ_SYS_H_WINSOCK2): Require
index 9d32a8b75c95cf843ac6fda29e77736731dd16e9..1ff45fd26bdd24a1dbc472d5adc88ff3a1d3277b 100644 (file)
@@ -9,8 +9,8 @@ Gnulib module: gethostname
 Portability problems fixed by Gnulib:
 @itemize
 @item
-This function is missing on some platforms:
-mingw.
+On mingw, this function has a prototype that differs from that
+specified by POSIX, and it is defined only in the ws2_32 library.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 83a50bd2d435a46495ce60247a859272e6ac3ef3..63c80fff0cc5b789f1b5f45991a1e85774672a08 100644 (file)
@@ -145,6 +145,11 @@ rpl_fd_isset (SOCKET fd, fd_set * set)
 #  define close close_used_without_including_unistd_h
 # endif
 
+# if @HAVE_WINSOCK2_H@ && !defined _GL_UNISTD_H
+#  undef gethostname
+#  define gethostname gethostname_used_without_including_unistd_h
+# endif
+
 # if @GNULIB_SOCKET@
 #  if @HAVE_WINSOCK2_H@
 #   undef socket
index d949c9916a2a3c539bb59dde9023cd1fa6ef2372..fa8616a2a22bb91b67b3d9db554266c6ba22547a 100644 (file)
 # include <sys/types.h>
 #endif
 
+#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
+#   undef connect
+#   define connect             connect_used_without_including_sys_socket_h
+#   undef accept
+#   define accept              accept_used_without_including_sys_socket_h
+#   undef bind
+#   define bind                        bind_used_without_including_sys_socket_h
+#   undef getpeername
+#   define getpeername         getpeername_used_without_including_sys_socket_h
+#   undef getsockname
+#   define getsockname         getsockname_used_without_including_sys_socket_h
+#   undef getsockopt
+#   define getsockopt          getsockopt_used_without_including_sys_socket_h
+#   undef listen
+#   define listen              listen_used_without_including_sys_socket_h
+#   undef recv
+#   define recv                        recv_used_without_including_sys_socket_h
+#   undef send
+#   define send                        send_used_without_including_sys_socket_h
+#   undef recvfrom
+#   define recvfrom            recvfrom_used_without_including_sys_socket_h
+#   undef sendto
+#   define sendto              sendto_used_without_including_sys_socket_h
+#   undef setsockopt
+#   define setsockopt          setsockopt_used_without_including_sys_socket_h
+#   undef shutdown
+#   define shutdown            shutdown_used_without_including_sys_socket_h
+#  endif
+#  if !defined _GL_SYS_SELECT_H
+#   undef select
+#   define select              select_used_without_including_sys_select_h
+#  endif
+# endif
+#endif
+
 /* The definition of GL_LINK_WARNING is copied here.  */
 
 
@@ -284,9 +325,16 @@ extern int getdtablesize (void);
    Null terminate it if the name is shorter than LEN.
    If the host name is longer than LEN, set errno = EINVAL and return -1.
    Return 0 if successful, otherwise set errno and return -1.  */
-# if !@HAVE_GETHOSTNAME@
+# if @UNISTD_H_HAVE_WINSOCK2_H@
+#  undef gethostname
+#  define gethostname rpl_gethostname
+# endif
+# if @UNISTD_H_HAVE_WINSOCK2_H@ || !@HAVE_GETHOSTNAME@
 extern int gethostname(char *name, size_t len);
 # endif
+#elif @UNISTD_H_HAVE_WINSOCK2_H@
+# undef gethostname
+# define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
 #elif defined GNULIB_POSIXCHECK
 # undef gethostname
 # define gethostname(n,l) \
index b8c4e2a75a88205891a4641dfea6866926b7ce4e..217f9c17de0cbb9aff8656a1b169025891400e51 100644 (file)
@@ -1,4 +1,4 @@
-# gethostname.m4 serial 3
+# gethostname.m4 serial 4
 dnl Copyright (C) 2002, 2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -7,6 +7,7 @@ dnl with or without modifications, as long as this notice is preserved.
 AC_DEFUN([gl_FUNC_GETHOSTNAME],
 [
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  gl_PREREQ_SYS_H_WINSOCK2
   AC_REPLACE_FUNCS(gethostname)
   if test $ac_cv_func_gethostname = no; then
     HAVE_GETHOSTNAME=0
index 2fffbb1b2b30e3d407a001304a5520c11e1ceb7f..c61b5a9701f0165c15214767eabdadee26b1fa19 100644 (file)
@@ -4,6 +4,7 @@ gethostname() function: Return machine's hostname.
 Files:
 lib/gethostname.c
 m4/gethostname.m4
+m4/sys_socket_h.m4
 
 Depends-on:
 unistd