6 #ifndef USE_WINDOWS_FILE 24 #define kChunkSizeMax (1 << 22) 30 #ifdef USE_WINDOWS_FILE 31 p->handle = INVALID_HANDLE_VALUE;
37 #if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE) 40 #ifdef USE_WINDOWS_FILE 41 p->handle = CreateFileA(name,
42 writeMode ? GENERIC_WRITE : GENERIC_READ,
43 FILE_SHARE_READ,
NULL,
44 writeMode ? CREATE_ALWAYS : OPEN_EXISTING,
45 FILE_ATTRIBUTE_NORMAL,
NULL);
46 return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();
48 p->
file = fopen(name, writeMode ?
"wb+" :
"rb");
49 return (p->
file != 0) ? 0 :
62 #ifdef USE_WINDOWS_FILE 65 p->handle = CreateFileW(
name,
66 writeMode ? GENERIC_WRITE : GENERIC_READ,
67 FILE_SHARE_READ,
NULL,
68 writeMode ? CREATE_ALWAYS : OPEN_EXISTING,
69 FILE_ATTRIBUTE_NORMAL,
NULL);
70 return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();
72 WRes InFile_OpenW(
CSzFile *p,
const WCHAR *
name) {
return File_OpenW(p, name, 0); }
73 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)
81 if (!CloseHandle(p->handle))
82 return GetLastError();
83 p->handle = INVALID_HANDLE_VALUE;
99 size_t originalSize = *
size;
100 if (originalSize == 0)
103 #ifdef USE_WINDOWS_FILE 108 DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
110 BOOL
res = ReadFile(p->handle, data, curSize, &processed,
NULL);
111 data = (
void *)((
Byte *)data + processed);
112 originalSize -= processed;
115 return GetLastError();
119 while (originalSize > 0);
124 *size = fread(data, 1, originalSize, p->
file);
125 if (*size == originalSize)
127 return ferror(p->
file);
134 size_t originalSize = *
size;
135 if (originalSize == 0)
138 #ifdef USE_WINDOWS_FILE 143 DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
145 BOOL
res = WriteFile(p->handle, data, curSize, &processed,
NULL);
146 data = (
void *)((
Byte *)data + processed);
147 originalSize -= processed;
150 return GetLastError();
154 while (originalSize > 0);
159 *size = fwrite(data, 1, originalSize, p->
file);
160 if (*size == originalSize)
162 return ferror(p->
file);
169 #ifdef USE_WINDOWS_FILE 173 value.LowPart = (DWORD)*pos;
174 value.HighPart = (LONG)((
UInt64)*pos >> 16 >> 16);
178 case SZ_SEEK_CUR: moveMethod = FILE_CURRENT;
break;
180 default:
return ERROR_INVALID_PARAMETER;
182 value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);
183 if (value.LowPart == 0xFFFFFFFF)
189 *pos = ((
Int64)value.HighPart << 32) | value.LowPart;
203 res = fseek(p->
file, (
long)*pos, moveMethod);
204 *pos = ftell(p->
file);
212 #ifdef USE_WINDOWS_FILE 215 DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);
216 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)