Miscellaneous calls
[reactos.git] / posix / lib / psxdll / unistd / access.c
1 /* $Id: access.c,v 1.1 2002/05/17 02:16:16 hyperion Exp $
2 */
3 /*
4 * COPYRIGHT: See COPYING in the top level directory
5 * PROJECT: ReactOS POSIX+ Subsystem
6 * FILE: subsys/psx/lib/psxdll/unistd/access.c
7 * PURPOSE: Determine accessibility of a file
8 * PROGRAMMER: KJK::Hyperion <noog@libero.it>
9 * UPDATE HISTORY:
10 * 13/02/2002: Created
11 */
12
13 #include <ddk/ntddk.h>
14 #include <unistd.h>
15 #include <fcntl.h>
16 #include <psx/errno.h>
17
18 int access(const char *path, int amode)
19 {
20 OBJECT_ATTRIBUTES oaFileAttribs;
21 IO_STATUS_BLOCK isbStatus;
22 ACCESS_MASK amDesiredAccess = 0;
23 NTSTATUS nErrCode;
24 HANDLE hFile;
25
26 if(amode != F_OK)
27 {
28 if(amode && R_OK) amDesiredAccess |= GENERIC_READ;
29 if(amode && W_OK) amDesiredAccess |= GENERIC_WRITE;
30 if(amode && X_OK) amDesiredAccess |= GENERIC_EXECUTE;
31 }
32
33 nErrCode = NtCreateFile
34 (
35 &hFile,
36 amDesiredAccess,
37 &oaFileAttribs,
38 &isbStatus,
39 0,
40 0,
41 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
42 FILE_OPEN,
43 0,
44 0,
45 0
46 );
47
48 if(NT_SUCCESS(nErrCode))
49 {
50 NtClose(hFile);
51 return (0);
52 }
53
54 errno = __status_to_errno(nErrCode);
55 return (-1);
56 }
57
58 /* EOF */
59