CMS 3D CMS Logo

Classes | Functions
7zFile.h File Reference
#include <cstdio>
#include "Types.h"

Go to the source code of this file.

Classes

struct  CFileInStream
 
struct  CFileOutStream
 
struct  CFileSeqInStream
 
struct  CSzFile
 

Functions

WRes File_Close (CSzFile *p)
 
void File_Construct (CSzFile *p)
 
WRes File_GetLength (CSzFile *p, UInt64 *length)
 
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)
 
void FileOutStream_CreateVTable (CFileOutStream *p)
 
void FileSeqInStream_CreateVTable (CFileSeqInStream *p)
 
WRes InFile_Open (CSzFile *p, const char *name)
 
WRes OutFile_Open (CSzFile *p, const char *name)
 

Function Documentation

◆ File_Close()

WRes File_Close ( CSzFile p)

Definition at line 77 of file 7zFile.cc.

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 }

References AlCaHLTBitMon_ParallelJobs::p.

Referenced by LzmaFile::Close().

◆ File_Construct()

void File_Construct ( CSzFile p)

Definition at line 28 of file 7zFile.cc.

28  {
29 #ifdef USE_WINDOWS_FILE
30  p->handle = INVALID_HANDLE_VALUE;
31 #else
32  p->file = nullptr;
33 #endif
34 }

References AlCaHLTBitMon_ParallelJobs::p.

Referenced by LzmaFile::Open().

◆ File_GetLength()

WRes File_GetLength ( CSzFile p,
UInt64 length 
)

Definition at line 212 of file 7zFile.cc.

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 }

References AlCaHLTBitMon_ParallelJobs::p.

◆ File_Read()

WRes File_Read ( CSzFile p,
void *  data,
size_t *  size 
)

Definition at line 95 of file 7zFile.cc.

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 }

References data, NULL, AlCaHLTBitMon_ParallelJobs::p, and findQualityFiles::size.

Referenced by FileInStream_Read(), and FileSeqInStream_Read().

◆ File_Seek()

WRes File_Seek ( CSzFile p,
Int64 pos,
ESzSeek  origin 
)

Definition at line 159 of file 7zFile.cc.

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 }

References AlCaHLTBitMon_ParallelJobs::p, SZ_SEEK_CUR, SZ_SEEK_END, SZ_SEEK_SET, and relativeConstraints::value.

Referenced by FileInStream_Seek().

◆ File_Write()

WRes File_Write ( CSzFile p,
const void *  data,
size_t *  size 
)

Definition at line 127 of file 7zFile.cc.

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 }

References data, NULL, AlCaHLTBitMon_ParallelJobs::p, and findQualityFiles::size.

Referenced by FileOutStream_Write().

◆ FileInStream_CreateVTable()

void FileInStream_CreateVTable ( CFileInStream p)

Definition at line 257 of file 7zFile.cc.

257  {
258  p->s.Read = FileInStream_Read;
259  p->s.Seek = FileInStream_Seek;
260 }

References FileInStream_Read(), FileInStream_Seek(), and AlCaHLTBitMon_ParallelJobs::p.

◆ FileOutStream_CreateVTable()

void FileOutStream_CreateVTable ( CFileOutStream p)

Definition at line 270 of file 7zFile.cc.

270 { p->s.Write = FileOutStream_Write; }

References FileOutStream_Write(), and AlCaHLTBitMon_ParallelJobs::p.

◆ FileSeqInStream_CreateVTable()

void FileSeqInStream_CreateVTable ( CFileSeqInStream p)

Definition at line 243 of file 7zFile.cc.

243 { p->s.Read = FileSeqInStream_Read; }

References FileSeqInStream_Read(), and AlCaHLTBitMon_ParallelJobs::p.

Referenced by LzmaFile::Open().

◆ InFile_Open()

WRes InFile_Open ( CSzFile p,
const char *  name 
)

Definition at line 58 of file 7zFile.cc.

58 { return File_Open(p, name, 0); }

References File_Open(), Skims_PA_cff::name, and AlCaHLTBitMon_ParallelJobs::p.

Referenced by LzmaFile::Open().

◆ OutFile_Open()

WRes OutFile_Open ( CSzFile p,
const char *  name 
)

Definition at line 59 of file 7zFile.cc.

59 { return File_Open(p, name, 1); }

References File_Open(), Skims_PA_cff::name, and AlCaHLTBitMon_ParallelJobs::p.

Byte
unsigned char Byte
Definition: Types.h:60
SZ_SEEK_END
Definition: Types.h:155
FileSeqInStream_Read
static SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size)
Definition: 7zFile.cc:238
WRes
int WRes
Definition: Types.h:48
File_Open
static WRes File_Open(CSzFile *p, const char *name, int writeMode)
Definition: 7zFile.cc:37
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
pos
Definition: PixelAliasList.h:18
UInt64
unsigned long long int UInt64
Definition: Types.h:88
FileInStream_Read
static SRes FileInStream_Read(void *pp, void *buf, size_t *size)
Definition: 7zFile.cc:247
FileOutStream_Write
static size_t FileOutStream_Write(void *pp, const void *data, size_t size)
Definition: 7zFile.cc:264
Int64
long long int Int64
Definition: Types.h:87
value
Definition: value.py:1
SZ_SEEK_SET
Definition: Types.h:155
res
Definition: Electron.h:6
NULL
#define NULL
Definition: scimark2.h:8
relativeConstraints.value
value
Definition: relativeConstraints.py:53
FileInStream_Seek
static SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin)
Definition: 7zFile.cc:252
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
SZ_SEEK_CUR
Definition: Types.h:155
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443