Sam Steingold <[EMAIL PROTECTED]> writes: > gnulib/lib/gethostname.c says: > > #ifdef HAVE_UNAME > # include <sys/utsname.h> > #endif > > 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? /Simon diff --git a/ChangeLog b/ChangeLog index 8d92122..b911473 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-08-11 Simon Josefsson <[EMAIL PROTECTED]> + + * lib/gethostname.c: Unconditionally include sys/utsname.h and + call uname. + + * m4/gethostname.m4: Assume uname exists. + 2008-08-07 Paolo Bonzini <[EMAIL PROTECTED]> * lib/lock.c (glthread_recursive_lock_init_multithreaded) diff --git a/lib/gethostname.c b/lib/gethostname.c index 169dd4e..c9624f0 100644 --- a/lib/gethostname.c +++ b/lib/gethostname.c @@ -19,9 +19,7 @@ #include <config.h> -#ifdef HAVE_UNAME -# include <sys/utsname.h> -#endif +#include <sys/utsname.h> #include <string.h> @@ -34,7 +32,6 @@ int gethostname (char *name, size_t len) { -#ifdef HAVE_UNAME struct utsname uts; if (uname (&uts) == -1) @@ -46,8 +43,6 @@ gethostname (char *name, size_t len) len = sizeof (uts.nodename); } strncpy (name, uts.nodename, len); -#else - strcpy (name, ""); /* Hardcode your system name if you want. */ -#endif + return 0; } diff --git a/m4/gethostname.m4 b/m4/gethostname.m4 index 1e9749d..616f9e4 100644 --- a/m4/gethostname.m4 +++ b/m4/gethostname.m4 @@ -1,5 +1,5 @@ -# 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. @@ -14,5 +14,5 @@ AC_DEFUN([gl_FUNC_GETHOSTNAME], # Prerequisites of lib/gethostname.c. AC_DEFUN([gl_PREREQ_GETHOSTNAME], [ - AC_CHECK_FUNCS(uname) + : ])