2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
5 POSIX function access().
8 #include <aros/debug.h>
10 #include <proto/dos.h>
11 #include <dos/filesystem.h>
14 #include <aros/debug.h>
16 #include "__arosc_privdata.h"
20 /*****************************************************************************
32 Check access permissions of a file or pathname
35 path - the path of the file being checked
36 mode - the bitwise inclusive OR of the access permissions
39 W_OK - for write permission
40 R_OK - for readpermissions
41 X_OK - for execute permission
42 F_OK - Just to see whether the file exists
45 If path cannot be found or if any of the desired access
46 modes would not be granted, then a -1 value is returned;
47 otherwise a 0 value is returned.
60 ******************************************************************************/
63 struct FileInfoBlock
*fib
= NULL
;
66 struct DosList
*dl
= NULL
;
69 if (!path
) /* safety check */
75 D(bug("[access] Path: %s\n", path
));
76 if (!strlen(path
)) /* empty path */
82 /* POSIX root is (poorly) emulated, its contents is accessible */
83 if (__doupath
&& (path
[0] == '/') && (path
[1] == '\0'))
85 if (mode
& (W_OK
|R_OK
)) {
92 apath
= __path_u2a(path
);
93 D(bug("[access] AROS path: %s\n", apath
));
94 /* Check if the volume exists. Calling Lock on non-existing volume will bring up System Requester */
95 if (SplitName(apath
, ':', vol
, 0, sizeof(vol
)-1) != -1)
97 D(bug("[access] Volume name: %s\n", vol
));
98 if(strcmp(vol
, "PROGDIR") != 0)
100 dl
= LockDosList(LDF_ALL
| LDF_READ
);
101 dl
= FindDosEntry(dl
, vol
, LDF_ALL
);
102 UnLockDosList(LDF_ALL
| LDF_READ
);
103 /* Volume / Assign / Device not found */
112 /* Create a lock and examine a lock */
114 lock
= Lock(apath
, SHARED_LOCK
);
117 errno
= IoErr2errno(IoErr());
121 fib
= AllocDosObject(DOS_FIB
, NULL
);
124 errno
= IoErr2errno(IoErr());
129 if (Examine(lock
, fib
))
131 /* Notice : protection flags are 'low-active' (0 means access is granted) */
133 if ((mode
& R_OK
) && (result
== 0) && (fib
->fib_Protection
& (1 << FIBB_READ
)))
138 if ((mode
& W_OK
) && (result
== 0) && (fib
->fib_Protection
& (1 << FIBB_WRITE
)))
143 if ((mode
& X_OK
) && (result
== 0) && (fib
->fib_Protection
& (1 << FIBB_EXECUTE
)))
151 /* We get here if Examine() failed. However it can be a character device
152 (NIL:, ZERO:, etc) which does not support EXAMINE action.
153 Currently we consider them read-write. If really needded, the routine
154 can be modified in order to try to open the device in different modes. */
156 BPTR fh
= OpenFromLock(lock
);
160 ischar
= IsInteractive(fh
);
170 /* Character devices are not executable in any way */
184 FreeDosObject(DOS_FIB
, fib
);