6 #ifndef USE_WINDOWS_FILE 24 #define kChunkSizeMax (1 << 22) 29 #ifdef USE_WINDOWS_FILE 30 p->handle = INVALID_HANDLE_VALUE;
36 #if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE) 38 #ifdef USE_WINDOWS_FILE 39 p->handle = CreateFileA(name,
40 writeMode ? GENERIC_WRITE : GENERIC_READ,
43 writeMode ? CREATE_ALWAYS : OPEN_EXISTING,
44 FILE_ATTRIBUTE_NORMAL,
46 return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();
48 p->
file = fopen(name, writeMode ?
"wb+" :
"rb");
49 return (p->
file !=
nullptr) ? 0 :
62 #ifdef USE_WINDOWS_FILE 64 p->handle = CreateFileW(
name,
65 writeMode ? GENERIC_WRITE : GENERIC_READ,
68 writeMode ? CREATE_ALWAYS : OPEN_EXISTING,
69 FILE_ATTRIBUTE_NORMAL,
71 return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();
73 WRes InFile_OpenW(
CSzFile *p,
const WCHAR *
name) {
return File_OpenW(p, name, 0); }
74 WRes OutFile_OpenW(
CSzFile *p,
const WCHAR *
name) {
return File_OpenW(p, name, 1); }
78 #ifdef USE_WINDOWS_FILE 79 if (p->handle != INVALID_HANDLE_VALUE) {
80 if (!CloseHandle(p->handle))
81 return GetLastError();
82 p->handle = INVALID_HANDLE_VALUE;
85 if (p->
file !=
nullptr) {
96 size_t originalSize = *
size;
97 if (originalSize == 0)
100 #ifdef USE_WINDOWS_FILE 104 DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
106 BOOL
res = ReadFile(p->handle, data, curSize, &processed,
NULL);
107 data = (
void *)((
Byte *)data + processed);
108 originalSize -= processed;
111 return GetLastError();
114 }
while (originalSize > 0);
119 *size = fread(data, 1, originalSize, p->
file);
120 if (*size == originalSize)
122 return ferror(p->
file);
128 size_t originalSize = *
size;
129 if (originalSize == 0)
132 #ifdef USE_WINDOWS_FILE 136 DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
138 BOOL
res = WriteFile(p->handle, data, curSize, &processed,
NULL);
139 data = (
void *)((
Byte *)data + processed);
140 originalSize -= processed;
143 return GetLastError();
146 }
while (originalSize > 0);
151 *size = fwrite(data, 1, originalSize, p->
file);
152 if (*size == originalSize)
154 return ferror(p->
file);
160 #ifdef USE_WINDOWS_FILE 164 value.LowPart = (DWORD)*pos;
165 value.HighPart = (LONG)((
UInt64)*pos >> 16 >> 16);
168 moveMethod = FILE_BEGIN;
171 moveMethod = FILE_CURRENT;
174 moveMethod = FILE_END;
177 return ERROR_INVALID_PARAMETER;
179 value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);
180 if (value.LowPart == 0xFFFFFFFF) {
185 *pos = ((
Int64)value.HighPart << 32) | value.LowPart;
194 moveMethod = SEEK_SET;
197 moveMethod = SEEK_CUR;
200 moveMethod = SEEK_END;
205 res = fseek(p->
file, (
long)*pos, moveMethod);
206 *pos = ftell(p->
file);
213 #ifdef USE_WINDOWS_FILE 216 DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);
217 if (sizeLow == 0xFFFFFFFF) {
218 DWORD
res = GetLastError();
222 *length = (((
UInt64)sizeHigh) << 32) + sizeLow;
228 int res = fseek(p->
file, 0, SEEK_END);
229 *length = ftell(p->
file);
230 fseek(p->
file, pos, SEEK_SET);
static WRes File_Open(CSzFile *p, const char *name, int writeMode)
WRes File_Write(CSzFile *p, const void *data, size_t *size)
unsigned long long int UInt64
void FileInStream_CreateVTable(CFileInStream *p)
static SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size)
size_t(* Write)(void *p, const void *buf, size_t size)
WRes File_GetLength(CSzFile *p, UInt64 *length)
static size_t FileOutStream_Write(void *pp, const void *data, size_t size)
static SRes FileInStream_Read(void *pp, void *buf, size_t *size)
void File_Construct(CSzFile *p)
WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)
WRes File_Read(CSzFile *p, void *data, size_t *size)
SRes(* Read)(void *p, void *buf, size_t *size)
WRes OutFile_Open(CSzFile *p, const char *name)
static SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin)
WRes File_Close(CSzFile *p)
void FileOutStream_CreateVTable(CFileOutStream *p)
char data[epos_bytes_allocation]
void FileSeqInStream_CreateVTable(CFileSeqInStream *p)
SRes(* Seek)(void *p, Int64 *pos, ESzSeek origin)
WRes InFile_Open(CSzFile *p, const char *name)
SRes(* Read)(void *p, void *buf, size_t *size)