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