-#if defined(STAT_STATFS2_BSIZE) && !defined(_IBMR2) /* 4.3BSD, SunOS 4, HP-UX, AIX PS/2. */
-#include <sys/vfs.h>
-#endif
-
-#ifdef STAT_STATFS2_FSIZE /* 4.4BSD. */
-#include <sys/mount.h>
-#endif
-
-#ifdef STAT_STATFS2_FS_DATA /* Ultrix. */
-#include <sys/param.h>
-#include <sys/mount.h>
-#endif
-
-#ifdef STAT_READ /* SVR2. */
-#include <sys/param.h>
-#include <sys/filsys.h>
-#include <fcntl.h>
-#endif
-
-#if defined(STAT_STATFS4) || (defined(_AIX) && defined(_IBMR2)) /* SVR3, Dynix, Irix, AIX RS6000. */
-#include <sys/statfs.h>
-#endif
-
-#if defined(_AIX) && defined(_I386) /* AIX PS/2. */
-#include <sys/stat.h>
-#include <sys/dustat.h>
-#endif
-
-#ifdef STAT_STATVFS /* SVR4. */
-#include <sys/statvfs.h>
-int statvfs ();
-#endif
-
-/* Set B_NEW to the number of TOSIZE-byte blocks used by B FROMSIZE-byte
- blocks, rounding away from zero. TOSIZE must be positive. Return -1
- from invoking function if FROMSIZE is not positive. */
-
-#define ADJUST_BLOCKS(b_new, b, fromsize, tosize) \
- do \
- { \
- if ((tosize) <= 0) \
- abort (); \
- if ((fromsize) <= 0) \
- return -1; \
- \
- if ((fromsize) == (tosize)) /* E.g., from 512 to 512. */ \
- (b_new) = (b); \
- else if ((fromsize) > (tosize)) /* E.g., from 2048 to 512. */ \
- (b_new) = (b) * ((fromsize) / (tosize)); \
- else /* E.g., from 256 to 512. */ \
- (b_new) = ((b) + ((b) < 0 ? -1 : 1)) / ((tosize) / (fromsize)); \
- } \
- while (0)
+/* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+#undef open
+#undef close
+
+/* Many space usage primitives use all 1 bits to denote a value that is
+ not applicable or unknown. Propagate this information by returning
+ a uintmax_t value that is all 1 bits if X is all 1 bits, even if X
+ is unsigned and narrower than uintmax_t. */
+#define PROPAGATE_ALL_ONES(x) \
+ ((sizeof (x) < sizeof (uintmax_t) \
+ && (~ (x) == (sizeof (x) < sizeof (int) \
+ ? - (1 << (sizeof (x) * CHAR_BIT)) \
+ : 0))) \
+ ? UINTMAX_MAX : (uintmax_t) (x))
+
+/* Extract the top bit of X as an uintmax_t value. */
+#define EXTRACT_TOP_BIT(x) ((x) \
+ & ((uintmax_t) 1 << (sizeof (x) * CHAR_BIT - 1)))
+
+/* If a value is negative, many space usage primitives store it into an
+ integer variable by assignment, even if the variable's type is unsigned.
+ So, if a space usage variable X's top bit is set, convert X to the
+ uintmax_t value V such that (- (uintmax_t) V) is the negative of
+ the original value. If X's top bit is clear, just yield X.
+ Use PROPAGATE_TOP_BIT if the original value might be negative;
+ otherwise, use PROPAGATE_ALL_ONES. */
+#define PROPAGATE_TOP_BIT(x) ((x) | ~ (EXTRACT_TOP_BIT (x) - 1))