home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / unixlib / !UnixLib / src / unix / c / access next >
Encoding:
Text File  |  1994-09-30  |  681 b   |  45 lines

  1. static char sccs_id[] = "@(#) access.c 1.2 " __DATE__ " HJR";
  2.  
  3. /* access.c (c) Copyright 1990 H.Rogers */
  4.  
  5. #include <errno.h>
  6.  
  7. #include "sys/types.h"
  8. #include "sys/unix.h"
  9. #include "sys/os.h"
  10.  
  11. int
  12. access (char *file, register int mode)
  13. {
  14.   int r[6];
  15.   os_error *e;
  16.   int i;
  17.  
  18.   file = __uname (file, 0);
  19.  
  20.   if (e = os_file (0x05, file, r))
  21.     {
  22.       __seterr (e);
  23.       return (-1);
  24.     }
  25.   if (!r[0])
  26.     {
  27.       errno = ENOENT;
  28.       return (-1);
  29.     }
  30.  
  31.   i = ((r[5] & 0040) >> 4) | ((r[5] & 0020) >> 2) |
  32.     ((r[5] & 0002)) | ((r[5] & 0001) << 2);
  33.  
  34.   if (i & 0002)
  35.     i |= 0001;
  36.  
  37.   if ((i & mode) != mode)
  38.     {
  39.       errno = EPERM;
  40.       return (-1);
  41.     }
  42.  
  43.   return (0);
  44. }
  45.