home *** CD-ROM | disk | FTP | other *** search
- /* access() emulation; relies heavily on stat() */
-
- #include <types.h>
- #include <stat.h>
- #include <fcntl.h>
- #include <errno.h>
- #include <unistd.h>
-
- extern int __mint;
-
- int
- access(path, mode)
- const char *path;
- int mode;
- {
- struct stat sb;
- int uid, gid;
-
- if (stat(path, &sb) < 0)
- return -1; /* errno was set by stat() */
- if (mode == F_OK)
- return 0; /* existence test succeeded */
-
- /* somewhat crufty code -- relies on R_OK, etc. matching the bits in the
- file mode, but what the heck, we can do this
- */
- if (__mint < 9 || ( (uid = geteuid()) == sb.st_uid ) ) {
- if ( ((sb.st_mode >> 6) & mode) == mode )
- return 0;
- else
- goto accdn;
- }
-
- if ( (gid = getegid()) == sb.st_gid ) {
- if ( ((sb.st_mode >> 3) & mode) == mode )
- return 0;
- else
- goto accdn;
- }
-
- if ( (sb.st_mode & mode) == mode)
- return 0;
- accdn:
- errno = EACCESS; return -1;
- }
-