From 20491bb197b77a1fb32516f65732d168c4cf07d3 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 25 Oct 2008 23:13:43 +0200 Subject: [PATCH] Override the gethostname() declaration on native Windows systems. --- ChangeLog | 14 ++++++++++ doc/posix-functions/gethostname.texi | 4 +-- lib/sys_socket.in.h | 5 ++++ lib/unistd.in.h | 50 +++++++++++++++++++++++++++++++++++- m4/gethostname.m4 | 3 ++- modules/gethostname | 1 + 6 files changed, 73 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index e180e153a..8eb9366b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2008-10-25 Ben Pfaff + Bruno Haible + + * lib/unistd.in.h: Include . + (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 * m4/sys_socket_h.m4 (gl_PREREQ_SYS_H_WINSOCK2): Require diff --git a/doc/posix-functions/gethostname.texi b/doc/posix-functions/gethostname.texi index 9d32a8b75..1ff45fd26 100644 --- a/doc/posix-functions/gethostname.texi +++ b/doc/posix-functions/gethostname.texi @@ -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: diff --git a/lib/sys_socket.in.h b/lib/sys_socket.in.h index 83a50bd2d..63c80fff0 100644 --- a/lib/sys_socket.in.h +++ b/lib/sys_socket.in.h @@ -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 diff --git a/lib/unistd.in.h b/lib/unistd.in.h index d949c9916..fa8616a2a 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -42,6 +42,47 @@ # include #endif +#if @GNULIB_GETHOSTNAME@ +/* Get all possible declarations of gethostname(). */ +# if @UNISTD_H_HAVE_WINSOCK2_H@ +# include +# 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) \ diff --git a/m4/gethostname.m4 b/m4/gethostname.m4 index b8c4e2a75..217f9c17d 100644 --- a/m4/gethostname.m4 +++ b/m4/gethostname.m4 @@ -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 diff --git a/modules/gethostname b/modules/gethostname index 2fffbb1b2..c61b5a970 100644 --- a/modules/gethostname +++ b/modules/gethostname @@ -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 -- 2.11.0