home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / statfs.c < prev    next >
C/C++ Source or Header  |  1992-09-05  |  1KB  |  72 lines

  1. /*
  2.  * statfs() emulation for MiNT/TOS
  3.  *
  4.  * Written by Adrian Ashley (adrian@secret.uucp)
  5.  * and placed in the public domain.
  6.  */
  7.  
  8. #include <errno.h>
  9. #include <stat.h>
  10. #include <osbind.h>
  11. #ifdef __TURBOC__
  12. #include <sys\statfs.h>
  13. #else
  14. #include <sys/statfs.h>
  15. #endif
  16.  
  17. int statfs(path, buf)
  18.   char *path;
  19.   struct statfs *buf;
  20. {
  21.   int r;
  22.   _DISKINFO free;
  23.   struct stat statbuf;
  24.  
  25.   if (!buf || !path)
  26.   {
  27.     errno = EFAULT;
  28.     return -1;
  29.   }
  30.  
  31.   r = stat(path, &statbuf);
  32.  
  33.   if (r == -1)
  34.     return -1;
  35.  
  36.   (void) Dfree(&free, statbuf.st_dev + 1);
  37.  
  38.   buf->f_type = 0;
  39.   buf->f_bsize = free.b_secsiz * free.b_clsiz;
  40.   buf->f_blocks = free.b_total;
  41.   buf->f_bfree = buf->f_bavail = free.b_free;
  42.   buf->f_files = buf->f_ffree = buf->f_fsid.val[0] = buf->f_fsid.val[1] = -1L;
  43.  
  44.   return 0;
  45. }
  46.  
  47. #ifdef TEST
  48.  
  49. #include <stdio.h>
  50.  
  51. main(int argc, char **argv)
  52. {
  53.   int i = 0, r;
  54.   register char *p;
  55.   struct statfs stbuf;
  56.  
  57.   while (--argc)
  58.   {
  59.     p = argv[++i];
  60.  
  61.     r = statfs(p, &stbuf);
  62.     if (r == -1)
  63.       perror(p);
  64.     else
  65.       printf("statfs(`%s'): %ld free bytes\n", p,
  66.     (long)(stbuf.f_bfree * stbuf.f_bsize));
  67.   }
  68.   return 0;
  69. }
  70.  
  71. #endif
  72.