2 Copyright © 1995-2009, 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 if (!strlen(path
)) /* empty path */
78 /* Check if the volume exists. Calling Lock on non-existing volume will bring up System Requester */
79 if (SplitName(__path_u2a(path
), ':', vol
, 0, sizeof(vol
)-1) != -1)
81 if(strcmp(vol
, "PROGDIR") != 0)
83 dl
= LockDosList(LDF_ALL
| LDF_READ
);
84 dl
= FindDosEntry(dl
, vol
, LDF_ALL
);
85 UnLockDosList(LDF_ALL
| LDF_READ
);
86 /* Volume / Assign / Device not found */
95 /* Create a lock and examine a lock */
97 lock
= Lock(__path_u2a(path
), SHARED_LOCK
);
100 errno
= IoErr2errno(IoErr());
104 fib
= AllocDosObject(DOS_FIB
, NULL
);
107 errno
= IoErr2errno(IoErr());
112 if (Examine(lock
, fib
))
114 /* Notice : protection flags are 'low-active' (0 means access is granted) */
116 if ((mode
& R_OK
) && (result
== 0) && (fib
->fib_Protection
& (1 << FIBB_READ
)))
121 if ((mode
& W_OK
) && (result
== 0) && (fib
->fib_Protection
& (1 << FIBB_WRITE
)))
126 if ((mode
& X_OK
) && (result
== 0) && (fib
->fib_Protection
& (1 << FIBB_EXECUTE
)))
138 FreeDosObject(DOS_FIB
, fib
);