Fix a test failure from a clang that masquerades as gcc 13.
[gnulib.git] / m4 / mountlist.m4
blobff414e66a6d867e4ce9cda36c9998b915dbb3c2b
1 # mountlist.m4
2 # serial 17
3 dnl Copyright (C) 2002-2006, 2009-2024 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.
8 dnl From Jim Meyering.
10 AC_PREREQ([2.60])
12 AC_DEFUN([gl_MOUNTLIST],
14   AC_REQUIRE([AC_CANONICAL_HOST])
15   AC_CHECK_FUNCS([listmntent])
16   AC_CHECK_HEADERS_ONCE([sys/param.h sys/statvfs.h])
18   # We must include grp.h before ucred.h on OSF V4.0, since ucred.h uses
19   # NGROUPS (as the array dimension for a struct member) without a definition.
20   AC_CHECK_HEADERS([sys/ucred.h], [], [], [#include <grp.h>])
22   AC_CHECK_HEADERS([sys/mount.h], [], [],
23     [AC_INCLUDES_DEFAULT
24      [#if HAVE_SYS_PARAM_H
25        #include <sys/param.h>
26       #endif
27     ]])
29   AC_CHECK_HEADERS([mntent.h sys/fs_types.h])
30   getfsstat_includes="\
31 $ac_includes_default
32 #if HAVE_SYS_PARAM_H
33 # include <sys/param.h> /* needed by powerpc-apple-darwin1.3.7 */
34 #endif
35 #if HAVE_SYS_UCRED_H
36 # include <grp.h> /* needed for definition of NGROUPS */
37 # include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */
38 #endif
39 #if HAVE_SYS_MOUNT_H
40 # include <sys/mount.h>
41 #endif
42 #if HAVE_SYS_FS_TYPES_H
43 # include <sys/fs_types.h> /* needed by powerpc-apple-darwin1.3.7 */
44 #endif
46   AC_CHECK_MEMBERS([struct fsstat.f_fstypename],,,[$getfsstat_includes])
48   # Determine how to get the list of mounted file systems.
49   ac_list_mounted_fs=
51   # If the getmntent function is available but not in the standard library,
52   # make sure LIBS contains the appropriate -l option.
53   AC_FUNC_GETMNTENT
55   if test -z "$ac_list_mounted_fs"; then
56     # AIX.
57     AC_CACHE_CHECK([for mntctl function and struct vmount],
58       [fu_cv_sys_mounted_vmount],
59       [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <fshelp.h>]])],
60          [fu_cv_sys_mounted_vmount=yes],
61          [fu_cv_sys_mounted_vmount=no])])
62     if test $fu_cv_sys_mounted_vmount = yes; then
63       ac_list_mounted_fs=found
64       AC_DEFINE([MOUNTED_VMOUNT], [1],
65         [Define if there is a function named mntctl that can be used to read
66          the list of mounted file systems, and there is a system header file
67          that declares 'struct vmount'.  (AIX)])
68     fi
69   fi
71   if test $ac_cv_func_getmntent = yes; then
73     # This system has the getmntent function.
74     # Determine whether it's the one-argument variant or the two-argument one.
76     if test -z "$ac_list_mounted_fs"; then
77       # glibc, HP-UX, IRIX, Cygwin, Android, also (obsolete) 4.3BSD, SunOS.
78       AC_CACHE_CHECK([for one-argument getmntent function],
79         [fu_cv_sys_mounted_getmntent1],
80         [AC_COMPILE_IFELSE(
81            [AC_LANG_PROGRAM([[
82 /* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */
83 #include <stdio.h>
85 #include <mntent.h>
86 #if defined __ANDROID__        /* Android */
87 # undef MOUNTED
88 # define MOUNTED "/proc/mounts"
89 #elif !defined MOUNTED
90 # if defined _PATH_MOUNTED     /* GNU libc  */
91 #  define MOUNTED _PATH_MOUNTED
92 # endif
93 # if defined MNT_MNTTAB        /* HP-UX.  */
94 #  define MOUNTED MNT_MNTTAB
95 # endif
96 #endif
97 ]],
98               [[struct mntent *mnt = 0; char *table = MOUNTED;
99                 if (sizeof mnt && sizeof table) return 0;
100               ]])],
101            [fu_cv_sys_mounted_getmntent1=yes],
102            [fu_cv_sys_mounted_getmntent1=no])
103         ])
104       if test $fu_cv_sys_mounted_getmntent1 = yes; then
105         ac_list_mounted_fs=found
106         AC_DEFINE([MOUNTED_GETMNTENT1], [1],
107           [Define if there is a function named getmntent for reading the list
108            of mounted file systems, and that function takes a single argument.
109            (4.3BSD, SunOS, HP-UX, Irix)])
110         gl_CHECK_FUNCS_ANDROID([setmntent],
111           [[#include <stdio.h>
112             #include <mntent.h>
113           ]])
114         gl_CHECK_FUNCS_ANDROID([endmntent],
115           [[#include <stdio.h>
116             #include <mntent.h>
117           ]])
118         gl_CHECK_FUNCS_ANDROID([hasmntopt],
119           [[#include <stdio.h>
120             #include <mntent.h>
121           ]])
122       fi
123     fi
125     if test -z "$ac_list_mounted_fs"; then
126       # Solaris >= 8.
127       AC_CACHE_CHECK([for getextmntent function],
128         [fu_cv_sys_mounted_getextmntent],
129         [AC_EGREP_HEADER([getextmntent], [sys/mnttab.h],
130            [fu_cv_sys_mounted_getextmntent=yes],
131            [fu_cv_sys_mounted_getextmntent=no])])
132       if test $fu_cv_sys_mounted_getextmntent = yes; then
133         ac_list_mounted_fs=found
134         AC_DEFINE([MOUNTED_GETEXTMNTENT], [1],
135           [Define if there is a function named getextmntent for reading the list
136            of mounted file systems.  (Solaris)])
137       fi
138     fi
140     if test -z "$ac_list_mounted_fs"; then
141       # Solaris < 8, also (obsolete) SVR4.
142       # Solaris >= 8 has the two-argument getmntent but is already handled above.
143       AC_CACHE_CHECK([for two-argument getmntent function],
144         [fu_cv_sys_mounted_getmntent2],
145         [AC_EGREP_HEADER([getmntent], [sys/mnttab.h],
146            [fu_cv_sys_mounted_getmntent2=yes],
147            [fu_cv_sys_mounted_getmntent2=no])
148         ])
149       if test $fu_cv_sys_mounted_getmntent2 = yes; then
150         ac_list_mounted_fs=found
151         AC_DEFINE([MOUNTED_GETMNTENT2], [1],
152           [Define if there is a function named getmntent for reading the list of
153            mounted file systems, and that function takes two arguments.  (SVR4)])
154         AC_CHECK_FUNCS([hasmntopt])
155       fi
156     fi
158   fi
160   if test -z "$ac_list_mounted_fs"; then
161     # OSF/1, also (obsolete) Apple Darwin 1.3.
162     # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
164     AC_CACHE_CHECK([for getfsstat function],
165       [fu_cv_sys_mounted_getfsstat],
166       [AC_LINK_IFELSE(
167          [AC_LANG_PROGRAM([[
168 #include <sys/types.h>
169 #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
170 # define FS_TYPE(Ent) ((Ent).f_fstypename)
171 #else
172 # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
173 #endif
174 $getfsstat_includes
175             ]],
176             [[struct statfs *stats;
177               int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
178               char *t = FS_TYPE (*stats);
179             ]])],
180          [fu_cv_sys_mounted_getfsstat=yes],
181          [fu_cv_sys_mounted_getfsstat=no])
182       ])
183     if test $fu_cv_sys_mounted_getfsstat = yes; then
184       ac_list_mounted_fs=found
185       AC_DEFINE([MOUNTED_GETFSSTAT], [1],
186         [Define if there is a function named getfsstat for reading the
187          list of mounted file systems.  (DEC Alpha running OSF/1)])
188     fi
189   fi
191   if test -z "$ac_list_mounted_fs"; then
192     # (obsolete) SVR3
193     AC_CACHE_CHECK([for FIXME existence of three headers],
194       [fu_cv_sys_mounted_fread_fstyp],
195       [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
196 #include <sys/statfs.h>
197 #include <sys/fstyp.h>
198 #include <mnttab.h>
199 ]])],
200          [fu_cv_sys_mounted_fread_fstyp=yes],
201          [fu_cv_sys_mounted_fread_fstyp=no])
202       ])
203     if test $fu_cv_sys_mounted_fread_fstyp = yes; then
204       ac_list_mounted_fs=found
205       AC_DEFINE([MOUNTED_FREAD_FSTYP], [1],
206         [Define if (like SVR2) there is no specific function for reading the
207          list of mounted file systems, and your system has these header files:
208          <sys/fstyp.h> and <sys/statfs.h>.  (SVR3)])
209     fi
210   fi
212   if test -z "$ac_list_mounted_fs"; then
213     # Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, also (obsolete) 4.4BSD.
214     # OSF/1 also has getmntinfo but is already handled above.
215     # We cannot use AC_CHECK_FUNCS([getmntinfo]) here, because at the linker
216     # level the function is sometimes called getmntinfo64 or getmntinfo$INODE64
217     # on Mac OS X, __getmntinfo13 on NetBSD and Minix, _F64_getmntinfo on OSF/1.
218     AC_CACHE_CHECK([for getmntinfo function],
219       [fu_cv_sys_mounted_getmntinfo],
220       [AC_LINK_IFELSE(
221          [AC_LANG_PROGRAM([[
222 #if HAVE_SYS_PARAM_H
223 # include <sys/param.h>
224 #endif
225 #include <sys/types.h>
226 #if HAVE_SYS_MOUNT_H
227 # include <sys/mount.h>
228 #endif
229 #if HAVE_SYS_STATVFS_H
230 # include <sys/statvfs.h>
231 #endif
232 #include <stdlib.h>
233             ]],
234             [[int count = getmntinfo (NULL, MNT_WAIT);
235             ]])],
236          [fu_cv_sys_mounted_getmntinfo=yes],
237          [fu_cv_sys_mounted_getmntinfo=no])
238       ])
239     if test $fu_cv_sys_mounted_getmntinfo = yes; then
240       AC_CACHE_CHECK([whether getmntinfo returns statvfs structures],
241         [fu_cv_sys_mounted_getmntinfo2],
242         [AC_COMPILE_IFELSE(
243            [AC_LANG_PROGRAM([[
244 #if HAVE_SYS_PARAM_H
245 # include <sys/param.h>
246 #endif
247 #include <sys/types.h>
248 #if HAVE_SYS_MOUNT_H
249 # include <sys/mount.h>
250 #endif
251 #if HAVE_SYS_STATVFS_H
252 # include <sys/statvfs.h>
253 #endif
254 extern
255 #ifdef __cplusplus
257 #endif
258 int getmntinfo (struct statfs **, int);
259               ]], [[]])],
260            [fu_cv_sys_mounted_getmntinfo2=no],
261            [fu_cv_sys_mounted_getmntinfo2=yes])
262         ])
263       if test $fu_cv_sys_mounted_getmntinfo2 = no; then
264         # Mac OS X, FreeBSD, OpenBSD, also (obsolete) 4.4BSD.
265         ac_list_mounted_fs=found
266         AC_DEFINE([MOUNTED_GETMNTINFO], [1],
267           [Define if there is a function named getmntinfo for reading the
268            list of mounted file systems and it returns an array of
269            'struct statfs'.  (4.4BSD, Darwin)])
270       else
271         # NetBSD, Minix.
272         ac_list_mounted_fs=found
273         AC_DEFINE([MOUNTED_GETMNTINFO2], [1],
274           [Define if there is a function named getmntinfo for reading the
275            list of mounted file systems and it returns an array of
276            'struct statvfs'.  (NetBSD 3.0)])
277       fi
278     fi
279   fi
281   if test -z "$ac_list_mounted_fs"; then
282     # Haiku, also (obsolete) BeOS.
283     AC_CHECK_FUNCS([next_dev fs_stat_dev])
284     AC_CHECK_HEADERS([fs_info.h])
285     AC_CACHE_CHECK([for BEOS mounted file system support functions],
286       [fu_cv_sys_mounted_fs_stat_dev],
287       [if test $ac_cv_header_fs_info_h = yes \
288           && test $ac_cv_func_next_dev = yes \
289           && test $ac_cv_func_fs_stat_dev = yes; then
290          fu_cv_sys_mounted_fs_stat_dev=yes
291        else
292          fu_cv_sys_mounted_fs_stat_dev=no
293        fi
294       ])
295     if test $fu_cv_sys_mounted_fs_stat_dev = yes; then
296       ac_list_mounted_fs=found
297       AC_DEFINE([MOUNTED_FS_STAT_DEV], [1],
298         [Define if there are functions named next_dev and fs_stat_dev for
299          reading the list of mounted file systems.  (BeOS)])
300     fi
301   fi
303   if test -z "$ac_list_mounted_fs"; then
304     # Interix / BSD alike statvfs
305     # the code is really interix specific, so make sure, we're on it.
306     case "$host" in
307       *-interix*)
308         AC_CHECK_FUNCS([statvfs])
309         if test $ac_cv_func_statvfs = yes; then
310           ac_list_mounted_fs=found
311           AC_DEFINE([MOUNTED_INTERIX_STATVFS], [1],
312             [Define if we are on interix, and ought to use statvfs plus
313              some special knowledge on where mounted file systems can be
314              found. (Interix)])
315         fi
316         ;;
317     esac
318   fi
320   if test -z "$ac_list_mounted_fs"; then
321     AC_MSG_ERROR([could not determine how to read list of mounted file systems])
322     # FIXME -- no need to abort building the whole package
323     # Can't build mountlist.c or anything that needs its functions
324   fi
326   if test $ac_list_mounted_fs = found; then
327     gl_cv_list_mounted_fs=yes
328   else
329     gl_cv_list_mounted_fs=no
330   fi
333 # Prerequisites of lib/mountlist.c not done by gl_MOUNTLIST.
334 AC_DEFUN([gl_PREREQ_MOUNTLIST_EXTRA],
336   dnl Note gl_MOUNTLIST checks for mntent.h, not sys/mntent.h.
337   AC_CHECK_HEADERS([sys/mntent.h])
338   AC_HEADER_MAJOR()dnl for use of makedev ()
339   gl_FSTYPENAME
342 # Replace Autoconf's AC_FUNC_GETMNTENT to omit checks that are unnecessary
343 # nowadays.
344 AC_DEFUN([AC_FUNC_GETMNTENT],
346   # getmntent is in the standard C library on most systems, but in -lgen on
347   # Unixware.
348   AC_SEARCH_LIBS([getmntent], [gen])
349   AC_CHECK_FUNCS([getmntent])