mlib update: new isnan()/isnanf() implementation
[tangerine.git] / compiler / clib / access.c
blobfa3f5faf752cd15f329d1b657eb1d872ec6fc89c
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 POSIX function access().
6 */
8 #include <errno.h>
9 #include <proto/dos.h>
10 #include <dos/filesystem.h>
12 #include <aros/debug.h>
14 #include "__errno.h"
15 #include "__upath.h"
17 /*****************************************************************************
19 NAME */
20 #include <unistd.h>
22 int access (
24 /* SYNOPSIS */
25 const char *path,
26 int mode)
28 /* FUNCTION
29 Check access permissions of a file or pathname
31 INPUTS
32 path - the path of the file being checked
33 mode - the bitwise inclusive OR of the access permissions
34 to be checked:
36 W_OK - for write permission
37 R_OK - for readpermissions
38 X_OK - for execute permission
39 F_OK - Just to see whether the file exists
41 RESULT
42 If path cannot be found or if any of the desired access
43 modes would not be granted, then a -1 value is returned;
44 otherwise a 0 value is returned.
46 NOTES
47 Even if a process has appropriate privileges and indicates
48 success for X_OK, the file may not actually have execute
49 permission bits set. Likewise for R_OK and W_OK.
51 EXAMPLE
53 BUGS
55 SEE ALSO
56 open(), ftruncate()
58 INTERNALS
60 ******************************************************************************/
62 ULONG amode = 0;
63 BPTR fh;
65 if (!path) /* safety check */
67 errno = EFAULT;
68 return -1;
71 /* how can we check whether a file exists without having read permission?? */
72 if (!mode) mode = R_OK;
74 if (mode & R_OK) amode |= FMF_READ;
75 if (mode & W_OK) amode |= FMF_WRITE;
76 if (mode & X_OK) amode |= FMF_EXECUTE;
78 if (!(fh = Lock(__path_u2a(path), amode)))
80 errno = IoErr2errno(IoErr());
81 return -1;
84 Close(fh);
85 return 0;