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 77 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  if (!CloseHandle(p->handle))
81  return GetLastError();
82  p->handle = INVALID_HANDLE_VALUE;
83  }
84 #else
85  if (p->file != nullptr) {
86  int res = fclose(p->file);
87  if (res != 0)
88  return res;
89  p->file = nullptr;
90  }
91 #endif
92  return 0;
93 }
FILE * file
Definition: 7zFile.h:27
Definition: Electron.h:6
void File_Construct ( CSzFile p)

Definition at line 28 of file 7zFile.cc.

References CSzFile::file.

Referenced by LzmaFile::Open().

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

Definition at line 212 of file 7zFile.cc.

References CSzFile::file.

212  {
213 #ifdef USE_WINDOWS_FILE
214 
215  DWORD sizeHigh;
216  DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);
217  if (sizeLow == 0xFFFFFFFF) {
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:88
FILE * file
Definition: 7zFile.h:27
Definition: Electron.h:6
static WRes File_Open ( CSzFile p,
const char *  name,
int  writeMode 
)
static

Definition at line 37 of file 7zFile.cc.

References CSzFile::file, and NULL.

Referenced by InFile_Open(), and OutFile_Open().

37  {
38 #ifdef USE_WINDOWS_FILE
39  p->handle = CreateFileA(name,
40  writeMode ? GENERIC_WRITE : GENERIC_READ,
41  FILE_SHARE_READ,
42  NULL,
43  writeMode ? CREATE_ALWAYS : OPEN_EXISTING,
44  FILE_ATTRIBUTE_NORMAL,
45  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:27
#define NULL
Definition: scimark2.h:8
WRes File_Read ( CSzFile p,
void *  data,
size_t *  size 
)

Definition at line 95 of file 7zFile.cc.

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

Referenced by FileInStream_Read(), and FileSeqInStream_Read().

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

Definition at line 159 of file 7zFile.cc.

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

Referenced by FileInStream_Seek().

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

Definition at line 127 of file 7zFile.cc.

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

Referenced by FileOutStream_Write().

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

Definition at line 257 of file 7zFile.cc.

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

257  {
258  p->s.Read = FileInStream_Read;
259  p->s.Seek = FileInStream_Seek;
260 }
static SRes FileInStream_Read(void *pp, void *buf, size_t *size)
Definition: 7zFile.cc:247
SRes(* Read)(void *p, void *buf, size_t *size)
Definition: Types.h:158
static SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin)
Definition: 7zFile.cc:252
ISeekInStream s
Definition: 7zFile.h:61
SRes(* Seek)(void *p, Int64 *pos, ESzSeek origin)
Definition: Types.h:159
static SRes FileInStream_Read ( void *  pp,
void *  buf,
size_t *  size 
)
static

Definition at line 247 of file 7zFile.cc.

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

Referenced by FileInStream_CreateVTable().

247  {
249  return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ;
250 }
size
Write out results.
CSzFile file
Definition: 7zFile.h:62
WRes File_Read(CSzFile *p, void *data, size_t *size)
Definition: 7zFile.cc:95
#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 252 of file 7zFile.cc.

References CFileInStream::file, and File_Seek().

Referenced by FileInStream_CreateVTable().

252  {
254  return File_Seek(&p->file, pos, origin);
255 }
CSzFile file
Definition: 7zFile.h:62
WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)
Definition: 7zFile.cc:159
void FileOutStream_CreateVTable ( CFileOutStream p)

Definition at line 270 of file 7zFile.cc.

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

270 { p->s.Write = FileOutStream_Write; }
size_t(* Write)(void *p, const void *buf, size_t size)
Definition: Types.h:150
static size_t FileOutStream_Write(void *pp, const void *data, size_t size)
Definition: 7zFile.cc:264
ISeqOutStream s
Definition: 7zFile.h:68
static size_t FileOutStream_Write ( void *  pp,
const void *  data,
size_t  size 
)
static

Definition at line 264 of file 7zFile.cc.

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

Referenced by FileOutStream_CreateVTable().

264  {
266  File_Write(&p->file, data, &size);
267  return size;
268 }
size
Write out results.
WRes File_Write(CSzFile *p, const void *data, size_t *size)
Definition: 7zFile.cc:127
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
CSzFile file
Definition: 7zFile.h:69
void FileSeqInStream_CreateVTable ( CFileSeqInStream p)

Definition at line 243 of file 7zFile.cc.

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

Referenced by LzmaFile::Open().

243 { p->s.Read = FileSeqInStream_Read; }
static SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size)
Definition: 7zFile.cc:238
ISeqInStream s
Definition: 7zFile.h:54
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 238 of file 7zFile.cc.

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

Referenced by FileSeqInStream_CreateVTable().

238  {
240  return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ;
241 }
size
Write out results.
CSzFile file
Definition: 7zFile.h:55
WRes File_Read(CSzFile *p, void *data, size_t *size)
Definition: 7zFile.cc:95
#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:37
WRes OutFile_Open ( CSzFile p,
const char *  name 
)

Definition at line 59 of file 7zFile.cc.

References File_Open(), Skims_PA_cff::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:37