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