home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / OLS / Os2 / LHA2P205 / LHA2P205.LZH / lha2-2.05pre / source.lzh / src / dosio.c < prev    next >
C/C++ Source or Header  |  1995-12-31  |  2KB  |  98 lines

  1. /*
  2.  * dosio.c --- MS-DOS and IBM OS/2 dependent I/O
  3.  *   Copyright (C) 1988-1992, Haruyasu YOSHIZAKI
  4.  *   Copyright (C) 1991-1995, Satoshi HIRAMATSU (OS/2 HPFS version)
  5.  *
  6.  * $Log$
  7.  */
  8.  
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <ctype.h>
  14. #include <io.h>
  15. #include <time.h>
  16. #include "port2.h"
  17. #include "typedef.h"
  18. #include "lh.h"
  19.  
  20.  
  21. time_t
  22. #ifndef __SUPPORT_CTIME_ATIME__
  23. getfiletime(FILE *f)
  24. {
  25.   union stamp stamp;
  26.   unsigned date, time;
  27.  
  28.   _dos_getftime(fileno(f), &date, &time);
  29.   stamp.t.date = 0xffff & date;
  30.   stamp.t.time = 0xffff & time;
  31.  
  32.   return dos2unix(&stamp.s);
  33. }
  34.  
  35.  
  36. int
  37. setfiletime(FILE *f, time_t utc)
  38. {
  39.   union stamp *stamp;
  40.   unsigned date, time;
  41.  
  42.   stamp = (union stamp *)unix2dos(utc);
  43.   fflush(f);
  44.  
  45.   return _dos_setftime(fileno(f), stamp->t.date, stamp->t.time);
  46. }
  47. #else
  48. getfiletime(FILE *f)
  49. {
  50.   time_t mod, cre, acc;
  51.  
  52.   _os2_getftime(fileno(f), &mod, &cre, &acc);
  53.  
  54.   return mod;
  55. }
  56.  
  57.  
  58. int
  59. setfiletime(FILE *f, time_t *mod, time_t *cre, time_t *acc)
  60. {
  61.   fflush(f);
  62.  
  63.   return _os2_setftime(fileno(f), mod, cre, acc);
  64. }
  65. #endif
  66.  
  67.  
  68. static char
  69. physicaldrive(char *filename)
  70. {
  71.   if((isalpha(*filename) != 0) && (*(filename + 1)) == ':')
  72.     return tolower((int)*filename) - 'a' + 1;
  73.  
  74.   return 0;            /* current drive */
  75. }
  76.  
  77.  
  78. long
  79. diskspace(char *filename)
  80. {
  81.   struct diskfree_t dtable;
  82.   struct find_t srchbuf;
  83.   long cluster, freespace;
  84.  
  85.   if(_dos_findfirst(filename, 0x07, &srchbuf))
  86.     srchbuf.size = 0;
  87. #ifdef __SUPPORT_EA__
  88.   if(srchbuf.ea)
  89.     free(srchbuf.ea);
  90. #endif
  91.   _dos_getdiskfree(physicaldrive(filename), &dtable);
  92.   cluster = (long)dtable.bytes_per_sector*(long)dtable.sectors_per_cluster;
  93.   freespace = (long)dtable.avail_clusters*cluster;
  94.   freespace += (srchbuf.size + cluster - 1)/cluster*cluster;
  95.  
  96.   return freespace;
  97. }
  98.