From: Bruno Haible Date: Sat, 8 Aug 2009 09:18:41 +0000 (+0200) Subject: Define HOST_NAME_MAX also for the various Unix platforms. X-Git-Tag: v0.1~5693 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=9e74daebbd03566e8e2f18ee49c4a928a563ccb5;p=gnulib.git Define HOST_NAME_MAX also for the various Unix platforms. --- diff --git a/ChangeLog b/ChangeLog index d3df86cde..e3e562fb5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-08-08 Bruno Haible + + * m4/gethostname.m4 (gl_FUNC_GETHOSTNAME): Define HOST_NAME_MAX also + for the various Unix platforms. + * doc/posix-headers/limits.texi: Update platforms list regarding + HOST_NAME_MAX. + Reported by Tom G. Christensen . + 2009-08-07 Jim Meyering selinux-at: fix typo in a comment diff --git a/doc/posix-headers/limits.texi b/doc/posix-headers/limits.texi index fa5c1eb31..21b53bba8 100644 --- a/doc/posix-headers/limits.texi +++ b/doc/posix-headers/limits.texi @@ -8,7 +8,7 @@ Gnulib module: gethostname Portability problems fixed by Gnulib: @itemize The @code{HOST_NAME_MAX} macro is not defined on some platforms: -mingw. +MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin, mingw, Interix 3.5, BeOS. @end itemize Portability problems not fixed by Gnulib: diff --git a/m4/gethostname.m4 b/m4/gethostname.m4 index 8af4aa049..e32f7e52e 100644 --- a/m4/gethostname.m4 +++ b/m4/gethostname.m4 @@ -1,4 +1,4 @@ -# gethostname.m4 serial 7 +# gethostname.m4 serial 8 dnl Copyright (C) 2002, 2008, 2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -43,12 +43,52 @@ AC_DEFUN([gl_FUNC_GETHOSTNAME], fi dnl Also provide HOST_NAME_MAX when lacks it. - if test "$gl_cv_w32_gethostname" = "yes"; then - # says: - # "if a buffer of 256 bytes is passed in the name parameter and - # the namelen parameter is set to 256, the buffer size will always - # be adequate." - AC_DEFINE([HOST_NAME_MAX], [256], + dnl - On most Unix systems, use MAXHOSTNAMELEN from instead. + dnl - On Solaris, Cygwin, BeOS, use MAXHOSTNAMELEN from instead. + dnl - On mingw, use 256, because + dnl says: + dnl "if a buffer of 256 bytes is passed in the name parameter and + dnl the namelen parameter is set to 256, the buffer size will always + dnl be adequate." + dnl With this, there is no need to use sysconf (_SC_HOST_NAME_MAX), which + dnl is not a compile-time constant. + dnl We cannot override using the usual technique, because + dnl gl_CHECK_NEXT_HEADERS does not work for . Therefore retrieve + dnl the value of HOST_NAME_MAX at configure time. + AC_CHECK_HEADERS_ONCE([sys/param.h]) + AC_CHECK_HEADERS_ONCE([sys/socket.h]) + AC_CHECK_HEADERS_ONCE([netdb.h]) + AC_CACHE_CHECK([for HOST_NAME_MAX], [gl_cv_decl_HOST_NAME_MAX], [ + gl_cv_decl_HOST_NAME_MAX= + AC_EGREP_CPP([lucky], [ +#include +#ifdef HOST_NAME_MAX +lucky +#endif + ], [gl_cv_decl_HOST_NAME_MAX=yes]) + if test -z "$gl_cv_decl_HOST_NAME_MAX"; then + dnl It's not defined in . Substitute it. + if test "$gl_cv_w32_gethostname" = yes; then + dnl mingw. + gl_cv_decl_HOST_NAME_MAX=256 + else + _AC_COMPUTE_INT([MAXHOSTNAMELEN], [gl_cv_decl_HOST_NAME_MAX], [ +#include +#if HAVE_SYS_PARAM_H +# include +#endif +#if HAVE_SYS_SOCKET_H +# include +#endif +#if HAVE_NETDB_H +# include +#endif +]) + fi + fi + ]) + if test "$gl_cv_decl_HOST_NAME_MAX" != yes; then + AC_DEFINE_UNQUOTED([HOST_NAME_MAX], [$gl_cv_decl_HOST_NAME_MAX], [Define HOST_NAME_MAX when does not define it.]) fi ])