home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff218.lzh / EdLib / filetype.c < prev    next >
C/C++ Source or Header  |  1989-06-04  |  844b  |  46 lines

  1. /*
  2.  * edlib v1.1 Copyright 1989 Edwin Hoogerbeets
  3.  * This code is freely redistributable as long as no charge other than
  4.  * reasonable copying fees are levied for it.
  5.  */
  6. #include "edlib.h"
  7. #include <libraries/dos.h>
  8. #include <exec/memory.h>
  9. #include <errno.h>
  10.  
  11. #define FIBSIZE sizeof(struct FileInfoBlock)
  12.  
  13. extern struct FileInfoBlock *AllocMem();
  14. extern struct FileLock      *Lock();
  15.  
  16. int filetype(path)
  17. char *path;
  18. {
  19.   register struct FileInfoBlock *fib;
  20.   register struct FileLock *lock;
  21.   register int result;
  22.  
  23.  
  24.   if ( !(fib = AllocMem(FIBSIZE,MEMF_CLEAR)) ) {
  25.     errno = ENOMEM;
  26.     return(-1);
  27.   }
  28.  
  29.   if ( !(lock = Lock(path,ACCESS_READ)) ) {
  30.     errno = EACCES;
  31.     return(-1);
  32.   }
  33.  
  34.   Examine(lock,fib);
  35.  
  36.   result = ( fib->fib_DirEntryType > 0 ) ? TYPE_DIR : TYPE_FILE;
  37.  
  38.   UnLock(lock);
  39.   FreeMem(fib,FIBSIZE);
  40.  
  41.   return(result);
  42. }
  43.  
  44.  
  45.  
  46.