ReactOS 0.4.15-dev-7931-gfd331f1
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
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 "CCFDATAStorage.h"
20#include "raw.h"
21#include "mszip.h"
22
23#if !defined(CAB_READ_ONLY)
24
32{
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
104
105#if defined(_WIN32)
107#endif
108
109 return CAB_STATUS_SUCCESS;
110}
111
122{
124#if defined(_WIN32)
125 FileHandle = fopen(FullName, "w+b");
126#else
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{
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)
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 */
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define PATH_MAX
Definition: types.h:280
#define MID_TRACE
Definition: debug.h:15
#define CAB_STATUS_CANNOT_READ
Definition: cabinet.h:28
#define CAB_STATUS_FAILURE
Definition: cabinet.h:24
#define CAB_STATUS_CANNOT_CREATE
Definition: cabinet.h:27
#define CAB_STATUS_SUCCESS
Definition: cabinet.h:23
#define CAB_STATUS_CANNOT_WRITE
Definition: cabinet.h:29
Definition: bufpool.h:45
ULONG ReadBlock(PCFDATA Data, void *Buffer, PULONG BytesRead)
virtual ~CCFDATAStorage()
ULONG Seek(LONG Position)
char FullName[PATH_MAX]
ULONG WriteBlock(PCFDATA Data, void *Buffer, PULONG BytesWritten)
#define NULL
Definition: types.h:112
__kernel_off_t off_t
Definition: linux.h:201
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
_CRTIMP char *__cdecl tmpnam(_Pre_maybenull_ _Post_z_ char *_Buffer)
_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)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)
_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_ _CRTIMP FILE *__cdecl tmpfile(void)
Definition: file.c:3914
#define SEEK_SET
Definition: jmemansi.c:26
#define ASSERT(a)
Definition: mode.c:44
static LPSTR pName
Definition: security.c:75
int remove
Definition: msacm.c:1366
long LONG
Definition: pedump.c:60
#define errno
Definition: errno.h:18
static char TmpName[PATH_MAX]
Definition: cache.c:23
#define DPRINT
Definition: sndvol32.h:71
static COORD Position
Definition: mouse.c:34
uint32_t * PULONG
Definition: typedefs.h:59
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:960
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870