1 # getdomainname.m4 serial 10
2 dnl Copyright (C) 2002-2003, 2008-2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_GETDOMAINNAME],
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10 AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H
11 AC_REQUIRE([gl_HEADER_NETDB])dnl for HAVE_NETDB_H
13 dnl Persuade glibc <unistd.h> to declare getdomainname().
14 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
16 dnl Where is getdomainname() defined?
17 dnl - On Solaris, it is in libnsl. But this function is not declared and
18 dnl is discouraged, see
19 dnl <https://web.archive.org/web/20100121182558/http://www.sun.com/software/solaris/programs/abi/appcert_faq.xml#q18>.
20 dnl We need to avoid a collision with this function.
21 dnl - Otherwise it is in libc.
22 AC_CHECK_FUNCS([getdomainname], , [
23 AC_CACHE_CHECK([for getdomainname in -lnsl],
24 [gl_cv_func_getdomainname_in_libnsl],
25 [gl_cv_func_getdomainname_in_libnsl=no
35 int getdomainname (char *, size_t);
37 [[getdomainname(NULL, 0);]])],
38 [gl_cv_func_getdomainname_in_libnsl=yes])
43 dnl What about the declaration?
44 dnl - It's int getdomainname(char *, size_t) on glibc, NetBSD, OpenBSD.
45 dnl - It's int getdomainname(char *, int) on Mac OS X, FreeBSD, AIX, IRIX,
47 AC_CHECK_DECLS([getdomainname], , ,
48 [[#include <sys/types.h>
49 #ifdef HAVE_SYS_SOCKET_H
50 #include <sys/socket.h>
57 AC_CACHE_CHECK([for getdomainname's second argument type],
58 [gl_cv_decl_getdomainname_argtype2],
59 [if test $ac_cv_have_decl_getdomainname; then
62 [[#include <sys/types.h>
63 #ifdef HAVE_SYS_SOCKET_H
64 #include <sys/socket.h>
74 int getdomainname (char *, int);
77 [gl_cv_decl_getdomainname_argtype2='int'],
78 [gl_cv_decl_getdomainname_argtype2='size_t'])
80 gl_cv_decl_getdomainname_argtype2='int'
84 if test $ac_cv_have_decl_getdomainname = no; then
85 HAVE_DECL_GETDOMAINNAME=0
88 if { test $ac_cv_func_getdomainname = yes \
89 && test $gl_cv_decl_getdomainname_argtype2 != size_t; \
91 || test "$gl_cv_func_getdomainname_in_libnsl" = yes; then
92 REPLACE_GETDOMAINNAME=1
96 # Prerequisites of lib/getdomainname.c.
97 AC_DEFUN([gl_PREREQ_GETDOMAINNAME], [
98 if test $ac_cv_func_getdomainname = yes; then
99 AC_DEFINE([HAVE_GETDOMAINNAME], [1],
100 [Define if the getdomainname() function is present and can be used.])
102 AC_CHECK_HEADERS([sys/systeminfo.h])
103 AC_CHECK_FUNCS([sysinfo])