This commit was generated by cvs2svn to compensate for changes in r52,
[reactos.git] / reactos / lib / kernel32 / file / lfile.c
1 /*
2 * created: Boudewijn Dekker
3 * org. source: WINE
4 * date: june 1998
5 * todo: check the _lopen for correctness
6 */
7
8 #undef WIN32_LEAN_AND_MEAN
9 #include <windows.h>
10 #include <string.h>
11 #include <wstring.h>
12 #include <fcntl.h>
13
14
15
16 long _hread(
17 HFILE hFile,
18 LPVOID lpBuffer,
19 long lBytes
20 )
21 {
22 DWORD NumberOfBytesRead;
23 if ( ReadFile((HANDLE)hFile,(LPCVOID)lpBuffer,(DWORD)lBytes,&NumberOfBytesRead, NULL) == FALSE )
24 return -1;
25 else
26 return NumberOfBytesRead;
27
28 }
29
30 UINT STDCALL _lread(HFILE fd,LPVOID buffer,UINT count)
31 {
32 return _hread(fd,buffer, count);
33 }
34
35
36 long _hwrite(
37 HFILE hFile,
38 LPCSTR lpBuffer,
39 long lBytes
40 )
41 {
42
43 DWORD NumberOfBytesWritten;
44 if ( lBytes == 0 ) {
45 if ( SetEndOfFile((HANDLE) hFile ) == FALSE )
46 return -1;
47 else
48 return 0;
49 }
50 if ( WriteFile((HANDLE)hFile,(LPCVOID)lpBuffer,(DWORD)lBytes, &NumberOfBytesWritten,NULL) == FALSE )
51 return -1;
52 else
53 return NumberOfBytesWritten;
54
55 }
56
57 UINT
58 STDCALL
59 _lwrite(
60 HFILE hFile,
61 LPCSTR lpBuffer,
62 UINT uBytes
63 )
64 {
65 return _hwrite(hFile,lpBuffer,uBytes);
66 }
67
68 #define OF_OPENMASK (OF_READ|OF_READWRITE|OF_WRITE|OF_CREATE)
69 #define OF_FILEMASK (OF_DELETE|OF_PARSE)
70 #define OF_MASK (OF_OPENMASK|OF_FILEMASK)
71
72 HFILE _open( LPCSTR lpPathName, int iReadWrite )
73 {
74
75
76
77 HFILE fd;
78 int nFunction;
79
80
81
82
83 /* Don't assume a 1:1 relationship between OF_* modes and O_* modes */
84 /* Here we translate the read/write permission bits (which had better */
85 /* be the low 2 bits. If not, we're in trouble. Other bits are */
86 /* passed through unchanged */
87
88 nFunction = wFunction & 3;
89
90 switch (wFunction & 3) {
91 case OF_READ:
92 nFunction |= O_RDONLY;
93 break;
94 case OF_READWRITE:
95 nFunction |= O_RDWR;
96 break;
97 case OF_WRITE:
98 nFunction |= O_WRONLY;
99 break;
100 default:
101 //ERRSTR((LF_ERROR, "_lopen: bad file open mode %x\n", wFunction));
102 return HFILE_ERROR;
103 }
104 SetLastError(0);
105 fd = CreateFileA( filename,nFunction,OPEN_EXISTING,
106 NULL,OPEN_EXISTING,NULL,NULL);
107 if (fd == INVALID_HANDLE_VALUE )
108 return HFILE_ERROR;
109 return fd;
110 }
111
112 int _creat(const char *filename, int pmode)
113 {
114 SetLastError(0);
115 return CreateFileA( filename,GENERIC_READ & GENERIC_WRITE,FILE_SHARE_WRITE,
116 NULL,CREATE_ALWAYS,pmode & 0x00003FB7,NULL);
117 }
118
119
120 int _lclose(
121 HFILE hFile
122 )
123 {
124 if ( CloseHandle((HANDLE)hFile) )
125 return 0;
126 else
127 return -1;
128 }
129
130 LONG _llseek(
131 HFILE hFile,
132 LONG lOffset,
133 int iOrigin
134 )
135 {
136 return SetFilePointer((HANDLE) hFile, lOffset, NULL,(DWORD)iOrigin );
137 }
138
139