Sam Steingold <[EMAIL PROTECTED]> writes: > Simon Josefsson wrote: >> Sam Steingold <[EMAIL PROTECTED]> writes: >> >>> Simon Josefsson wrote: >>>> Sam Steingold <[EMAIL PROTECTED]> writes: >>>> >>>>>>> 1. why aren't you testing for HAVE_SYS_UTSNAME_H instead? >>>>>>> >>>>>>> 2. are there really systems without uname & <sys/utsname.h>, given >>>>>>> that these are in posix? >>>>>>> http://www.opengroup.org/onlinepubs/009695399/functions/uname.html >>>>>> I think the right solution here should be to apply the patch below. >>>>>> If there are problems on any system caused by that, the solution to >>>>>> that problem should be to create a module for sys/utsname.h and uname. >>>>>> The gethostname module shouldn't depend on such modules, they need to >>>>>> be added manually by maintainers who want compatibility with non-POSIX >>>>>> systems. Thoughts? >>>>> note that gethostname is just as posix as uname, >>>>> http://www.opengroup.org/onlinepubs/009695399/functions/gethostname.html >>>>> so the gethostname module is only needed for non-posix systems. >>>> Indeed, so I am less sure my patch is the right thing. Could you >>>> explain why the current code causes problems for you? >>> no problems - just questions: >>> >>> 1. is this module ever needed on a unix system? >>> i.e., are there any unix systems still in use that lack gethostname? >>> >>> 2. are there any unix systems still in use that lack uname? >> >> Ben answered those questions. Even if the code may not be optimal for >> some platform we aren't aware of, until we know of a real problem with >> it I think we could leave the code as-is. > > Please name the platform(s) which can benefit from this module. > > Ben's answer suggests that the set is empty.
Ben said MinGW doesn't have gethostname. I don't know what nsk-G06 is, is it a platform gnulib supports? Hm. I think MinGW actually does have a gethostname, but you need to link to -lws2_32 to see it. Yup. I actually have a local tree of gnulib that implements this test. Patch below, but it is ancient and there were likely some reason this was never installed. I'll see if I can revise it. /Simon diff --git a/ChangeLog b/ChangeLog index f52d4c2..070a15e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,22 @@ 2008-01-17 Simon Josefsson <[EMAIL PROTECTED]> + Bruno Haible <[EMAIL PROTECTED]> + + * lib/unistd.in.h: Include <sys/socket.h> conditionally. + * modules/unistd (Makefile.am): Substitute GNULIB_GETHOSTNAME. + * modules/gethostname (Depends-on): Add sys_socket and unistd. + (configure.ac): Invoke gl_MODULE_INDICATOR. + (Include): Document <unistd.h>. + * m4/unistd_h.m4: Default GNULIB_GETHOSTNAME to 0. + +2008-01-17 Simon Josefsson <[EMAIL PROTECTED]> + + * m4/gethostname.m4: Look for gethostname in winsock2.h and + -lws2_32 too, for mingw. + + * modules/gethostname (Depends-on): Add sys_socket, needed for + proper mingw checks. + +2008-01-17 Simon Josefsson <[EMAIL PROTECTED]> * modules/gethostname-tests: New file. diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 5400c86..809c14a 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>. */ +#if [EMAIL PROTECTED]@ && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) +# include <sys/socket.h> +#endif + /* The definition of GL_LINK_WARNING is copied here. */ diff --git a/m4/gethostname.m4 b/m4/gethostname.m4 index 1e9749d..359cdf1 100644 --- a/m4/gethostname.m4 +++ b/m4/gethostname.m4 @@ -1,13 +1,45 @@ -# gethostname.m4 serial 2 -dnl Copyright (C) 2002 Free Software Foundation, Inc. +# gethostname.m4 serial 3 +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, dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_GETHOSTNAME], [ - AC_REPLACE_FUNCS(gethostname) - if test $ac_cv_func_gethostname = no; then + AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H + + AC_CACHE_CHECK([for gethostname], [gl_cv_func_gethostname], [ + AC_TRY_LINK([ +#include <sys/types.h> +#ifdef HAVE_SYS_SOCKET_H +#include <sys/socket.h> +#endif +#include <stddef.h> +], [gethostname("", 0);], + [gl_cv_func_gethostname=yes], + [gl_cv_func_gethostname=no])]) + if test $gl_cv_func_gethostname = no; then + AC_CACHE_CHECK(for gethostname in winsock2.h and -lws2_32, + gl_cv_w32_gethostname, [ + gl_cv_w32_gethostname=no + am_save_LIBS="$LIBS" + LIBS="$LIBS -lws2_32" + AC_TRY_LINK([ +#ifdef HAVE_WINSOCK2_H +#include <winsock2.h> +#endif +#include <stddef.h> +], [gethostname("", 0);], gl_cv_w32_gethostname=yes) + LIBS="$am_save_LIBS"]) + if test "$gl_cv_w32_gethostname" = "yes"; then + LIBS="$LIBS -lws2_32" + else + AC_LIBOBJ(gethostname) + fi + fi + + if test "$ac_cv_func_gethostname" = no && + test "$gl_cv_w32_gethostname" = no; then gl_PREREQ_GETHOSTNAME fi ]) diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 index 4b8857c..1eca87c 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -1,5 +1,5 @@ # unistd_h.m4 serial 10 -dnl Copyright (C) 2006-2007 Free Software Foundation, Inc. +dnl Copyright (C) 2006-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, dnl with or without modifications, as long as this notice is preserved. @@ -38,6 +38,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], GNULIB_FTRUNCATE=0; AC_SUBST([GNULIB_FTRUNCATE]) GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD]) GNULIB_GETLOGIN_R=0; AC_SUBST([GNULIB_GETLOGIN_R]) + GNULIB_GETHOSTNAME=0; AC_SUBST([GNULIB_GETHOSTNAME]) GNULIB_GETPAGESIZE=0; AC_SUBST([GNULIB_GETPAGESIZE]) GNULIB_LCHOWN=0; AC_SUBST([GNULIB_LCHOWN]) GNULIB_LSEEK=0; AC_SUBST([GNULIB_LSEEK]) diff --git a/modules/gethostname b/modules/gethostname index 7c13807..b169701 100644 --- a/modules/gethostname +++ b/modules/gethostname @@ -6,13 +6,17 @@ lib/gethostname.c m4/gethostname.m4 Depends-on: +unistd +sys_socket configure.ac: gl_FUNC_GETHOSTNAME +gl_MODULE_INDICATOR([gethostname]) Makefile.am: Include: +<unistd.h> License: LGPL diff --git a/modules/unistd b/modules/unistd index 4d16cf3..d1005f1 100644 --- a/modules/unistd +++ b/modules/unistd @@ -29,6 +29,7 @@ unistd.h: unistd.in.h -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \ -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \ -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \ + -e 's|@''GNULIB_GETHOSTNAME''@|$(GNULIB_GETHOSTNAME)|g' \ -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \ -e 's|@''GNULIB_LCHOWN''@|$(GNULIB_LCHOWN)|g' \ -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \