Debian Codegraph @

m4/getdomainname.m4

raw
1 # getdomainname.m4
2 # serial 16
3 dnl Copyright (C) 2002-2003, 2008-2026 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 AC_DEFUN([gl_FUNC_GETDOMAINNAME],
10 [
11 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
12 AC_REQUIRE([gl_SYS_SOCKET_H])dnl for HAVE_SYS_SOCKET_H
13 AC_REQUIRE([gl_NETDB_H])dnl for HAVE_NETDB_H
14
15 dnl Persuade glibc <unistd.h> to declare getdomainname().
16 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
17
18 dnl Where is getdomainname() defined?
19 dnl - On Solaris, it is in libnsl. But this function is not declared and
20 dnl is discouraged, see
21 dnl <https://web.archive.org/web/20100121182558/http://www.sun.com/software/solaris/programs/abi/appcert_faq.xml#q18>.
22 dnl We need to avoid a collision with this function.
23 dnl - Otherwise it is in libc.
24 gl_CHECK_FUNCS_ANDROID([getdomainname], [[#include <unistd.h>]])
25 if test $ac_cv_func_getdomainname = no; then
26 AC_CACHE_CHECK([for getdomainname in -lnsl],
27 [gl_cv_func_getdomainname_in_libnsl],
28 [gl_cv_func_getdomainname_in_libnsl=no
29 gl_saved_LIBS="$LIBS"
30 LIBS="$LIBS -lnsl"
31 AC_LINK_IFELSE(
32 [AC_LANG_PROGRAM(
33 [[#include <stddef.h>
34 extern
35 #ifdef __cplusplus
36 "C"
37 #endif
38 int getdomainname (char *, size_t);
39 ]],
40 [[getdomainname(NULL, 0);]])],
41 [gl_cv_func_getdomainname_in_libnsl=yes])
42 LIBS="$gl_saved_LIBS"
43 ])
44 fi
45
46 dnl What about the declaration?
47 dnl - It's int getdomainname(char *, size_t) on glibc, NetBSD, OpenBSD.
48 dnl - It's int getdomainname(char *, int) on Mac OS X, FreeBSD, AIX.
49 AC_CHECK_DECLS([getdomainname], , ,
50 [[#include <sys/types.h>
51 #ifdef HAVE_SYS_SOCKET_H
52 #include <sys/socket.h>
53 #endif
54 #ifdef HAVE_NETDB_H
55 #include <netdb.h>
56 #endif
57 #include <unistd.h>
58 ]])
59 AC_CACHE_CHECK([for getdomainname's second argument type],
60 [gl_cv_decl_getdomainname_argtype2],
61 [if test $ac_cv_have_decl_getdomainname; then
62 AC_COMPILE_IFELSE(
63 [AC_LANG_PROGRAM(
64 [[#include <sys/types.h>
65 #ifdef HAVE_SYS_SOCKET_H
66 #include <sys/socket.h>
67 #endif
68 #ifdef HAVE_NETDB_H
69 #include <netdb.h>
70 #endif
71 #include <unistd.h>
72 extern
73 #ifdef __cplusplus
74 "C"
75 #endif
76 int getdomainname (char *, int);
77 ]],
78 [[]])],
79 [gl_cv_decl_getdomainname_argtype2='int'],
80 [gl_cv_decl_getdomainname_argtype2='size_t'])
81 else
82 gl_cv_decl_getdomainname_argtype2='int'
83 fi
84 ])
85
86 if test $ac_cv_have_decl_getdomainname = no; then
87 HAVE_DECL_GETDOMAINNAME=0
88 fi
89
90 if { test $ac_cv_func_getdomainname = yes \
91 && test $gl_cv_decl_getdomainname_argtype2 != size_t; \
92 } \
93 || case "$gl_cv_onwards_func_getdomainname" in \
94 future*) true ;; \
95 *) false ;; \
96 esac \
97 || test "$gl_cv_func_getdomainname_in_libnsl" = yes; then
98 REPLACE_GETDOMAINNAME=1
99 fi
100 ])
101
102 # Prerequisites of lib/getdomainname.c.
103 AC_DEFUN([gl_PREREQ_GETDOMAINNAME], [
104 if test $ac_cv_func_getdomainname = yes; then
105 AC_DEFINE([HAVE_GETDOMAINNAME], [1],
106 [Define if the getdomainname() function is present and can be used.])
107 fi
108 AC_CHECK_HEADERS([sys/systeminfo.h])
109 AC_CHECK_FUNCS([sysinfo])
110 ])