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.

References AlCaHLTBitMon_ParallelJobs::p.

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 }
Definition: Electron.h:6

◆ File_Construct()

void File_Construct ( CSzFile p)

Definition at line 28 of file 7zFile.cc.

References AlCaHLTBitMon_ParallelJobs::p.

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_GetLength()

WRes File_GetLength ( CSzFile p,
UInt64 length 
)

Definition at line 212 of file 7zFile.cc.

References AlCaHLTBitMon_ParallelJobs::p.

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
Definition: Electron.h:6

◆ File_Read()

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

Definition at line 95 of file 7zFile.cc.

References data, NULL, AlCaHLTBitMon_ParallelJobs::p, 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.
#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

◆ File_Seek()

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

Definition at line 159 of file 7zFile.cc.

References AlCaHLTBitMon_ParallelJobs::p, 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
int WRes
Definition: Types.h:48
Definition: Electron.h:6
Definition: value.py:1
long long int Int64
Definition: Types.h:87

◆ File_Write()

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

Definition at line 127 of file 7zFile.cc.

References data, NULL, AlCaHLTBitMon_ParallelJobs::p, 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.
#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

◆ FileInStream_CreateVTable()

void FileInStream_CreateVTable ( CFileInStream p)

Definition at line 257 of file 7zFile.cc.

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

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
static SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin)
Definition: 7zFile.cc:252

◆ FileOutStream_CreateVTable()

void FileOutStream_CreateVTable ( CFileOutStream p)

Definition at line 270 of file 7zFile.cc.

References FileOutStream_Write(), and AlCaHLTBitMon_ParallelJobs::p.

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

◆ FileSeqInStream_CreateVTable()

void FileSeqInStream_CreateVTable ( CFileSeqInStream p)

Definition at line 243 of file 7zFile.cc.

References FileSeqInStream_Read(), and AlCaHLTBitMon_ParallelJobs::p.

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

◆ InFile_Open()

WRes InFile_Open ( CSzFile p,
const char *  name 
)

Definition at line 58 of file 7zFile.cc.

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

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

◆ OutFile_Open()

WRes OutFile_Open ( CSzFile p,
const char *  name 
)

Definition at line 59 of file 7zFile.cc.

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

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