CMS 3D CMS Logo

Functions
7zFile.cc File Reference
#include "7zFile.h"
#include <cerrno>

Go to the source code of this file.

Functions

WRes File_Close (CSzFile *p)
 
void File_Construct (CSzFile *p)
 
WRes File_GetLength (CSzFile *p, UInt64 *length)
 
static WRes File_Open (CSzFile *p, const char *name, int writeMode)
 
WRes File_Read (CSzFile *p, void *data, size_t *size)
 
WRes File_Seek (CSzFile *p, Int64 *pos, ESzSeek origin)
 
WRes File_Write (CSzFile *p, const void *data, size_t *size)
 
void FileInStream_CreateVTable (CFileInStream *p)
 
static SRes FileInStream_Read (void *pp, void *buf, size_t *size)
 
static SRes FileInStream_Seek (void *pp, Int64 *pos, ESzSeek origin)
 
void FileOutStream_CreateVTable (CFileOutStream *p)
 
static size_t FileOutStream_Write (void *pp, const void *data, size_t size)
 
void FileSeqInStream_CreateVTable (CFileSeqInStream *p)
 
static SRes FileSeqInStream_Read (void *pp, void *buf, size_t *size)
 
WRes InFile_Open (CSzFile *p, const char *name)
 
WRes OutFile_Open (CSzFile *p, const char *name)
 

Function Documentation

WRes File_Close ( CSzFile p)

Definition at line 76 of file 7zFile.cc.

References CSzFile::file.

Referenced by LzmaFile::Close().

77 {
78  #ifdef USE_WINDOWS_FILE
79  if (p->handle != INVALID_HANDLE_VALUE)
80  {
81  if (!CloseHandle(p->handle))
82  return GetLastError();
83  p->handle = INVALID_HANDLE_VALUE;
84  }
85  #else
86  if (p->file != nullptr)
87  {
88  int res = fclose(p->file);
89  if (res != 0)
90  return res;
91  p->file = nullptr;
92  }
93  #endif
94  return 0;
95 }
FILE * file
Definition: 7zFile.h:28
Definition: Electron.h:6
void File_Construct ( CSzFile p)

Definition at line 28 of file 7zFile.cc.

References CSzFile::file.

Referenced by LzmaFile::Open().

29 {
30  #ifdef USE_WINDOWS_FILE
31  p->handle = INVALID_HANDLE_VALUE;
32  #else
33  p->file = nullptr;
34  #endif
35 }
FILE * file
Definition: 7zFile.h:28
WRes File_GetLength ( CSzFile p,
UInt64 length 
)

Definition at line 210 of file 7zFile.cc.

References CSzFile::file.

211 {
212  #ifdef USE_WINDOWS_FILE
213 
214  DWORD sizeHigh;
215  DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);
216  if (sizeLow == 0xFFFFFFFF)
217  {
218  DWORD res = GetLastError();
219  if (res != NO_ERROR)
220  return res;
221  }
222  *length = (((UInt64)sizeHigh) << 32) + sizeLow;
223  return 0;
224 
225  #else
226 
227  long pos = ftell(p->file);
228  int res = fseek(p->file, 0, SEEK_END);
229  *length = ftell(p->file);
230  fseek(p->file, pos, SEEK_SET);
231  return res;
232 
233  #endif
234 }
unsigned long long int UInt64
Definition: Types.h:83
FILE * file
Definition: 7zFile.h:28
Definition: Electron.h:6
static WRes File_Open ( CSzFile p,
const char *  name,
int  writeMode 
)
static

Definition at line 38 of file 7zFile.cc.

References CSzFile::file, and NULL.

Referenced by InFile_Open(), and OutFile_Open().

39 {
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();
47  #else
48  p->file = fopen(name, writeMode ? "wb+" : "rb");
49  return (p->file != nullptr) ? 0 :
50  #ifdef UNDER_CE
51  2; /* ENOENT */
52  #else
53  errno;
54  #endif
55  #endif
56 }
FILE * file
Definition: 7zFile.h:28
#define NULL
Definition: scimark2.h:8
WRes File_Read ( CSzFile p,
void *  data,
size_t *  size 
)

Definition at line 97 of file 7zFile.cc.

References CSzFile::file, NULL, and findQualityFiles::size.

Referenced by FileInStream_Read(), and FileSeqInStream_Read().

98 {
99  size_t originalSize = *size;
100  if (originalSize == 0)
101  return 0;
102 
103  #ifdef USE_WINDOWS_FILE
104 
105  *size = 0;
106  do
107  {
108  DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
109  DWORD processed = 0;
110  BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);
111  data = (void *)((Byte *)data + processed);
112  originalSize -= processed;
113  *size += processed;
114  if (!res)
115  return GetLastError();
116  if (processed == 0)
117  break;
118  }
119  while (originalSize > 0);
120  return 0;
121 
122  #else
123 
124  *size = fread(data, 1, originalSize, p->file);
125  if (*size == originalSize)
126  return 0;
127  return ferror(p->file);
128 
129  #endif
130 }
size
Write out results.
FILE * file
Definition: 7zFile.h:28
#define NULL
Definition: scimark2.h:8
Definition: Electron.h:6
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
unsigned char Byte
Definition: Types.h:55
WRes File_Seek ( CSzFile p,
Int64 pos,
ESzSeek  origin 
)

Definition at line 167 of file 7zFile.cc.

References CSzFile::file, SZ_SEEK_CUR, SZ_SEEK_END, SZ_SEEK_SET, and relativeConstraints::value.

Referenced by FileInStream_Seek().

168 {
169  #ifdef USE_WINDOWS_FILE
170 
171  LARGE_INTEGER value;
172  DWORD moveMethod;
173  value.LowPart = (DWORD)*pos;
174  value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */
175  switch (origin)
176  {
177  case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;
178  case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;
179  case SZ_SEEK_END: moveMethod = FILE_END; break;
180  default: return ERROR_INVALID_PARAMETER;
181  }
182  value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);
183  if (value.LowPart == 0xFFFFFFFF)
184  {
185  WRes res = GetLastError();
186  if (res != NO_ERROR)
187  return res;
188  }
189  *pos = ((Int64)value.HighPart << 32) | value.LowPart;
190  return 0;
191 
192  #else
193 
194  int moveMethod;
195  int res;
196  switch (origin)
197  {
198  case SZ_SEEK_SET: moveMethod = SEEK_SET; break;
199  case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;
200  case SZ_SEEK_END: moveMethod = SEEK_END; break;
201  default: return 1;
202  }
203  res = fseek(p->file, (long)*pos, moveMethod);
204  *pos = ftell(p->file);
205  return res;
206 
207  #endif
208 }
unsigned long long int UInt64
Definition: Types.h:83
FILE * file
Definition: 7zFile.h:28
int WRes
Definition: Types.h:48
Definition: Electron.h:6
long long int Int64
Definition: Types.h:82
WRes File_Write ( CSzFile p,
const void *  data,
size_t *  size 
)

Definition at line 132 of file 7zFile.cc.

References CSzFile::file, NULL, and findQualityFiles::size.

Referenced by FileOutStream_Write().

133 {
134  size_t originalSize = *size;
135  if (originalSize == 0)
136  return 0;
137 
138  #ifdef USE_WINDOWS_FILE
139 
140  *size = 0;
141  do
142  {
143  DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
144  DWORD processed = 0;
145  BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL);
146  data = (void *)((Byte *)data + processed);
147  originalSize -= processed;
148  *size += processed;
149  if (!res)
150  return GetLastError();
151  if (processed == 0)
152  break;
153  }
154  while (originalSize > 0);
155  return 0;
156 
157  #else
158 
159  *size = fwrite(data, 1, originalSize, p->file);
160  if (*size == originalSize)
161  return 0;
162  return ferror(p->file);
163 
164  #endif
165 }
size
Write out results.
FILE * file
Definition: 7zFile.h:28
#define NULL
Definition: scimark2.h:8
Definition: Electron.h:6
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
unsigned char Byte
Definition: Types.h:55
void FileInStream_CreateVTable ( CFileInStream p)

Definition at line 265 of file 7zFile.cc.

References FileInStream_Read(), FileInStream_Seek(), ISeekInStream::Read, CFileInStream::s, and ISeekInStream::Seek.

266 {
267  p->s.Read = FileInStream_Read;
268  p->s.Seek = FileInStream_Seek;
269 }
static SRes FileInStream_Read(void *pp, void *buf, size_t *size)
Definition: 7zFile.cc:253
SRes(* Read)(void *p, void *buf, size_t *size)
Definition: Types.h:165
static SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin)
Definition: 7zFile.cc:259
ISeekInStream s
Definition: 7zFile.h:66
SRes(* Seek)(void *p, Int64 *pos, ESzSeek origin)
Definition: Types.h:166
static SRes FileInStream_Read ( void *  pp,
void *  buf,
size_t *  size 
)
static

Definition at line 253 of file 7zFile.cc.

References CFileInStream::file, File_Read(), SZ_ERROR_READ, and SZ_OK.

Referenced by FileInStream_CreateVTable().

254 {
256  return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ;
257 }
size
Write out results.
CSzFile file
Definition: 7zFile.h:67
WRes File_Read(CSzFile *p, void *data, size_t *size)
Definition: 7zFile.cc:97
#define SZ_ERROR_READ
Definition: Types.h:34
#define SZ_OK
Definition: Types.h:25
static SRes FileInStream_Seek ( void *  pp,
Int64 pos,
ESzSeek  origin 
)
static

Definition at line 259 of file 7zFile.cc.

References CFileInStream::file, and File_Seek().

Referenced by FileInStream_CreateVTable().

260 {
262  return File_Seek(&p->file, pos, origin);
263 }
CSzFile file
Definition: 7zFile.h:67
WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)
Definition: 7zFile.cc:167
void FileOutStream_CreateVTable ( CFileOutStream p)

Definition at line 281 of file 7zFile.cc.

References FileOutStream_Write(), CFileOutStream::s, and ISeqOutStream::Write.

282 {
284 }
size_t(* Write)(void *p, const void *buf, size_t size)
Definition: Types.h:151
static size_t FileOutStream_Write(void *pp, const void *data, size_t size)
Definition: 7zFile.cc:274
ISeqOutStream s
Definition: 7zFile.h:75
static size_t FileOutStream_Write ( void *  pp,
const void *  data,
size_t  size 
)
static

Definition at line 274 of file 7zFile.cc.

References CFileOutStream::file, File_Write(), and findQualityFiles::size.

Referenced by FileOutStream_CreateVTable().

275 {
277  File_Write(&p->file, data, &size);
278  return size;
279 }
size
Write out results.
WRes File_Write(CSzFile *p, const void *data, size_t *size)
Definition: 7zFile.cc:132
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
CSzFile file
Definition: 7zFile.h:76
void FileSeqInStream_CreateVTable ( CFileSeqInStream p)

Definition at line 245 of file 7zFile.cc.

References FileSeqInStream_Read(), ISeqInStream::Read, and CFileSeqInStream::s.

Referenced by LzmaFile::Open().

246 {
248 }
static SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size)
Definition: 7zFile.cc:239
ISeqInStream s
Definition: 7zFile.h:57
SRes(* Read)(void *p, void *buf, size_t *size)
Definition: Types.h:139
static SRes FileSeqInStream_Read ( void *  pp,
void *  buf,
size_t *  size 
)
static

Definition at line 239 of file 7zFile.cc.

References CFileSeqInStream::file, File_Read(), SZ_ERROR_READ, and SZ_OK.

Referenced by FileSeqInStream_CreateVTable().

240 {
242  return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ;
243 }
size
Write out results.
CSzFile file
Definition: 7zFile.h:58
WRes File_Read(CSzFile *p, void *data, size_t *size)
Definition: 7zFile.cc:97
#define SZ_ERROR_READ
Definition: Types.h:34
#define SZ_OK
Definition: Types.h:25
WRes InFile_Open ( CSzFile p,
const char *  name 
)

Definition at line 58 of file 7zFile.cc.

References File_Open().

Referenced by LzmaFile::Open().

58 { return File_Open(p, name, 0); }
static WRes File_Open(CSzFile *p, const char *name, int writeMode)
Definition: 7zFile.cc:38
WRes OutFile_Open ( CSzFile p,
const char *  name 
)

Definition at line 59 of file 7zFile.cc.

References File_Open(), dataset::name, NULL, AlCaHLTBitMon_ParallelJobs::p, and EcalSimRawData_cfi::writeMode.

59 { return File_Open(p, name, 1); }
static WRes File_Open(CSzFile *p, const char *name, int writeMode)
Definition: 7zFile.cc:38