home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / access.c < prev    next >
C/C++ Source or Header  |  1993-02-13  |  898b  |  47 lines

  1. /* access() emulation; relies heavily on stat() */
  2.  
  3. #include <types.h>
  4. #include <stat.h>
  5. #include <fcntl.h>
  6. #include <errno.h>
  7. #include <unistd.h>
  8.  
  9. extern int __mint;
  10.  
  11. int
  12. access(path, mode)
  13.     const char *path;
  14.     int mode;
  15. {
  16.     struct stat sb;
  17.  
  18.     if (stat(path, &sb) < 0)
  19.         return -1;    /* errno was set by stat() */
  20.     if (mode == F_OK)
  21.         return 0;    /* existence test succeeded */
  22.  
  23.     if (getuid() == 0) return 0; /* super user can access anything */
  24.  
  25. /* somewhat crufty code -- relies on R_OK, etc. matching the bits in the
  26.    file mode, but what the heck, we can do this
  27.  */
  28.     if (__mint < 9 || ( getuid() == sb.st_uid ) ) {
  29.         if ( ((sb.st_mode >> 6) & mode) == mode )
  30.             return 0;
  31.         else
  32.             goto accdn;
  33.     }
  34.  
  35.     if ( getgid() == sb.st_gid ) {
  36.         if ( ((sb.st_mode >> 3) & mode) == mode )
  37.             return 0;
  38.         else
  39.             goto accdn;
  40.     }
  41.  
  42.     if ( (sb.st_mode & mode) == mode)
  43.         return 0;
  44. accdn:
  45.     errno = EACCESS; return -1;
  46. }
  47.