Extracted from fileutils/configure.in.
[gnulib.git] / m4 / fsusage.m4
1 #serial 1
2
3 # From fileutils/configure.in
4 # Determine how a program can obtain filesystems usage information.
5
6 AC_DEFUN(jm_FILE_SYSTEM_USAGE,
7 [
8
9 AC_CHECKING(how to get filesystem space usage)
10 space=no
11
12 # Perform only the link test since it seems there are no variants of the
13 # statvfs function.  This check is more than just AC_CHECK_FUNCS(statvfs)
14 # because that got a false positive on SCO OSR5.  Adding the declaration
15 # of a `struct statvfs' causes this test to fail (as it should) on such
16 # systems.  That system is reported to work fine with STAT_STATFS4 which
17 # is what it gets when this test fails.
18 if test $space = no; then
19   # SVR4
20   AC_CACHE_CHECK([for statvfs function (SVR4)], fu_cv_sys_stat_statvfs,
21                  [AC_TRY_LINK([#include <sys/types.h>
22 #include <sys/statvfs.h>],
23                               [struct statvfs fsd; statvfs (0, &fsd);],
24                               fu_cv_sys_stat_statvfs=yes,
25                               fu_cv_sys_stat_statvfs=no)])
26   if test $fu_cv_sys_stat_statvfs = yes; then
27     space=yes
28     AC_DEFINE(STAT_STATVFS, 1,
29               [  Define if there is a function named statvfs.  (SVR4)])
30   fi
31 fi
32
33 if test $space = no; then
34   # DEC Alpha running OSF/1
35   AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)])
36   AC_CACHE_VAL(fu_cv_sys_stat_statfs3_osf1,
37   [AC_TRY_RUN([
38 #include <sys/param.h>
39 #include <sys/types.h>
40 #include <sys/mount.h>
41   main ()
42   {
43     struct statfs fsd;
44     fsd.f_fsize = 0;
45     exit (statfs (".", &fsd, sizeof (struct statfs)));
46   }],
47   fu_cv_sys_stat_statfs3_osf1=yes,
48   fu_cv_sys_stat_statfs3_osf1=no,
49   fu_cv_sys_stat_statfs3_osf1=no)])
50   AC_MSG_RESULT($fu_cv_sys_stat_statfs3_osf1)
51   if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
52     space=yes
53     AC_DEFINE(STAT_STATFS3_OSF1, 1,
54               [   Define if  statfs takes 3 args.  (DEC Alpha running OSF/1)])
55   fi
56 fi
57
58 if test $space = no; then
59 # AIX
60   AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl
61 member (AIX, 4.3BSD)])
62   AC_CACHE_VAL(fu_cv_sys_stat_statfs2_bsize,
63   [AC_TRY_RUN([
64 #ifdef HAVE_SYS_PARAM_H
65 #include <sys/param.h>
66 #endif
67 #ifdef HAVE_SYS_MOUNT_H
68 #include <sys/mount.h>
69 #endif
70 #ifdef HAVE_SYS_VFS_H
71 #include <sys/vfs.h>
72 #endif
73   main ()
74   {
75   struct statfs fsd;
76   fsd.f_bsize = 0;
77   exit (statfs (".", &fsd));
78   }],
79   fu_cv_sys_stat_statfs2_bsize=yes,
80   fu_cv_sys_stat_statfs2_bsize=no,
81   fu_cv_sys_stat_statfs2_bsize=no)])
82   AC_MSG_RESULT($fu_cv_sys_stat_statfs2_bsize)
83   if test $fu_cv_sys_stat_statfs2_bsize = yes; then
84     space=yes
85     AC_DEFINE(STAT_STATFS2_BSIZE, 1,
86 [  Define if statfs takes 2 args and struct statfs has a field named f_bsize.
87    (4.3BSD, SunOS 4, HP-UX, AIX PS/2)])
88   fi
89 fi
90
91 if test $space = no; then
92 # SVR3
93   AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
94   AC_CACHE_VAL(fu_cv_sys_stat_statfs4,
95   [AC_TRY_RUN([#include <sys/types.h>
96 #include <sys/statfs.h>
97   main ()
98   {
99   struct statfs fsd;
100   exit (statfs (".", &fsd, sizeof fsd, 0));
101   }],
102     fu_cv_sys_stat_statfs4=yes,
103     fu_cv_sys_stat_statfs4=no,
104     fu_cv_sys_stat_statfs4=no)])
105   AC_MSG_RESULT($fu_cv_sys_stat_statfs4)
106   if test $fu_cv_sys_stat_statfs4 = yes; then
107     space=yes
108     AC_DEFINE(STAT_STATFS4, 1,
109               [  Define if statfs takes 4 args.  (SVR3, Dynix, Irix, Dolphin)])
110   fi
111 fi
112
113 if test $space = no; then
114 # 4.4BSD and NetBSD
115   AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl
116 member (4.4BSD and NetBSD)])
117   AC_CACHE_VAL(fu_cv_sys_stat_statfs2_fsize,
118   [AC_TRY_RUN([#include <sys/types.h>
119 #ifdef HAVE_SYS_PARAM_H
120 #include <sys/param.h>
121 #endif
122 #ifdef HAVE_SYS_MOUNT_H
123 #include <sys/mount.h>
124 #endif
125   main ()
126   {
127   struct statfs fsd;
128   fsd.f_fsize = 0;
129   exit (statfs (".", &fsd));
130   }],
131   fu_cv_sys_stat_statfs2_fsize=yes,
132   fu_cv_sys_stat_statfs2_fsize=no,
133   fu_cv_sys_stat_statfs2_fsize=no)])
134   AC_MSG_RESULT($fu_cv_sys_stat_statfs2_fsize)
135   if test $fu_cv_sys_stat_statfs2_fsize = yes; then
136     space=yes
137     AC_DEFINE(STAT_STATFS2_FSIZE, 1,
138 [  Define if statfs takes 2 args and struct statfs has a field named f_fsize.
139    (4.4BSD, NetBSD)])
140   fi
141 fi
142
143 if test $space = no; then
144   # Ultrix
145   AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
146   AC_CACHE_VAL(fu_cv_sys_stat_fs_data,
147   [AC_TRY_RUN([#include <sys/types.h>
148 #ifdef HAVE_SYS_PARAM_H
149 #include <sys/param.h>
150 #endif
151 #ifdef HAVE_SYS_MOUNT_H
152 #include <sys/mount.h>
153 #endif
154 #ifdef HAVE_SYS_FS_TYPES_H
155 #include <sys/fs_types.h>
156 #endif
157   main ()
158   {
159   struct fs_data fsd;
160   /* Ultrix's statfs returns 1 for success,
161      0 for not mounted, -1 for failure.  */
162   exit (statfs (".", &fsd) != 1);
163   }],
164   fu_cv_sys_stat_fs_data=yes,
165   fu_cv_sys_stat_fs_data=no,
166   fu_cv_sys_stat_fs_data=no)])
167   AC_MSG_RESULT($fu_cv_sys_stat_fs_data)
168   if test $fu_cv_sys_stat_fs_data = yes; then
169     space=yes
170     AC_DEFINE(STAT_STATFS2_FS_DATA, 1,
171 [  Define if statfs takes 2 args and the second argument has
172    type struct fs_data.  (Ultrix)])
173   fi
174 fi
175
176 if test $space = no; then
177 # SVR2
178 AC_TRY_CPP([#include <sys/filsys.h>],
179   AC_DEFINE(STAT_READ_FILSYS, 1,
180 [  Define if there is no specific function for reading filesystems usage
181    information and you have the <sys/filsys.h> header file.  (SVR2)])
182   space=yes)
183 fi
184
185 ])