X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=m4%2Fgethostname.m4;h=d759ab1326c665c55bda4b74c0f0f21c9c67d6c8;hb=1276a2c5f24c0c932426aca9c899fa524d2443f2;hp=620e023c8389285937162de97a954f18c0970b54;hpb=33bcc047c11586cff59d22566226e847e0c23954;p=gnulib.git diff --git a/m4/gethostname.m4 b/m4/gethostname.m4 index 620e023c8..d759ab132 100644 --- a/m4/gethostname.m4 +++ b/m4/gethostname.m4 @@ -1,9 +1,12 @@ -# gethostname.m4 serial 6 -dnl Copyright (C) 2002, 2008, 2009 Free Software Foundation, Inc. +# gethostname.m4 serial 13 +dnl Copyright (C) 2002, 2008-2014 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. +# Ensure +# - the gethostname() function, +# - the HOST_NAME_MAX macro in . AC_DEFUN([gl_FUNC_GETHOSTNAME], [ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) @@ -11,7 +14,7 @@ AC_DEFUN([gl_FUNC_GETHOSTNAME], dnl Where is gethostname() defined? dnl - On native Windows, it is in ws2_32.dll. - dnl - Otherwise is is in libc. + dnl - Otherwise it is in libc. GETHOSTNAME_LIB= AC_CHECK_FUNCS([gethostname], , [ AC_CACHE_CHECK([for gethostname in winsock2.h and -lws2_32], @@ -19,12 +22,12 @@ AC_DEFUN([gl_FUNC_GETHOSTNAME], [gl_cv_w32_gethostname=no gl_save_LIBS="$LIBS" LIBS="$LIBS -lws2_32" - AC_TRY_LINK([ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #ifdef HAVE_WINSOCK2_H #include #endif #include -], [gethostname(NULL, 0);], [gl_cv_w32_gethostname=yes]) +]], [[gethostname(NULL, 0);]])], [gl_cv_w32_gethostname=yes]) LIBS="$gl_save_LIBS" ]) if test "$gl_cv_w32_gethostname" = "yes"; then @@ -34,9 +37,65 @@ AC_DEFUN([gl_FUNC_GETHOSTNAME], AC_SUBST([GETHOSTNAME_LIB]) if test "$ac_cv_func_gethostname" = no; then - AC_LIBOBJ([gethostname]) HAVE_GETHOSTNAME=0 - gl_PREREQ_GETHOSTNAME + fi + + gl_PREREQ_HOST_NAME_MAX +]) + +# Provide HOST_NAME_MAX when lacks it. +AC_DEFUN([gl_PREREQ_HOST_NAME_MAX], [ + 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 +], + [dnl The system does not define MAXHOSTNAMELEN in any of the common + dnl headers. Use a safe fallback. + gl_cv_decl_HOST_NAME_MAX=256 + ]) + 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 ])