home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / DLIBSSRC.ZIP / STAT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-09-21  |  1.2 KB  |  57 lines

  1. #include <osbind.h>
  2. #include <stdio.h>
  3. #include <io.h>
  4.  
  5. static    STAT    _dta;        /* local DTA buffer */
  6.  
  7. int access(name, amode)
  8. char *name;
  9. int amode;
  10. /*
  11.  *    Return non-zero if a file with the given <name> can be accessed
  12.  *    in the given <amode>.  Possible <amode> values are:
  13.  *        _ACCe        file/directory exists
  14.  *        _ACCr        file can be read
  15.  *        _ACCw        file can be written
  16.  *        _ACCrw        file can be read and written
  17.  */
  18. {
  19.     register STAT *_pdta;        /* pointer to old DTA */
  20.     register int rv;
  21.  
  22.     _pdta = Fgetdta();
  23.     Fsetdta(&_dta);
  24.     rv = (Fsfirst(name, amode) == 0);
  25.     Fsetdta(_pdta);
  26.     return(rv);
  27. }
  28.  
  29. int stat(name, statbuf)
  30. char *name;
  31. STAT *statbuf;
  32. /*
  33.  *    Search for file <name> and load <statbuf> with information
  34.  *    about that file, if it is found.  Return 0 if found, or
  35.  *    ERROR (-1) if no file/directory matched <name>.  Volume
  36.  *    labels are not included in the search.
  37.  */
  38. {
  39.     if(access(name, 0x17)) {
  40.         *statbuf = _dta;
  41.         return(0);
  42.     }
  43.     return(ERROR);
  44. }
  45.  
  46. long fsize(name)
  47. char *name;
  48. /*
  49.  *    Return the size of the file <name> in bytes.  Note that this
  50.  *    is a long value.  Return -1L if the file is not found.
  51.  */
  52. {
  53.     if(access(name, 0x07))
  54.         return(_dta.S_size);
  55.     return(-1L);
  56. }
  57.