merge with 3.8
[gnulib.git] / lib / fsusage.c
index 8cc0c6d..c9ed26c 100644 (file)
 
 int statfs ();
 
+#if defined (STATFS_OSF1)      /* DEC Alpha running OSF/1 */
+#  include <sys/mount.h>
+#endif
+
 #if defined(STAT_STATFS2_BSIZE) && !defined(_IBMR2) /* 4.3BSD, SunOS 4, HP-UX, AIX PS/2.  */
 #include <sys/vfs.h>
 #endif
@@ -56,14 +60,18 @@ int statvfs ();
 /* Return the number of TOSIZE-byte blocks used by
    BLOCKS FROMSIZE-byte blocks, rounding up.  */
 
-#define adjust_blocks(blocks, fromsize, tosize)                \
-  (((fromsize) == (tosize))                            \
-   ? (blocks)  /* E.g., from 512 to 512.  */           \
-   : (((fromsize) > (tosize))                          \
-      /* E.g., from 2048 to 512.  */                   \
-      ? (blocks) * ((fromsize) / (tosize))             \
-      /* E.g., from 256 to 512.  */                    \
-      : ((blocks) + 1) / ((tosize) / (fromsize))))
+static long
+adjust_blocks (blocks, fromsize, tosize)
+     long blocks;
+     int fromsize, tosize;
+{
+  if (fromsize == tosize)      /* E.g., from 512 to 512.  */
+    return blocks;
+  else if (fromsize > tosize)  /* E.g., from 2048 to 512.  */
+    return blocks * (fromsize / tosize);
+  else                         /* E.g., from 256 to 512.  */
+    return (blocks + 1) / (tosize / fromsize);
+}
 
 /* Fill in the fields of FSP with information about space usage for
    the filesystem on which PATH resides.
@@ -76,6 +84,14 @@ get_fs_usage (path, disk, fsp)
      char *path, *disk;
      struct fs_usage *fsp;
 {
+#if defined (STATFS_OSF1)
+  struct statfs fsd;
+
+  if (statfs (path, &fsd, sizeof (struct statfs)) != 0)
+    return (-1);
+#define convert_blocks(b) adjust_blocks ((b),fsd.f_fsize, 512)
+#endif /* STATFS_OSF1 */
+
 #ifdef STAT_STATFS2_FS_DATA    /* Ultrix.  */
   struct fs_data fsd;
 
@@ -140,9 +156,11 @@ get_fs_usage (path, disk, fsp)
      no matter what value f_bsize has.  */
 #define convert_blocks(b) (b)
 #ifndef _SEQUENT_              /* _SEQUENT_ is DYNIX/ptx.  */
+#ifndef DOLPHIN                        /* DOLPHIN 3.8.alfa/7.18 has f_bavail */
 #define f_bavail f_bfree
 #endif
 #endif
+#endif
 
 #ifdef STAT_STATVFS            /* SVR4.  */
   struct statvfs fsd;