2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
5 POSIX.1-2008 function access().
12 #include <aros/debug.h>
15 #include "__posixc_intbase.h"
17 /*****************************************************************************
29 Check access permissions of a file or pathname
32 path - the path of the file being checked
33 mode - the bitwise inclusive OR of the access permissions
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
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.
57 ******************************************************************************/
59 struct PosixCIntBase
*PosixCBase
=
60 (struct PosixCIntBase
*)__aros_getbase_PosixCBase();
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 (PosixCBase
->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
= __stdc_ioerr2errno(IoErr());
120 fib
= AllocDosObject(DOS_FIB
, NULL
);
123 errno
= __stdc_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
);