2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
5 POSIX function access().
10 #include <dos/filesystem.h>
13 #include <aros/debug.h>
18 /*****************************************************************************
30 Check access permissions of a file or pathname
33 path - the path of the file being checked
34 mode - the bitwise inclusive OR of the access permissions
37 W_OK - for write permission
38 R_OK - for readpermissions
39 X_OK - for execute permission
40 F_OK - Just to see whether the file exists
43 If path cannot be found or if any of the desired access
44 modes would not be granted, then a -1 value is returned;
45 otherwise a 0 value is returned.
58 ******************************************************************************/
61 struct FileInfoBlock
*fib
= NULL
;
64 struct DosList
*dl
= NULL
;
66 if (!path
) /* safety check */
72 /* Check if the volume exists. Calling Lock on non-existing volume will bring up System Requester */
73 if (SplitName(__path_u2a(path
), ':', vol
, 0, sizeof(vol
)-1) != -1)
75 if(strcmp(vol
, "PROGDIR") != 0)
77 dl
= LockDosList(LDF_ALL
| LDF_READ
);
78 dl
= FindDosEntry(dl
, vol
, LDF_ALL
);
79 UnLockDosList(LDF_ALL
| LDF_READ
);
80 /* Volume / Assign / Device not found */
89 /* Create a lock and examine a lock */
91 lock
= Lock(__path_u2a(path
), SHARED_LOCK
);
94 errno
= IoErr2errno(IoErr());
98 fib
= AllocDosObject(DOS_FIB
, NULL
);
101 errno
= IoErr2errno(IoErr());
106 if (Examine(lock
, fib
))
108 /* Notice : protection flags are 'low-active' (0 means access is granted) */
110 if ((mode
& R_OK
) && (result
== 0) && (fib
->fib_Protection
& (1 << FIBB_READ
)))
115 if ((mode
& W_OK
) && (result
== 0) && (fib
->fib_Protection
& (1 << FIBB_WRITE
)))
120 if ((mode
& X_OK
) && (result
== 0) && (fib
->fib_Protection
& (1 << FIBB_EXECUTE
)))
132 FreeDosObject(DOS_FIB
, fib
);