home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GEMini Atari
/
GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso
/
zip
/
mint
/
mntlib16.lzh
/
MNTLIB16
/
ACCESS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-03
|
908b
|
46 lines
/* 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;
}