Michel reported on pspp-dev that PSPP fails to compile on mingw due to the following error:
> In file included from > C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/windows.h:98, > from lseek.c:26: > C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/winsock2.h:635: > error: conflicting types for 'gethostname' > ./unistd.h:313: error: previous declaration of 'gethostname' was here I can see what is going wrong: - The gethostname module fails to find gethostname() because it is in the ws2_32 library, which it doesn't try to link against. Thus, it tries to replace it. - Thus, it adds a prototype for gethostname() to the replacement unistd.h. This prototype has a length parameter of type size_t (per POSIX). - The lseek module needs unistd.h and windows.h. The latter in turn includes winsock2.h, which contains the Windows prototype for gethostname(), which has an length parameter of type int (who knows why). I think that the following change will fix the problem. Does it look like the right approach? If so, I will generate a new snapshot for Michel to test before I commit it to gnulib. Thanks, Ben. commit ed8093c8eedcf44193b29155a9bbf49f83e0d3e7 Author: Ben Pfaff <[EMAIL PROTECTED]> Date: Wed Oct 22 21:54:23 2008 -0700 Fix gethostname on mingw. * lib/unistd.in.h: Bypass bad winsock2 prototype for gethostname. Prevent calling gethostname on mingw without using the gethostname module. * gethostname.m4: Invoke gl_PREREQ_SYS_H_WINSOCK2 if it is available. * doc/posix-functions/gethostname.texi: Update. diff --git a/ChangeLog b/ChangeLog index b6c2893..e47a922 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-10-22 Ben Pfaff <[EMAIL PROTECTED]> + + * lib/unistd.in.h: Bypass bad winsock2 prototype for gethostname. + Prevent calling gethostname on mingw without using the gethostname + module. + * gethostname.m4: Invoke gl_PREREQ_SYS_H_WINSOCK2 if it is + available. + * doc/posix-functions/gethostname.texi: Update. + 2008-10-22 Simon Josefsson <[EMAIL PROTECTED]> * lib/sys_socket.in.h (FD_ISSET): Fix warnings under mingw. diff --git a/doc/posix-functions/gethostname.texi b/doc/posix-functions/gethostname.texi index 9d32a8b..1ff45fd 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/unistd.in.h b/lib/unistd.in.h index bfa3d49..7a5db76 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -281,8 +281,17 @@ extern int getdtablesize (void); 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 [EMAIL PROTECTED]@ +# if HAVE_WINSOCK2_H +# /* Bypass bad prototype for gethostname(). */ +# include <winsock2.h> +# undef gethostname +# define gethostname rpl_gethostname +# endif 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 b8c4e2a..7095ac3 100644 --- a/m4/gethostname.m4 +++ b/m4/gethostname.m4 @@ -6,6 +6,7 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_GETHOSTNAME], [ + m4_ifdef([gl_PREREQ_SYS_H_WINSOCK2], [gl_PREREQ_SYS_H_WINSOCK2]) AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) AC_REPLACE_FUNCS(gethostname) if test $ac_cv_func_gethostname = no; then -- "Welcome to the Slippery Slope. Here is your handbasket. Say, can you work 70 hours this week?" --Ron Mansolino