ReactOS  0.4.14-dev-833-g5f692ed
CCFDATAStorage.cxx
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS cabinet manager
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: CCFDATAStorage class implementation for Linux/Unix
5  * COPYRIGHT: Copyright 2017 Casper S. Hornstrup (chorns@users.sourceforge.net)
6  * Copyright 2017 Colin Finck <mail@colinfinck.de>
7  * Copyright 2018 Dmitry Bagdanov <dimbo_job@mail.ru>
8  */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <sys/stat.h>
13 #include <sys/types.h>
14 
15 #if !defined(_WIN32)
16 #include <dirent.h>
17 #endif
18 
19 #include "cabinet.h"
20 #include "raw.h"
21 #include "mszip.h"
22 
23 #if !defined(CAB_READ_ONLY)
24 
32 {
33  FileHandle = NULL;
34 }
35 
43 {
45 }
46 
57 {
58 #if defined(_WIN32)
59  char TmpName[PATH_MAX];
60  char *pName;
61  int length;
62 
63  if (tmpnam(TmpName) == NULL)
65 
66  /* Append 'tmp' if the file name ends with a dot */
68  if (length > 0 && TmpName[length - 1] == '.')
69  strcat(TmpName, "tmp");
70 
71  /* Skip a leading slash or backslash */
72  pName = TmpName;
73  if (*pName == '/' || *pName == '\\')
74  pName++;
75 
77 
78  FileHandle = fopen(FullName, "w+b");
79  if (FileHandle == NULL)
81 #else
82  if ((FileHandle = tmpfile()) == NULL)
84 #endif
85  return CAB_STATUS_SUCCESS;
86 }
87 
98 {
100 
102 
103  FileHandle = NULL;
104 
105 #if defined(_WIN32)
106  remove(FullName);
107 #endif
108 
109  return CAB_STATUS_SUCCESS;
110 }
111 
122 {
124 #if defined(_WIN32)
125  FileHandle = fopen(FullName, "w+b");
126 #else
127  FileHandle = tmpfile();
128 #endif
129  if (FileHandle == NULL)
130  {
131  DPRINT(MID_TRACE, ("ERROR '%i'.\n", errno));
132  return CAB_STATUS_FAILURE;
133  }
134 
135  return CAB_STATUS_SUCCESS;
136 }
137 
148 {
149  return (ULONG)ftell(FileHandle);
150 }
151 
152 
166 {
167  if (fseek(FileHandle, (off_t)Position, SEEK_SET) != 0)
168  return CAB_STATUS_FAILURE;
169  else
170  return CAB_STATUS_SUCCESS;
171 }
172 
173 
193 {
194  *BytesRead = fread(Buffer, 1, Data->CompSize, FileHandle);
195  if (*BytesRead != Data->CompSize)
196  return CAB_STATUS_CANNOT_READ;
197 
198  return CAB_STATUS_SUCCESS;
199 }
200 
201 
221 {
222  *BytesWritten = fwrite(Buffer, 1, Data->CompSize, FileHandle);
223  if (*BytesWritten != Data->CompSize)
225 
226  return CAB_STATUS_SUCCESS;
227 }
228 
229 
230 #endif /* CAB_READ_ONLY */
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
#define MID_TRACE
Definition: debug.h:15
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define CAB_STATUS_CANNOT_READ
Definition: cabinet.h:28
static COORD Position
Definition: mouse.c:34
__kernel_off_t off_t
Definition: linux.h:201
ULONG Seek(LONG Position)
virtual ~CCFDATAStorage()
int errno
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
long LONG
Definition: pedump.c:60
FILE * FileHandle
Definition: cabinet.h:316
#define CAB_STATUS_CANNOT_WRITE
Definition: cabinet.h:29
smooth NULL
Definition: ftsmooth.c:416
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
_Check_return_ _CRTIMP FILE *__cdecl tmpfile(void)
Definition: file.c:3912
#define SEEK_SET
Definition: jmemansi.c:26
static LPSTR pName
Definition: security.c:75
ULONG ReadBlock(PCFDATA Data, void *Buffer, PULONG BytesRead)
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define CAB_STATUS_CANNOT_CREATE
Definition: cabinet.h:27
#define CAB_STATUS_FAILURE
Definition: cabinet.h:24
#define PATH_MAX
Definition: types.h:280
#define CAB_STATUS_SUCCESS
Definition: cabinet.h:23
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
char FullName[PATH_MAX]
Definition: cabinet.h:315
static char TmpName[PATH_MAX]
Definition: cache.c:23
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_CRTIMP char *__cdecl tmpnam(_Pre_maybenull_ _Post_z_ char *_Buffer)
unsigned int * PULONG
Definition: retypes.h:1
ULONG WriteBlock(PCFDATA Data, void *Buffer, PULONG BytesWritten)
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)
unsigned int ULONG
Definition: retypes.h:1
int remove
Definition: msacm.c:1365
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255