summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2023-01-19 09:58:01 +0100
committerLudovic Courtès <ludo@gnu.org>2023-01-19 09:58:01 +0100
commita43a8fd8bad9d48ec25569c8b7891f8ed465f3f9 (patch)
treec853fd853b31a1fbe655e2bc369667b46297e3d7 /m4
parent3bb08542d297980ea8ca9403e71d2fcd640c4877 (diff)
downloadguile-a43a8fd8bad9d48ec25569c8b7891f8ed465f3f9.tar.gz
Add Gnulib 'gethostname' module, needed for MinGW.
This is again from Gnulib v0.1-5703-g356a414e8c. * m4/gnulib-cache.m4: Add 'gethostname'.
Diffstat (limited to 'm4')
-rw-r--r--m4/gethostname.m4107
-rw-r--r--m4/gnulib-cache.m42
-rw-r--r--m4/gnulib-comp.m412
3 files changed, 121 insertions, 0 deletions
diff --git a/m4/gethostname.m4 b/m4/gethostname.m4
new file mode 100644
index 000000000..63f5f6369
--- /dev/null
+++ b/m4/gethostname.m4
@@ -0,0 +1,107 @@
+# gethostname.m4 serial 15
+dnl Copyright (C) 2002, 2008-2023 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 <limits.h>.
+AC_DEFUN([gl_FUNC_GETHOSTNAME],
+[
+ AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+ gl_PREREQ_SYS_H_WINSOCK2
+
+ dnl Where is gethostname() defined?
+ dnl - On native Windows, it is in ws2_32.dll.
+ dnl - Otherwise it is in libc.
+ GETHOSTNAME_LIB=
+ AC_CHECK_FUNCS([gethostname], , [
+ AC_CACHE_CHECK([for gethostname in winsock2.h and -lws2_32],
+ [gl_cv_w32_gethostname],
+ [gl_cv_w32_gethostname=no
+ gl_save_LIBS="$LIBS"
+ LIBS="$LIBS -lws2_32"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
+#include <stddef.h>
+]], [[gethostname(NULL, 0);]])], [gl_cv_w32_gethostname=yes])
+ LIBS="$gl_save_LIBS"
+ ])
+ if test "$gl_cv_w32_gethostname" = "yes"; then
+ GETHOSTNAME_LIB="-lws2_32"
+ fi
+ ])
+ AC_SUBST([GETHOSTNAME_LIB])
+
+ if test "$ac_cv_func_gethostname" = no; then
+ HAVE_GETHOSTNAME=0
+ fi
+
+ gl_PREREQ_HOST_NAME_MAX
+])
+
+# Provide HOST_NAME_MAX when <limits.h> lacks it.
+AC_DEFUN([gl_PREREQ_HOST_NAME_MAX], [
+ dnl - On most Unix systems, use MAXHOSTNAMELEN from <sys/param.h> instead.
+ dnl - On Solaris, Cygwin, BeOS, use MAXHOSTNAMELEN from <netdb.h> instead.
+ dnl - On mingw, use 256, because
+ dnl <https://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-gethostname> 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 <limits.h> using the usual technique, because
+ dnl gl_CHECK_NEXT_HEADERS does not work for <limits.h>. 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 <limits.h>
+#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 <limits.h>. Substitute it.
+ if test "$gl_cv_w32_gethostname" = yes; then
+ dnl mingw.
+ gl_cv_decl_HOST_NAME_MAX=256
+ else
+ AC_COMPUTE_INT([gl_cv_decl_HOST_NAME_MAX], [MAXHOSTNAMELEN], [
+#include <sys/types.h>
+#if HAVE_SYS_PARAM_H
+# include <sys/param.h>
+#endif
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+#if HAVE_NETDB_H
+# include <netdb.h>
+#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 <limits.h> does not define it.])
+ fi
+])
+
+# Prerequisites of lib/gethostname.c.
+AC_DEFUN([gl_PREREQ_GETHOSTNAME], [
+ if test "$gl_cv_w32_gethostname" != "yes"; then
+ AC_CHECK_FUNCS([uname])
+ fi
+])
diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4
index cb3a403df..90e798514 100644
--- a/m4/gnulib-cache.m4
+++ b/m4/gnulib-cache.m4
@@ -78,6 +78,7 @@
# func \
# gendocs \
# getaddrinfo \
+# gethostname \
# getlogin \
# getpeername \
# getsockname \
@@ -183,6 +184,7 @@ gl_MODULES([
func
gendocs
getaddrinfo
+ gethostname
getlogin
getpeername
getsockname
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4
index 215acc1e7..ffa5df6e9 100644
--- a/m4/gnulib-comp.m4
+++ b/m4/gnulib-comp.m4
@@ -109,6 +109,7 @@ AC_DEFUN([gl_EARLY],
# Code from module gendocs:
# Code from module getaddrinfo:
# Code from module getdtablesize:
+ # Code from module gethostname:
# Code from module getlogin:
# Code from module getpeername:
# Code from module getrandom:
@@ -422,6 +423,12 @@ AC_DEFUN([gl_INIT],
gl_CONDITIONAL([GL_COND_OBJ_GAI_STRERROR],
[test $HAVE_DECL_GAI_STRERROR = 0 || test $REPLACE_GAI_STRERROR = 1])
gl_NETDB_MODULE_INDICATOR([getaddrinfo])
+ gl_FUNC_GETHOSTNAME
+ gl_CONDITIONAL([GL_COND_OBJ_GETHOSTNAME], [test $HAVE_GETHOSTNAME = 0])
+ AM_COND_IF([GL_COND_OBJ_GETHOSTNAME], [
+ gl_PREREQ_GETHOSTNAME
+ ])
+ gl_UNISTD_MODULE_INDICATOR([gethostname])
gl_FUNC_GETLOGIN
gl_CONDITIONAL([GL_COND_OBJ_GETLOGIN], [test $HAVE_GETLOGIN = 0])
gl_UNISTD_MODULE_INDICATOR([getlogin])
@@ -1664,6 +1671,9 @@ AC_SUBST([LTALLOCA])
if test $HAVE_GETADDRINFO = 0 || test $REPLACE_GETADDRINFO = 1; then
func_gl_gnulib_m4code_sockets
fi
+ if test $HAVE_GETHOSTNAME = 0; then
+ func_gl_gnulib_m4code_sockets
+ fi
if test $HAVE_INET_NTOP = 0 || test $REPLACE_INET_NTOP = 1; then
func_gl_gnulib_m4code_netinet_in
fi
@@ -2113,6 +2123,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/gai_strerror.c
lib/getaddrinfo.c
lib/getdtablesize.c
+ lib/gethostname.c
lib/getlogin.c
lib/getpeername.c
lib/getrandom.c
@@ -2381,6 +2392,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/func.m4
m4/getaddrinfo.m4
m4/getdtablesize.m4
+ m4/gethostname.m4
m4/getlogin.m4
m4/getrandom.m4
m4/gnulib-common.m4