Sync with trunk (r48545)
[reactos.git] / dll / win32 / kernel32 / file / lfile.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/file/lfile.c
6 * PURPOSE: Find functions
7 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
8 * UPDATE HISTORY:
9 * Created 01/11/98
10 */
11
12 #include <k32.h>
13 #define NDEBUG
14 #include <debug.h>
15
16 /*
17 * @implemented
18 */
19 long
20 WINAPI
21 _hread(HFILE hFile, LPVOID lpBuffer, long lBytes)
22 {
23 DWORD NumberOfBytesRead;
24
25 if (!ReadFile(LongToHandle(hFile),
26 lpBuffer,
27 (DWORD) lBytes,
28 &NumberOfBytesRead,
29 NULL))
30 {
31 return HFILE_ERROR;
32 }
33 return NumberOfBytesRead;
34 }
35
36
37 /*
38 * @implemented
39 */
40 long
41 WINAPI
42 _hwrite(HFILE hFile, LPCSTR lpBuffer, long lBytes)
43 {
44 DWORD NumberOfBytesWritten;
45
46 if (lBytes == 0)
47 {
48 if (!SetEndOfFile((HANDLE) hFile))
49 {
50 return HFILE_ERROR;
51 }
52 return 0;
53 }
54 if (!WriteFile(LongToHandle(hFile),
55 (LPVOID) lpBuffer,
56 (DWORD) lBytes,
57 &NumberOfBytesWritten,
58 NULL))
59 {
60 return HFILE_ERROR;
61 }
62 return NumberOfBytesWritten;
63 }
64
65
66 /*
67 * @implemented
68 */
69 HFILE
70 WINAPI
71 _lopen(LPCSTR lpPathName, int iReadWrite)
72 {
73 DWORD dwAccess, dwSharing, dwCreation;
74
75 if (iReadWrite & OF_CREATE)
76 {
77 dwCreation = CREATE_ALWAYS;
78 dwAccess = GENERIC_READ | GENERIC_WRITE;
79 }
80 else
81 {
82 dwCreation = OPEN_EXISTING;
83 switch(iReadWrite & 0x03)
84 {
85 case OF_READ: dwAccess = GENERIC_READ; break;
86 case OF_WRITE: dwAccess = GENERIC_WRITE; break;
87 case OF_READWRITE: dwAccess = GENERIC_READ | GENERIC_WRITE; break;
88 default: dwAccess = 0; break;
89 }
90 }
91
92 switch(iReadWrite & 0x70)
93 {
94 case OF_SHARE_EXCLUSIVE: dwSharing = 0; break;
95 case OF_SHARE_DENY_WRITE: dwSharing = FILE_SHARE_READ; break;
96 case OF_SHARE_DENY_READ: dwSharing = FILE_SHARE_WRITE; break;
97 case OF_SHARE_DENY_NONE:
98 case OF_SHARE_COMPAT:
99 default: dwSharing = FILE_SHARE_READ | FILE_SHARE_WRITE; break;
100 }
101
102 return (HFILE) CreateFileA(lpPathName,
103 dwAccess,
104 dwSharing,
105 NULL,
106 dwCreation,
107 FILE_ATTRIBUTE_NORMAL,
108 NULL);
109 }
110
111
112 /*
113 * @implemented
114 */
115 HFILE
116 WINAPI
117 _lcreat(LPCSTR lpPathName, int iAttribute)
118 {
119 HANDLE hFile;
120
121 iAttribute &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM;
122 hFile = CreateFileA(lpPathName,
123 GENERIC_READ | GENERIC_WRITE,
124 (FILE_SHARE_READ | FILE_SHARE_WRITE),
125 NULL,
126 CREATE_ALWAYS,
127 iAttribute,
128 NULL);
129
130 return HandleToLong(hFile);
131 }
132
133
134 /*
135 * @implemented
136 */
137 int
138 WINAPI
139 _lclose(HFILE hFile)
140 {
141 return CloseHandle(LongToHandle(hFile)) ? 0 : HFILE_ERROR;
142 }
143
144
145 /*
146 * @implemented
147 */
148 LONG
149 WINAPI
150 _llseek(HFILE hFile, LONG lOffset, int iOrigin)
151 {
152 return SetFilePointer(LongToHandle(hFile),
153 lOffset,
154 NULL,
155 (DWORD) iOrigin);
156 }
157
158 /* EOF */