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