home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 387b.lha / dice_v2.02 / lib / unix / access.c next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  785 b   |  48 lines

  1.  
  2. /*
  3.  *  ACCESS.C        Check File Accessibility
  4.  *
  5.  *  (c)Copyright 1990, Matthew Dillon, All Rights Reserved
  6.  */
  7.  
  8. #include <libraries/dos.h>
  9. #include <stdlib.h>
  10.  
  11. typedef struct FileInfoBlock    FIB;
  12.  
  13. int
  14. access(name, mode)
  15. const char *name;
  16. int mode;
  17. {
  18.     FIB *fib = malloc(sizeof(FIB));
  19.     int r = -1;
  20.  
  21.     if (fib) {
  22.     BPTR lock;
  23.     if (lock = Lock(name, SHARED_LOCK)) {
  24.         if (Examine(lock, fib)) {
  25.         long prot = fib->fib_Protection;
  26.  
  27.         r = 0;
  28.         if (mode & 4) {     /*  r   */
  29.             if (prot & 8)   /*  no read perm    */
  30.             r = -1;
  31.         }
  32.         if (mode & 2) {     /*  w   */
  33.             if (prot & 4)   /*  no write perm   */
  34.             r = -1;
  35.         }
  36.         if (mode & 1) {     /*  x   */
  37.             if (prot & 2)   /*  no execute perm */
  38.             r = -1;
  39.         }
  40.         }
  41.         UnLock(lock);
  42.     }
  43.     free(fib);
  44.     }
  45.     return(r);
  46. }
  47.  
  48.