error.c, md5.c, regex.c: Use '#if USE_UNLOCKED_IO' instead of
[gnulib.git] / m4 / fsusage.m4
1 # fsusage.m4 serial 13
2 # Obtaining file system usage information.
3
4 # Copyright (C) 1997, 1998, 2000, 2001, 2003, 2004 Free Software
5 # Foundation, Inc.
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software Foundation,
19 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
21 # Written by Jim Meyering.
22
23 AC_DEFUN([gl_FSUSAGE],
24 [
25   AC_CHECK_HEADERS_ONCE(sys/param.h)
26   AC_CHECK_HEADERS_ONCE(sys/vfs.h sys/fs_types.h)
27   AC_CHECK_HEADERS(sys/mount.h, [], [],
28     [AC_INCLUDES_DEFAULT
29      [#if HAVE_SYS_PARAM_H
30        #include <sys/param.h>
31       #endif]])
32   gl_FILE_SYSTEM_USAGE([gl_cv_fs_space=yes], [gl_cv_fs_space=no])
33   if test $gl_cv_fs_space = yes; then
34     AC_LIBOBJ(fsusage)
35     gl_PREREQ_FSUSAGE_EXTRA
36   fi
37 ])
38
39 # Try to determine how a program can obtain file system usage information.
40 # If successful, define the appropriate symbol (see fsusage.c) and
41 # execute ACTION-IF-FOUND.  Otherwise, execute ACTION-IF-NOT-FOUND.
42 #
43 # gl_FILE_SYSTEM_USAGE([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
44
45 AC_DEFUN([gl_FILE_SYSTEM_USAGE],
46 [
47
48 echo "checking how to get file system space usage..."
49 ac_fsusage_space=no
50
51 # Perform only the link test since it seems there are no variants of the
52 # statvfs function.  This check is more than just AC_CHECK_FUNCS(statvfs)
53 # because that got a false positive on SCO OSR5.  Adding the declaration
54 # of a `struct statvfs' causes this test to fail (as it should) on such
55 # systems.  That system is reported to work fine with STAT_STATFS4 which
56 # is what it gets when this test fails.
57 if test $ac_fsusage_space = no; then
58   # SVR4
59   AC_CACHE_CHECK([for statvfs function (SVR4)], fu_cv_sys_stat_statvfs,
60                  [AC_TRY_LINK([#include <sys/types.h>
61 #ifdef __GLIBC__
62 Do not use statvfs on systems with GNU libc, because that function stats
63 all preceding entries in /proc/mounts, and that makes df hang if even
64 one of the corresponding file systems is hard-mounted, but not available.
65 #endif
66 #include <sys/statvfs.h>],
67                               [struct statvfs fsd; statvfs (0, &fsd);],
68                               fu_cv_sys_stat_statvfs=yes,
69                               fu_cv_sys_stat_statvfs=no)])
70   if test $fu_cv_sys_stat_statvfs = yes; then
71     ac_fsusage_space=yes
72     AC_DEFINE(STAT_STATVFS, 1,
73               [  Define if there is a function named statvfs.  (SVR4)])
74   fi
75 fi
76
77 if test $ac_fsusage_space = no; then
78   # DEC Alpha running OSF/1
79   AC_MSG_CHECKING([for 3-argument statfs function (DEC OSF/1)])
80   AC_CACHE_VAL(fu_cv_sys_stat_statfs3_osf1,
81   [AC_TRY_RUN([
82 #include <sys/param.h>
83 #include <sys/types.h>
84 #include <sys/mount.h>
85   main ()
86   {
87     struct statfs fsd;
88     fsd.f_fsize = 0;
89     exit (statfs (".", &fsd, sizeof (struct statfs)));
90   }],
91   fu_cv_sys_stat_statfs3_osf1=yes,
92   fu_cv_sys_stat_statfs3_osf1=no,
93   fu_cv_sys_stat_statfs3_osf1=no)])
94   AC_MSG_RESULT($fu_cv_sys_stat_statfs3_osf1)
95   if test $fu_cv_sys_stat_statfs3_osf1 = yes; then
96     ac_fsusage_space=yes
97     AC_DEFINE(STAT_STATFS3_OSF1, 1,
98               [   Define if  statfs takes 3 args.  (DEC Alpha running OSF/1)])
99   fi
100 fi
101
102 if test $ac_fsusage_space = no; then
103 # AIX
104   AC_MSG_CHECKING([for two-argument statfs with statfs.bsize dnl
105 member (AIX, 4.3BSD)])
106   AC_CACHE_VAL(fu_cv_sys_stat_statfs2_bsize,
107   [AC_TRY_RUN([
108 #ifdef HAVE_SYS_PARAM_H
109 #include <sys/param.h>
110 #endif
111 #ifdef HAVE_SYS_MOUNT_H
112 #include <sys/mount.h>
113 #endif
114 #ifdef HAVE_SYS_VFS_H
115 #include <sys/vfs.h>
116 #endif
117   main ()
118   {
119   struct statfs fsd;
120   fsd.f_bsize = 0;
121   exit (statfs (".", &fsd));
122   }],
123   fu_cv_sys_stat_statfs2_bsize=yes,
124   fu_cv_sys_stat_statfs2_bsize=no,
125   fu_cv_sys_stat_statfs2_bsize=no)])
126   AC_MSG_RESULT($fu_cv_sys_stat_statfs2_bsize)
127   if test $fu_cv_sys_stat_statfs2_bsize = yes; then
128     ac_fsusage_space=yes
129     AC_DEFINE(STAT_STATFS2_BSIZE, 1,
130 [  Define if statfs takes 2 args and struct statfs has a field named f_bsize.
131    (4.3BSD, SunOS 4, HP-UX, AIX PS/2)])
132   fi
133 fi
134
135 if test $ac_fsusage_space = no; then
136 # SVR3
137   AC_MSG_CHECKING([for four-argument statfs (AIX-3.2.5, SVR3)])
138   AC_CACHE_VAL(fu_cv_sys_stat_statfs4,
139   [AC_TRY_RUN([#include <sys/types.h>
140 #include <sys/statfs.h>
141   main ()
142   {
143   struct statfs fsd;
144   exit (statfs (".", &fsd, sizeof fsd, 0));
145   }],
146     fu_cv_sys_stat_statfs4=yes,
147     fu_cv_sys_stat_statfs4=no,
148     fu_cv_sys_stat_statfs4=no)])
149   AC_MSG_RESULT($fu_cv_sys_stat_statfs4)
150   if test $fu_cv_sys_stat_statfs4 = yes; then
151     ac_fsusage_space=yes
152     AC_DEFINE(STAT_STATFS4, 1,
153               [  Define if statfs takes 4 args.  (SVR3, Dynix, Irix, Dolphin)])
154   fi
155 fi
156
157 if test $ac_fsusage_space = no; then
158 # 4.4BSD and NetBSD
159   AC_MSG_CHECKING([for two-argument statfs with statfs.fsize dnl
160 member (4.4BSD and NetBSD)])
161   AC_CACHE_VAL(fu_cv_sys_stat_statfs2_fsize,
162   [AC_TRY_RUN([#include <sys/types.h>
163 #ifdef HAVE_SYS_PARAM_H
164 #include <sys/param.h>
165 #endif
166 #ifdef HAVE_SYS_MOUNT_H
167 #include <sys/mount.h>
168 #endif
169   main ()
170   {
171   struct statfs fsd;
172   fsd.f_fsize = 0;
173   exit (statfs (".", &fsd));
174   }],
175   fu_cv_sys_stat_statfs2_fsize=yes,
176   fu_cv_sys_stat_statfs2_fsize=no,
177   fu_cv_sys_stat_statfs2_fsize=no)])
178   AC_MSG_RESULT($fu_cv_sys_stat_statfs2_fsize)
179   if test $fu_cv_sys_stat_statfs2_fsize = yes; then
180     ac_fsusage_space=yes
181     AC_DEFINE(STAT_STATFS2_FSIZE, 1,
182 [  Define if statfs takes 2 args and struct statfs has a field named f_fsize.
183    (4.4BSD, NetBSD)])
184   fi
185 fi
186
187 if test $ac_fsusage_space = no; then
188   # Ultrix
189   AC_MSG_CHECKING([for two-argument statfs with struct fs_data (Ultrix)])
190   AC_CACHE_VAL(fu_cv_sys_stat_fs_data,
191   [AC_TRY_RUN([#include <sys/types.h>
192 #ifdef HAVE_SYS_PARAM_H
193 #include <sys/param.h>
194 #endif
195 #ifdef HAVE_SYS_MOUNT_H
196 #include <sys/mount.h>
197 #endif
198 #ifdef HAVE_SYS_FS_TYPES_H
199 #include <sys/fs_types.h>
200 #endif
201   main ()
202   {
203   struct fs_data fsd;
204   /* Ultrix's statfs returns 1 for success,
205      0 for not mounted, -1 for failure.  */
206   exit (statfs (".", &fsd) != 1);
207   }],
208   fu_cv_sys_stat_fs_data=yes,
209   fu_cv_sys_stat_fs_data=no,
210   fu_cv_sys_stat_fs_data=no)])
211   AC_MSG_RESULT($fu_cv_sys_stat_fs_data)
212   if test $fu_cv_sys_stat_fs_data = yes; then
213     ac_fsusage_space=yes
214     AC_DEFINE(STAT_STATFS2_FS_DATA, 1,
215 [  Define if statfs takes 2 args and the second argument has
216    type struct fs_data.  (Ultrix)])
217   fi
218 fi
219
220 if test $ac_fsusage_space = no; then
221   # SVR2
222   AC_TRY_CPP([#include <sys/filsys.h>
223     ],
224     AC_DEFINE(STAT_READ_FILSYS, 1,
225       [Define if there is no specific function for reading file systems usage
226        information and you have the <sys/filsys.h> header file.  (SVR2)])
227     ac_fsusage_space=yes)
228 fi
229
230 AS_IF([test $ac_fsusage_space = yes], [$1], [$2])
231
232 ])
233
234
235 # Check for SunOS statfs brokenness wrt partitions 2GB and larger.
236 # If <sys/vfs.h> exists and struct statfs has a member named f_spare,
237 # enable the work-around code in fsusage.c.
238 AC_DEFUN([gl_STATFS_TRUNCATES],
239 [
240   AC_MSG_CHECKING([for statfs that truncates block counts])
241   AC_CACHE_VAL(fu_cv_sys_truncating_statfs,
242   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
243 #if !defined(sun) && !defined(__sun)
244 choke -- this is a workaround for a Sun-specific problem
245 #endif
246 #include <sys/types.h>
247 #include <sys/vfs.h>]],
248     [[struct statfs t; long c = *(t.f_spare);]])],
249     [fu_cv_sys_truncating_statfs=yes],
250     [fu_cv_sys_truncating_statfs=no])])
251   if test $fu_cv_sys_truncating_statfs = yes; then
252     AC_DEFINE(STATFS_TRUNCATES_BLOCK_COUNTS, 1,
253       [Define if the block counts reported by statfs may be truncated to 2GB
254        and the correct values may be stored in the f_spare array.
255        (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
256        SunOS 4.1.1 seems not to be affected.)])
257   fi
258   AC_MSG_RESULT($fu_cv_sys_truncating_statfs)
259 ])
260
261
262 # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE.
263 AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA],
264 [
265   AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])
266   AC_CHECK_HEADERS_ONCE(fcntl.h)
267   AC_CHECK_HEADERS(dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h sys/statvfs.h)
268   gl_STATFS_TRUNCATES
269 ])