2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
5 POSIX function access().
8 #include <aros/debug.h>
10 #include <proto/dos.h>
13 #include <aros/debug.h>
15 #include "__arosc_privdata.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 ******************************************************************************/
60 struct aroscbase
*aroscbase
= __GM_GetBase();
62 struct FileInfoBlock
*fib
= NULL
;
65 struct DosList
*dl
= NULL
;
68 if (!path
) /* safety check */
74 D(bug("[access] Path: %s\n", path
));
75 if (!strlen(path
)) /* empty path */
81 /* POSIX root is (poorly) emulated, its contents is accessible */
82 if (aroscbase
->acb_doupath
&& (path
[0] == '/') && (path
[1] == '\0'))
84 if (mode
& (W_OK
|R_OK
)) {
91 apath
= __path_u2a(path
);
92 D(bug("[access] AROS path: %s\n", apath
));
93 /* Check if the volume exists. Calling Lock on non-existing volume will bring up System Requester */
94 if (SplitName(apath
, ':', vol
, 0, sizeof(vol
)-1) != -1)
96 D(bug("[access] Volume name: %s\n", vol
));
97 if(strcmp(vol
, "PROGDIR") != 0)
99 dl
= LockDosList(LDF_ALL
| LDF_READ
);
100 dl
= FindDosEntry(dl
, vol
, LDF_ALL
);
101 UnLockDosList(LDF_ALL
| LDF_READ
);
102 /* Volume / Assign / Device not found */
111 /* Create a lock and examine a lock */
113 lock
= Lock(apath
, SHARED_LOCK
);
116 errno
= __arosc_ioerr2errno(IoErr());
120 fib
= AllocDosObject(DOS_FIB
, NULL
);
123 errno
= __arosc_ioerr2errno(IoErr());
128 if (Examine(lock
, fib
))
130 /* Notice : protection flags are 'low-active' (0 means access is granted) */
132 if ((mode
& R_OK
) && (result
== 0) && (fib
->fib_Protection
& (1 << FIBB_READ
)))
137 if ((mode
& W_OK
) && (result
== 0) && (fib
->fib_Protection
& (1 << FIBB_WRITE
)))
142 if ((mode
& X_OK
) && (result
== 0) && (fib
->fib_Protection
& (1 << FIBB_EXECUTE
)))
150 /* We get here if Examine() failed. However it can be a character device
151 (NIL:, ZERO:, etc) which does not support EXAMINE action.
152 Currently we consider them read-write. If really needded, the routine
153 can be modified in order to try to open the device in different modes. */
155 BPTR fh
= OpenFromLock(lock
);
159 ischar
= IsInteractive(fh
);
169 /* Character devices are not executable in any way */
183 FreeDosObject(DOS_FIB
, fib
);