home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / packer / zoo / msdos.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-12-27  |  2.2 KB  |  92 lines

  1. /* msdos.c */
  2.  
  3. /* Highly system-dependent routines go here */
  4.  
  5. /* settime() */
  6.  
  7. /* Accepts a date/time in DOS format and sets the file time. Returns 1
  8. if OK, 0 if error */
  9.  
  10. #include "options.h"
  11. #include "zoo.h"
  12. #include "intdos.h"
  13. #include "dta.h"                /* defines dta format & stuff */
  14. #include "zooio.h"        /* to satisfy declarations in zoofns.h */
  15. #include "zoofns.h"
  16. #include "errors.i"
  17.  
  18. int settime (file,date,time)
  19. ZOOFILE file;
  20. unsigned date, time;
  21. {
  22.     union REGS regs;
  23.     regs.h.ah = 0x57;                        /* DOS FileTimes call */
  24.     regs.h.al = 0x01;                    /* set date/time request */
  25.     regs.x.bx = fileno (file);        /* get handle */
  26.     regs.x.cx = time;
  27.     regs.x.dx = date;
  28.  
  29.     /* first flush file so later write won't occur on close */
  30.     fflush (file);
  31.  
  32.     intdos (®s, ®s);
  33.     if (regs.x.carry != 0)
  34.         return (0);
  35.     else
  36.         return (1);
  37. } /* settime */
  38.  
  39. /* gets date and time of file */
  40. gettime (file,date,time)
  41. ZOOFILE file;
  42. unsigned *date, *time;
  43. {
  44.     union REGS regs;
  45.     regs.h.ah = 0x57;                        /* DOS FileTimes call */
  46.     regs.h.al = 0x00;                        /* get date/time request */
  47.     regs.x.bx = fileno (file);        /* get handle */
  48.     intdos (®s, ®s);
  49.     *time = regs.x.cx;
  50.     *date = regs.x.dx;
  51.     if (regs.x.carry != 0)
  52.         return (0);
  53.     else
  54.         return (1);
  55. } /* settime */
  56.  
  57.  
  58. /* space() */
  59.  
  60. /* Returns free space in bytes on disk n (0 = default, 1 = A, etc.).  Returns
  61.     0 if drive number is invalid.  Before getting disk space, the function
  62.     requests DOS to flush its internal buffers */
  63.  
  64. unsigned long space (drive, alloc_size)
  65. int drive;
  66. int *alloc_size;
  67. {
  68.     unsigned long free_space;
  69.     union REGS regs;
  70.  
  71.     regs.h.ah = 0x0d;                                        /* disk reset DOS call */
  72.     intdos (®s, ®s);
  73.  
  74.     regs.h.ah = 0x36;                                        /* GetFreeSpace DOS call */
  75.     regs.h.dl = drive;
  76.     intdos (®s, ®s);
  77.  
  78.     /* space = clusters * sectors/cluster * bytes/sector.  */
  79.     /* ax=0xFFFF on error */
  80.  
  81.     /* cluster size = sectors/cluster * bytes/sector */
  82.     *alloc_size = regs.x.ax * regs.x.cx;
  83.  
  84.     /* space = cluster * alloc_size */
  85.     if (regs.x.ax == 0xffff)
  86.         return (0L);            /* invalid drive */
  87.     else {
  88.         free_space = ((unsigned long) regs.x.bx) * *alloc_size;
  89.         return (free_space);
  90.     }
  91. }
  92.