mbsnrtowcs: Work around Solaris 11.4 bug.
[gnulib.git] / m4 / ls-mntd-fs.m4
blob643d0cefd69287c3ee77e6ef9d65c6ef5d2dbf43
1 # serial 34
2 # How to list mounted file systems.
4 # Copyright (C) 1998-2004, 2006, 2009-2018 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.
11 dnl
12 dnl This is not pretty.  I've just taken the autoconf code and wrapped
13 dnl it in an AC_DEFUN and made some other fixes.
14 dnl
16 # Replace Autoconf's AC_FUNC_GETMNTENT to work around a bug in Autoconf
17 # through Autoconf 2.59.  We can remove this once we assume Autoconf 2.60
18 # or later.
19 AC_DEFUN([AC_FUNC_GETMNTENT],
21   # getmntent is in the standard C library on UNICOS, in -lsun on Irix 4,
22   # -lseq on Dynix/PTX, -lgen on Unixware.
23   AC_SEARCH_LIBS([getmntent], [sun seq 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   # This test must precede the ones for getmntent because Unicos-9 is
72   # reported to have the getmntent function, but its support is incompatible
73   # with other getmntent implementations.
75   # NOTE: Normally, I wouldn't use a check for system type as I've done for
76   # 'CRAY' below since that goes against the whole autoconf philosophy.  But
77   # I think there is too great a chance that some non-Cray system has a
78   # function named listmntent to risk the false positive.
80   if test -z "$ac_list_mounted_fs"; then
81     # (obsolete) Cray UNICOS 9
82     AC_CACHE_CHECK([for listmntent of Cray/Unicos-9],
83       [fu_cv_sys_mounted_cray_listmntent],
84       [fu_cv_sys_mounted_cray_listmntent=no
85         AC_EGREP_CPP([yes],
86           [#ifdef _CRAY
87 yes
88 #endif
89           ], [test $ac_cv_func_listmntent = yes \
90               && fu_cv_sys_mounted_cray_listmntent=yes]
91         )
92       ])
93     if test $fu_cv_sys_mounted_cray_listmntent = yes; then
94       ac_list_mounted_fs=found
95       AC_DEFINE([MOUNTED_LISTMNTENT], [1],
96         [Define if there is a function named listmntent that can be used to
97          list all mounted file systems.  (UNICOS)])
98     fi
99   fi
101   if test -z "$ac_list_mounted_fs"; then
102     # AIX.
103     AC_CACHE_CHECK([for mntctl function and struct vmount],
104       [fu_cv_sys_mounted_vmount],
105       [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <fshelp.h>]])],
106          [fu_cv_sys_mounted_vmount=yes],
107          [fu_cv_sys_mounted_vmount=no])])
108     if test $fu_cv_sys_mounted_vmount = yes; then
109       ac_list_mounted_fs=found
110       AC_DEFINE([MOUNTED_VMOUNT], [1],
111         [Define if there is a function named mntctl that can be used to read
112          the list of mounted file systems, and there is a system header file
113          that declares 'struct vmount'.  (AIX)])
114     fi
115   fi
117   if test $ac_cv_func_getmntent = yes; then
119     # This system has the getmntent function.
120     # Determine whether it's the one-argument variant or the two-argument one.
122     if test -z "$ac_list_mounted_fs"; then
123       # glibc, HP-UX, IRIX, Cygwin, Android, also (obsolete) 4.3BSD, SunOS, Dynix.
124       AC_CACHE_CHECK([for one-argument getmntent function],
125         [fu_cv_sys_mounted_getmntent1],
126         [AC_COMPILE_IFELSE(
127            [AC_LANG_PROGRAM([[
128 /* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */
129 #include <stdio.h>
131 #include <mntent.h>
132 #if !defined MOUNTED
133 # if defined _PATH_MOUNTED      /* GNU libc  */
134 #  define MOUNTED _PATH_MOUNTED
135 # endif
136 # if defined MNT_MNTTAB /* HP-UX.  */
137 #  define MOUNTED MNT_MNTTAB
138 # endif
139 # if defined MNTTABNAME /* Dynix.  */
140 #  define MOUNTED MNTTABNAME
141 # endif
142 #endif
144               [[struct mntent *mnt = 0; char *table = MOUNTED;
145                 if (sizeof mnt && sizeof table) return 0;
146               ]])],
147            [fu_cv_sys_mounted_getmntent1=yes],
148            [fu_cv_sys_mounted_getmntent1=no])
149         ])
150       if test $fu_cv_sys_mounted_getmntent1 = yes; then
151         ac_list_mounted_fs=found
152         AC_DEFINE([MOUNTED_GETMNTENT1], [1],
153           [Define if there is a function named getmntent for reading the list
154            of mounted file systems, and that function takes a single argument.
155            (4.3BSD, SunOS, HP-UX, Dynix, Irix)])
156         AC_CHECK_FUNCS([hasmntopt])
157       fi
158     fi
160     if test -z "$ac_list_mounted_fs"; then
161       # Solaris >= 8.
162       AC_CACHE_CHECK([for getextmntent function],
163         [fu_cv_sys_mounted_getextmntent],
164         [AC_EGREP_HEADER([getextmntent], [sys/mnttab.h],
165            [fu_cv_sys_mounted_getextmntent=yes],
166            [fu_cv_sys_mounted_getextmntent=no])])
167       if test $fu_cv_sys_mounted_getextmntent = yes; then
168         ac_list_mounted_fs=found
169         AC_DEFINE([MOUNTED_GETEXTMNTENT], [1],
170           [Define if there is a function named getextmntent for reading the list
171            of mounted file systems.  (Solaris)])
172       fi
173     fi
175     if test -z "$ac_list_mounted_fs"; then
176       # Solaris < 8, also (obsolete) SVR4.
177       # Solaris >= 8 has the two-argument getmntent but is already handled above.
178       AC_CACHE_CHECK([for two-argument getmntent function],
179         [fu_cv_sys_mounted_getmntent2],
180         [AC_EGREP_HEADER([getmntent], [sys/mnttab.h],
181            [fu_cv_sys_mounted_getmntent2=yes],
182            [fu_cv_sys_mounted_getmntent2=no])
183         ])
184       if test $fu_cv_sys_mounted_getmntent2 = yes; then
185         ac_list_mounted_fs=found
186         AC_DEFINE([MOUNTED_GETMNTENT2], [1],
187           [Define if there is a function named getmntent for reading the list of
188            mounted file systems, and that function takes two arguments.  (SVR4)])
189         AC_CHECK_FUNCS([hasmntopt])
190       fi
191     fi
193   fi
195   if test -z "$ac_list_mounted_fs"; then
196     # OSF/1, also (obsolete) Apple Darwin 1.3.
197     # powerpc-apple-darwin1.3.7 needs sys/param.h sys/ucred.h sys/fs_types.h
199     AC_CACHE_CHECK([for getfsstat function],
200       [fu_cv_sys_mounted_getfsstat],
201       [AC_LINK_IFELSE(
202          [AC_LANG_PROGRAM([[
203 #include <sys/types.h>
204 #if HAVE_STRUCT_FSSTAT_F_FSTYPENAME
205 # define FS_TYPE(Ent) ((Ent).f_fstypename)
206 #else
207 # define FS_TYPE(Ent) mnt_names[(Ent).f_type]
208 #endif
209 $getfsstat_includes
210             ]],
211             [[struct statfs *stats;
212               int numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
213               char *t = FS_TYPE (*stats);
214             ]])],
215          [fu_cv_sys_mounted_getfsstat=yes],
216          [fu_cv_sys_mounted_getfsstat=no])
217       ])
218     if test $fu_cv_sys_mounted_getfsstat = yes; then
219       ac_list_mounted_fs=found
220       AC_DEFINE([MOUNTED_GETFSSTAT], [1],
221         [Define if there is a function named getfsstat for reading the
222          list of mounted file systems.  (DEC Alpha running OSF/1)])
223     fi
224   fi
226   if test -z "$ac_list_mounted_fs"; then
227     # (obsolete) SVR3
228     AC_CACHE_CHECK([for FIXME existence of three headers],
229       [fu_cv_sys_mounted_fread_fstyp],
230       [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
231 #include <sys/statfs.h>
232 #include <sys/fstyp.h>
233 #include <mnttab.h>
234 ]])],
235          [fu_cv_sys_mounted_fread_fstyp=yes],
236          [fu_cv_sys_mounted_fread_fstyp=no])
237       ])
238     if test $fu_cv_sys_mounted_fread_fstyp = yes; then
239       ac_list_mounted_fs=found
240       AC_DEFINE([MOUNTED_FREAD_FSTYP], [1],
241         [Define if (like SVR2) there is no specific function for reading the
242          list of mounted file systems, and your system has these header files:
243          <sys/fstyp.h> and <sys/statfs.h>.  (SVR3)])
244     fi
245   fi
247   if test -z "$ac_list_mounted_fs"; then
248     # Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, also (obsolete) 4.4BSD.
249     # OSF/1 also has getmntinfo but is already handled above.
250     # We cannot use AC_CHECK_FUNCS([getmntinfo]) here, because at the linker
251     # level the function is sometimes called getmntinfo64 or getmntinfo$INODE64
252     # on Mac OS X, __getmntinfo13 on NetBSD and Minix, _F64_getmntinfo on OSF/1.
253     AC_CACHE_CHECK([for getmntinfo function],
254       [fu_cv_sys_mounted_getmntinfo],
255       [AC_LINK_IFELSE(
256          [AC_LANG_PROGRAM([[
257 #if HAVE_SYS_PARAM_H
258 # include <sys/param.h>
259 #endif
260 #include <sys/types.h>
261 #if HAVE_SYS_MOUNT_H
262 # include <sys/mount.h>
263 #endif
264 #if HAVE_SYS_STATVFS_H
265 # include <sys/statvfs.h>
266 #endif
267 #include <stdlib.h>
268             ]],
269             [[int count = getmntinfo (NULL, MNT_WAIT);
270             ]])],
271          [fu_cv_sys_mounted_getmntinfo=yes],
272          [fu_cv_sys_mounted_getmntinfo=no])
273       ])
274     if test $fu_cv_sys_mounted_getmntinfo = yes; then
275       AC_CACHE_CHECK([whether getmntinfo returns statvfs structures],
276         [fu_cv_sys_mounted_getmntinfo2],
277         [AC_COMPILE_IFELSE(
278            [AC_LANG_PROGRAM([[
279 #if HAVE_SYS_PARAM_H
280 # include <sys/param.h>
281 #endif
282 #include <sys/types.h>
283 #if HAVE_SYS_MOUNT_H
284 # include <sys/mount.h>
285 #endif
286 #if HAVE_SYS_STATVFS_H
287 # include <sys/statvfs.h>
288 #endif
289 extern
290 #ifdef __cplusplus
292 #endif
293 int getmntinfo (struct statfs **, int);
294               ]], [])],
295            [fu_cv_sys_mounted_getmntinfo2=no],
296            [fu_cv_sys_mounted_getmntinfo2=yes])
297         ])
298       if test $fu_cv_sys_mounted_getmntinfo2 = no; then
299         # Mac OS X, FreeBSD, OpenBSD, also (obsolete) 4.4BSD.
300         ac_list_mounted_fs=found
301         AC_DEFINE([MOUNTED_GETMNTINFO], [1],
302           [Define if there is a function named getmntinfo for reading the
303            list of mounted file systems and it returns an array of
304            'struct statfs'.  (4.4BSD, Darwin)])
305       else
306         # NetBSD, Minix.
307         ac_list_mounted_fs=found
308         AC_DEFINE([MOUNTED_GETMNTINFO2], [1],
309           [Define if there is a function named getmntinfo for reading the
310            list of mounted file systems and it returns an array of
311            'struct statvfs'.  (NetBSD 3.0)])
312       fi
313     fi
314   fi
316   if test -z "$ac_list_mounted_fs"; then
317     # (obsolete) Ultrix.
318     AC_CACHE_CHECK([for getmnt function],
319       [fu_cv_sys_mounted_getmnt],
320       [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
321 #include <sys/fs_types.h>
322 #include <sys/mount.h>]])],
323          [fu_cv_sys_mounted_getmnt=yes],
324          [fu_cv_sys_mounted_getmnt=no])
325       ])
326     if test $fu_cv_sys_mounted_getmnt = yes; then
327       ac_list_mounted_fs=found
328       AC_DEFINE([MOUNTED_GETMNT], [1],
329         [Define if there is a function named getmnt for reading the list of
330          mounted file systems.  (Ultrix)])
331     fi
332   fi
334   if test -z "$ac_list_mounted_fs"; then
335     # Haiku, also (obsolete) BeOS.
336     AC_CHECK_FUNCS([next_dev fs_stat_dev])
337     AC_CHECK_HEADERS([fs_info.h])
338     AC_CACHE_CHECK([for BEOS mounted file system support functions],
339       [fu_cv_sys_mounted_fs_stat_dev],
340       [if test $ac_cv_header_fs_info_h = yes \
341           && test $ac_cv_func_next_dev = yes \
342           && test $ac_cv_func_fs_stat_dev = yes; then
343          fu_cv_sys_mounted_fs_stat_dev=yes
344        else
345          fu_cv_sys_mounted_fs_stat_dev=no
346        fi
347       ])
348     if test $fu_cv_sys_mounted_fs_stat_dev = yes; then
349       ac_list_mounted_fs=found
350       AC_DEFINE([MOUNTED_FS_STAT_DEV], [1],
351         [Define if there are functions named next_dev and fs_stat_dev for
352          reading the list of mounted file systems.  (BeOS)])
353     fi
354   fi
356   if test -z "$ac_list_mounted_fs"; then
357     # (obsolete) SVR2.
358     AC_CACHE_CHECK([whether it is possible to resort to fread on /etc/mnttab],
359       [fu_cv_sys_mounted_fread],
360       [AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <mnttab.h>]])],
361          [fu_cv_sys_mounted_fread=yes],
362          [fu_cv_sys_mounted_fread=no])
363       ])
364     if test $fu_cv_sys_mounted_fread = yes; then
365       ac_list_mounted_fs=found
366       AC_DEFINE([MOUNTED_FREAD], [1],
367         [Define if there is no specific function for reading the list of
368          mounted file systems.  fread will be used to read /etc/mnttab.
369          (SVR2) ])
370     fi
371   fi
373   if test -z "$ac_list_mounted_fs"; then
374     # Interix / BSD alike statvfs
375     # the code is really interix specific, so make sure, we're on it.
376     case "$host" in
377       *-interix*)
378         AC_CHECK_FUNCS([statvfs])
379         if test $ac_cv_func_statvfs = yes; then
380           ac_list_mounted_fs=found
381           AC_DEFINE([MOUNTED_INTERIX_STATVFS], [1],
382             [Define if we are on interix, and ought to use statvfs plus
383              some special knowledge on where mounted file systems can be
384              found. (Interix)])
385         fi
386         ;;
387     esac
388   fi
390   if test -z "$ac_list_mounted_fs"; then
391     AC_MSG_ERROR([could not determine how to read list of mounted file systems])
392     # FIXME -- no need to abort building the whole package
393     # Can't build mountlist.c or anything that needs its functions
394   fi
396   AS_IF([test $ac_list_mounted_fs = found], [$1], [$2])