ocran 1.3.17 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.txt +306 -272
- data/LICENSE.txt +22 -22
- data/README.md +549 -531
- data/exe/ocran +5 -5
- data/ext/extconf.rb +15 -0
- data/lib/ocran/build_constants.rb +16 -16
- data/lib/ocran/build_facade.rb +17 -17
- data/lib/ocran/build_helper.rb +110 -105
- data/lib/ocran/command_output.rb +22 -22
- data/lib/ocran/dir_builder.rb +162 -0
- data/lib/ocran/direction.rb +623 -386
- data/lib/ocran/file_path_set.rb +69 -69
- data/lib/ocran/gem_spec_queryable.rb +172 -172
- data/lib/ocran/host_config_helper.rb +57 -37
- data/lib/ocran/inno_setup_script_builder.rb +111 -111
- data/lib/ocran/launcher_batch_builder.rb +85 -85
- data/lib/ocran/library_detector.rb +61 -61
- data/lib/ocran/library_detector_posix.rb +55 -0
- data/lib/ocran/option.rb +323 -273
- data/lib/ocran/refine_pathname.rb +104 -104
- data/lib/ocran/runner.rb +115 -105
- data/lib/ocran/runtime_environment.rb +46 -46
- data/lib/ocran/stub_builder.rb +298 -224
- data/lib/ocran/version.rb +5 -5
- data/lib/ocran/windows_command_escaping.rb +15 -15
- data/lib/ocran.rb +7 -7
- data/share/ocran/lzma.exe +0 -0
- data/src/Makefile +75 -0
- data/src/edicon.c +161 -0
- data/src/error.c +100 -0
- data/src/error.h +66 -0
- data/src/inst_dir.c +334 -0
- data/src/inst_dir.h +157 -0
- data/src/lzma/7zTypes.h +529 -0
- data/src/lzma/Compiler.h +43 -0
- data/src/lzma/LzmaDec.c +1363 -0
- data/src/lzma/LzmaDec.h +236 -0
- data/src/lzma/Precomp.h +10 -0
- data/src/script_info.c +246 -0
- data/src/script_info.h +7 -0
- data/src/stub.c +133 -0
- data/src/stub.manifest +29 -0
- data/src/stub.rc +3 -0
- data/src/system_utils.c +1002 -0
- data/src/system_utils.h +209 -0
- data/src/system_utils_posix.c +500 -0
- data/src/unpack.c +574 -0
- data/src/unpack.h +85 -0
- data/src/vit-ruby.ico +0 -0
- metadata +55 -22
- data/share/ocran/edicon.exe +0 -0
- data/share/ocran/stub.exe +0 -0
- data/share/ocran/stubw.exe +0 -0
data/src/inst_dir.h
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
#include <stdbool.h>
|
|
2
|
+
#include <stddef.h>
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @brief Creates an installation directory with a unique name.
|
|
6
|
+
*
|
|
7
|
+
* Attempts to create a directory within the specified target directory. This
|
|
8
|
+
* directory is assigned a unique name based on the "ocran" prefix to avoid
|
|
9
|
+
* conflicts. The function manages the lifetime of the created directory path's
|
|
10
|
+
* memory, which should not be freed by the caller.
|
|
11
|
+
* If directory cleanup is needed, call FreeInstDir().
|
|
12
|
+
*
|
|
13
|
+
* @param is_extract_to_exe_dir
|
|
14
|
+
* If true, the extraction directory will be created in the same folder as
|
|
15
|
+
* the executable; if false, it will be created in the system’s temporary
|
|
16
|
+
* directory.
|
|
17
|
+
* @return
|
|
18
|
+
* A pointer to the created directory path if successful, NULL if an error
|
|
19
|
+
* occurred. The returned path should not be freed by the caller.
|
|
20
|
+
*/
|
|
21
|
+
const char *CreateInstDir(bool is_extract_to_exe_dir);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @brief Free the allocated installation directory path
|
|
25
|
+
* and reset the internal pointer to NULL.
|
|
26
|
+
*
|
|
27
|
+
* Frees memory previously allocated for the installation directory path
|
|
28
|
+
* and clears the stored pointer so that GetInstDir() returns NULL until
|
|
29
|
+
* a new directory is set.
|
|
30
|
+
*/
|
|
31
|
+
void FreeInstDir(void);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @brief Get the current installation directory path.
|
|
35
|
+
*
|
|
36
|
+
* @return
|
|
37
|
+
* A pointer to the installation directory path if set, or NULL if the
|
|
38
|
+
* directory has not been initialized or has been freed.
|
|
39
|
+
*/
|
|
40
|
+
const char *GetInstDir(void);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @brief Concatenates the installation directory path with a given
|
|
44
|
+
* relative path.
|
|
45
|
+
*
|
|
46
|
+
* This function guarantees that the resulting path will not escape the
|
|
47
|
+
* installation directory. It will fail and return NULL if any of the following
|
|
48
|
+
* conditions are met:
|
|
49
|
+
* - the installation directory (InstDir) is not set or is empty
|
|
50
|
+
* - rel_path is NULL or empty
|
|
51
|
+
* - rel_path contains prohibited path elements such as "." or "..", including
|
|
52
|
+
* patterns like "/./" or "/../"
|
|
53
|
+
*
|
|
54
|
+
* @param rel_path
|
|
55
|
+
* A relative path to be combined with the installation directory path.
|
|
56
|
+
* Must not be absolute, must not be empty, and must not contain any "." or
|
|
57
|
+
* ".." segments (e.g., "/./", "/../", "./", "../").
|
|
58
|
+
*
|
|
59
|
+
* @return
|
|
60
|
+
* A newly allocated string representing the full path on success; NULL on
|
|
61
|
+
* error (and an appropriate error message is logged).
|
|
62
|
+
*/
|
|
63
|
+
char *ExpandInstDirPath(const char *rel_path);
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @brief Deletes the installation directory and its contents.
|
|
67
|
+
*
|
|
68
|
+
* @return true if the directory and its contents were deleted successfully,
|
|
69
|
+
* false otherwise.
|
|
70
|
+
*/
|
|
71
|
+
bool DeleteInstDir(void);
|
|
72
|
+
|
|
73
|
+
// Placeholder character used in paths.
|
|
74
|
+
#define PLACEHOLDER '|'
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @brief Replace placeholders in a template string
|
|
78
|
+
* with the installation directory path.
|
|
79
|
+
*
|
|
80
|
+
* @param tmpl
|
|
81
|
+
* The template string containing placeholder characters defined by the
|
|
82
|
+
* PLACEHOLDER macro, which will be replaced by the installation directory
|
|
83
|
+
* path.
|
|
84
|
+
* @return
|
|
85
|
+
* A newly allocated string with all PLACEHOLDER occurrences replaced by the
|
|
86
|
+
* installation directory path. Returns NULL on failure.
|
|
87
|
+
*/
|
|
88
|
+
char *ReplaceInstDirPlaceholder(const char *tmpl);
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @brief Recursively create a directory under the installation directory.
|
|
92
|
+
*
|
|
93
|
+
* This function ensures that a directory exists at the specified relative
|
|
94
|
+
* path under the installation directory. An empty rel_path is treated as
|
|
95
|
+
* already existing (returns true). If rel_path is NULL, ExpandInstDirPath
|
|
96
|
+
* fails, or directory creation fails, the function returns false and logs
|
|
97
|
+
* an error.
|
|
98
|
+
*
|
|
99
|
+
* @param rel_path
|
|
100
|
+
* A relative path to a directory under the installation directory.
|
|
101
|
+
* NULL is invalid (returns false). An empty string is treated as
|
|
102
|
+
* already existing (returns true).
|
|
103
|
+
*
|
|
104
|
+
* @return
|
|
105
|
+
* true if the directory already exists or was created successfully;
|
|
106
|
+
* false on error (and an error is logged).
|
|
107
|
+
*/
|
|
108
|
+
bool CreateDirectoryUnderInstDir(const char *rel_path);
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @brief Atomically write a file under the installation dir.
|
|
112
|
+
*
|
|
113
|
+
* This function writes the given buffer as a file at the specified
|
|
114
|
+
* relative path under the installation directory. It validates rel_path
|
|
115
|
+
* and buf, expands the full path, creates any missing parent directories,
|
|
116
|
+
* and writes the data atomically. If len is zero, an empty file is
|
|
117
|
+
* created.
|
|
118
|
+
*
|
|
119
|
+
* @param rel_path
|
|
120
|
+
* A relative file path under the installation directory. NULL or empty
|
|
121
|
+
* string is invalid (returns false).
|
|
122
|
+
* @param buf
|
|
123
|
+
* Pointer to the data to write. Must be non-NULL if len > 0.
|
|
124
|
+
* @param len
|
|
125
|
+
* Number of bytes to write. Zero creates an empty file. Values above
|
|
126
|
+
* MAXDWORD cause an error.
|
|
127
|
+
*
|
|
128
|
+
* @return
|
|
129
|
+
* true on success; false on failure (error logged via APP_ERROR/DEBUG).
|
|
130
|
+
*/
|
|
131
|
+
bool ExportFileToInstDir(const char *rel_path, const void *buf, size_t len);
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @brief Expands any installation-directory placeholder found in 'value' and
|
|
135
|
+
* sets the environment variable.
|
|
136
|
+
*
|
|
137
|
+
* @param name Environment variable name to set (must not be NULL).
|
|
138
|
+
* @param value Value string that may include a placeholder for the
|
|
139
|
+
* installation directory.
|
|
140
|
+
*
|
|
141
|
+
* @return true on success; false on failure.
|
|
142
|
+
*/
|
|
143
|
+
bool SetEnvWithInstDir(const char *name, const char *value);
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @brief Create a symlink under the installation directory (POSIX only).
|
|
147
|
+
*
|
|
148
|
+
* Creates a symbolic link at rel_link_path that points to target.
|
|
149
|
+
* Both paths are relative to the installation directory.
|
|
150
|
+
* The target is treated as a bare filename within the same directory.
|
|
151
|
+
*
|
|
152
|
+
* @param rel_link_path Relative path for the new symlink (e.g. "bin/libruby.so").
|
|
153
|
+
* @param target Symlink target filename (e.g. "libruby.so.3.2.0").
|
|
154
|
+
*
|
|
155
|
+
* @return true on success; false on failure.
|
|
156
|
+
*/
|
|
157
|
+
bool CreateSymlinkUnderInstDir(const char *rel_link_path, const char *target);
|
data/src/lzma/7zTypes.h
ADDED
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
/* 7zTypes.h -- Basic types
|
|
2
|
+
2022-04-01 : Igor Pavlov : Public domain */
|
|
3
|
+
|
|
4
|
+
#ifndef __7Z_TYPES_H
|
|
5
|
+
#define __7Z_TYPES_H
|
|
6
|
+
|
|
7
|
+
#ifdef _WIN32
|
|
8
|
+
/* #include <windows.h> */
|
|
9
|
+
#else
|
|
10
|
+
#include <errno.h>
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
#include <stddef.h>
|
|
14
|
+
|
|
15
|
+
#ifndef EXTERN_C_BEGIN
|
|
16
|
+
#ifdef __cplusplus
|
|
17
|
+
#define EXTERN_C_BEGIN extern "C" {
|
|
18
|
+
#define EXTERN_C_END }
|
|
19
|
+
#else
|
|
20
|
+
#define EXTERN_C_BEGIN
|
|
21
|
+
#define EXTERN_C_END
|
|
22
|
+
#endif
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
EXTERN_C_BEGIN
|
|
26
|
+
|
|
27
|
+
#define SZ_OK 0
|
|
28
|
+
|
|
29
|
+
#define SZ_ERROR_DATA 1
|
|
30
|
+
#define SZ_ERROR_MEM 2
|
|
31
|
+
#define SZ_ERROR_CRC 3
|
|
32
|
+
#define SZ_ERROR_UNSUPPORTED 4
|
|
33
|
+
#define SZ_ERROR_PARAM 5
|
|
34
|
+
#define SZ_ERROR_INPUT_EOF 6
|
|
35
|
+
#define SZ_ERROR_OUTPUT_EOF 7
|
|
36
|
+
#define SZ_ERROR_READ 8
|
|
37
|
+
#define SZ_ERROR_WRITE 9
|
|
38
|
+
#define SZ_ERROR_PROGRESS 10
|
|
39
|
+
#define SZ_ERROR_FAIL 11
|
|
40
|
+
#define SZ_ERROR_THREAD 12
|
|
41
|
+
|
|
42
|
+
#define SZ_ERROR_ARCHIVE 16
|
|
43
|
+
#define SZ_ERROR_NO_ARCHIVE 17
|
|
44
|
+
|
|
45
|
+
typedef int SRes;
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
#ifdef _MSC_VER
|
|
49
|
+
#if _MSC_VER > 1200
|
|
50
|
+
#define MY_ALIGN(n) __declspec(align(n))
|
|
51
|
+
#else
|
|
52
|
+
#define MY_ALIGN(n)
|
|
53
|
+
#endif
|
|
54
|
+
#else
|
|
55
|
+
#define MY_ALIGN(n) __attribute__ ((aligned(n)))
|
|
56
|
+
#endif
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
#ifdef _WIN32
|
|
60
|
+
|
|
61
|
+
/* typedef DWORD WRes; */
|
|
62
|
+
typedef unsigned WRes;
|
|
63
|
+
#define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)
|
|
64
|
+
|
|
65
|
+
// #define MY_HRES_ERROR__INTERNAL_ERROR MY_SRes_HRESULT_FROM_WRes(ERROR_INTERNAL_ERROR)
|
|
66
|
+
|
|
67
|
+
#else // _WIN32
|
|
68
|
+
|
|
69
|
+
// #define ENV_HAVE_LSTAT
|
|
70
|
+
typedef int WRes;
|
|
71
|
+
|
|
72
|
+
// (FACILITY_ERRNO = 0x800) is 7zip's FACILITY constant to represent (errno) errors in HRESULT
|
|
73
|
+
#define MY__FACILITY_ERRNO 0x800
|
|
74
|
+
#define MY__FACILITY_WIN32 7
|
|
75
|
+
#define MY__FACILITY__WRes MY__FACILITY_ERRNO
|
|
76
|
+
|
|
77
|
+
#define MY_HRESULT_FROM_errno_CONST_ERROR(x) ((HRESULT)( \
|
|
78
|
+
( (HRESULT)(x) & 0x0000FFFF) \
|
|
79
|
+
| (MY__FACILITY__WRes << 16) \
|
|
80
|
+
| (HRESULT)0x80000000 ))
|
|
81
|
+
|
|
82
|
+
#define MY_SRes_HRESULT_FROM_WRes(x) \
|
|
83
|
+
((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : MY_HRESULT_FROM_errno_CONST_ERROR(x))
|
|
84
|
+
|
|
85
|
+
// we call macro HRESULT_FROM_WIN32 for system errors (WRes) that are (errno)
|
|
86
|
+
#define HRESULT_FROM_WIN32(x) MY_SRes_HRESULT_FROM_WRes(x)
|
|
87
|
+
|
|
88
|
+
/*
|
|
89
|
+
#define ERROR_FILE_NOT_FOUND 2L
|
|
90
|
+
#define ERROR_ACCESS_DENIED 5L
|
|
91
|
+
#define ERROR_NO_MORE_FILES 18L
|
|
92
|
+
#define ERROR_LOCK_VIOLATION 33L
|
|
93
|
+
#define ERROR_FILE_EXISTS 80L
|
|
94
|
+
#define ERROR_DISK_FULL 112L
|
|
95
|
+
#define ERROR_NEGATIVE_SEEK 131L
|
|
96
|
+
#define ERROR_ALREADY_EXISTS 183L
|
|
97
|
+
#define ERROR_DIRECTORY 267L
|
|
98
|
+
#define ERROR_TOO_MANY_POSTS 298L
|
|
99
|
+
|
|
100
|
+
#define ERROR_INTERNAL_ERROR 1359L
|
|
101
|
+
#define ERROR_INVALID_REPARSE_DATA 4392L
|
|
102
|
+
#define ERROR_REPARSE_TAG_INVALID 4393L
|
|
103
|
+
#define ERROR_REPARSE_TAG_MISMATCH 4394L
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
// we use errno equivalents for some WIN32 errors:
|
|
107
|
+
|
|
108
|
+
#define ERROR_INVALID_PARAMETER EINVAL
|
|
109
|
+
#define ERROR_INVALID_FUNCTION EINVAL
|
|
110
|
+
#define ERROR_ALREADY_EXISTS EEXIST
|
|
111
|
+
#define ERROR_FILE_EXISTS EEXIST
|
|
112
|
+
#define ERROR_PATH_NOT_FOUND ENOENT
|
|
113
|
+
#define ERROR_FILE_NOT_FOUND ENOENT
|
|
114
|
+
#define ERROR_DISK_FULL ENOSPC
|
|
115
|
+
// #define ERROR_INVALID_HANDLE EBADF
|
|
116
|
+
|
|
117
|
+
// we use FACILITY_WIN32 for errors that has no errno equivalent
|
|
118
|
+
// Too many posts were made to a semaphore.
|
|
119
|
+
#define ERROR_TOO_MANY_POSTS ((HRESULT)0x8007012AL)
|
|
120
|
+
#define ERROR_INVALID_REPARSE_DATA ((HRESULT)0x80071128L)
|
|
121
|
+
#define ERROR_REPARSE_TAG_INVALID ((HRESULT)0x80071129L)
|
|
122
|
+
|
|
123
|
+
// if (MY__FACILITY__WRes != FACILITY_WIN32),
|
|
124
|
+
// we use FACILITY_WIN32 for COM errors:
|
|
125
|
+
#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)
|
|
126
|
+
#define E_INVALIDARG ((HRESULT)0x80070057L)
|
|
127
|
+
#define MY__E_ERROR_NEGATIVE_SEEK ((HRESULT)0x80070083L)
|
|
128
|
+
|
|
129
|
+
/*
|
|
130
|
+
// we can use FACILITY_ERRNO for some COM errors, that have errno equivalents:
|
|
131
|
+
#define E_OUTOFMEMORY MY_HRESULT_FROM_errno_CONST_ERROR(ENOMEM)
|
|
132
|
+
#define E_INVALIDARG MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL)
|
|
133
|
+
#define MY__E_ERROR_NEGATIVE_SEEK MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL)
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
#define TEXT(quote) quote
|
|
137
|
+
|
|
138
|
+
#define FILE_ATTRIBUTE_READONLY 0x0001
|
|
139
|
+
#define FILE_ATTRIBUTE_HIDDEN 0x0002
|
|
140
|
+
#define FILE_ATTRIBUTE_SYSTEM 0x0004
|
|
141
|
+
#define FILE_ATTRIBUTE_DIRECTORY 0x0010
|
|
142
|
+
#define FILE_ATTRIBUTE_ARCHIVE 0x0020
|
|
143
|
+
#define FILE_ATTRIBUTE_DEVICE 0x0040
|
|
144
|
+
#define FILE_ATTRIBUTE_NORMAL 0x0080
|
|
145
|
+
#define FILE_ATTRIBUTE_TEMPORARY 0x0100
|
|
146
|
+
#define FILE_ATTRIBUTE_SPARSE_FILE 0x0200
|
|
147
|
+
#define FILE_ATTRIBUTE_REPARSE_POINT 0x0400
|
|
148
|
+
#define FILE_ATTRIBUTE_COMPRESSED 0x0800
|
|
149
|
+
#define FILE_ATTRIBUTE_OFFLINE 0x1000
|
|
150
|
+
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x2000
|
|
151
|
+
#define FILE_ATTRIBUTE_ENCRYPTED 0x4000
|
|
152
|
+
|
|
153
|
+
#define FILE_ATTRIBUTE_UNIX_EXTENSION 0x8000 /* trick for Unix */
|
|
154
|
+
|
|
155
|
+
#endif
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
#ifndef RINOK
|
|
159
|
+
#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
|
|
160
|
+
#endif
|
|
161
|
+
|
|
162
|
+
#ifndef RINOK_WRes
|
|
163
|
+
#define RINOK_WRes(x) { WRes __result__ = (x); if (__result__ != 0) return __result__; }
|
|
164
|
+
#endif
|
|
165
|
+
|
|
166
|
+
typedef unsigned char Byte;
|
|
167
|
+
typedef short Int16;
|
|
168
|
+
typedef unsigned short UInt16;
|
|
169
|
+
|
|
170
|
+
#ifdef _LZMA_UINT32_IS_ULONG
|
|
171
|
+
typedef long Int32;
|
|
172
|
+
typedef unsigned long UInt32;
|
|
173
|
+
#else
|
|
174
|
+
typedef int Int32;
|
|
175
|
+
typedef unsigned int UInt32;
|
|
176
|
+
#endif
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
#ifndef _WIN32
|
|
180
|
+
|
|
181
|
+
typedef int INT;
|
|
182
|
+
typedef Int32 INT32;
|
|
183
|
+
typedef unsigned int UINT;
|
|
184
|
+
typedef UInt32 UINT32;
|
|
185
|
+
typedef INT32 LONG; // LONG, ULONG and DWORD must be 32-bit for _WIN32 compatibility
|
|
186
|
+
typedef UINT32 ULONG;
|
|
187
|
+
|
|
188
|
+
#undef DWORD
|
|
189
|
+
typedef UINT32 DWORD;
|
|
190
|
+
|
|
191
|
+
#define VOID void
|
|
192
|
+
|
|
193
|
+
#define HRESULT LONG
|
|
194
|
+
|
|
195
|
+
typedef void *LPVOID;
|
|
196
|
+
// typedef void VOID;
|
|
197
|
+
// typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
|
|
198
|
+
// gcc / clang on Unix : sizeof(long==sizeof(void*) in 32 or 64 bits)
|
|
199
|
+
typedef long INT_PTR;
|
|
200
|
+
typedef unsigned long UINT_PTR;
|
|
201
|
+
typedef long LONG_PTR;
|
|
202
|
+
typedef unsigned long DWORD_PTR;
|
|
203
|
+
|
|
204
|
+
typedef size_t SIZE_T;
|
|
205
|
+
|
|
206
|
+
#endif // _WIN32
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
#define MY_HRES_ERROR__INTERNAL_ERROR ((HRESULT)0x8007054FL)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
#ifdef _SZ_NO_INT_64
|
|
213
|
+
|
|
214
|
+
/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
|
|
215
|
+
NOTES: Some code will work incorrectly in that case! */
|
|
216
|
+
|
|
217
|
+
typedef long Int64;
|
|
218
|
+
typedef unsigned long UInt64;
|
|
219
|
+
|
|
220
|
+
#else
|
|
221
|
+
|
|
222
|
+
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
|
223
|
+
typedef __int64 Int64;
|
|
224
|
+
typedef unsigned __int64 UInt64;
|
|
225
|
+
#define UINT64_CONST(n) n
|
|
226
|
+
#else
|
|
227
|
+
typedef long long int Int64;
|
|
228
|
+
typedef unsigned long long int UInt64;
|
|
229
|
+
#define UINT64_CONST(n) n ## ULL
|
|
230
|
+
#endif
|
|
231
|
+
|
|
232
|
+
#endif
|
|
233
|
+
|
|
234
|
+
#ifdef _LZMA_NO_SYSTEM_SIZE_T
|
|
235
|
+
typedef UInt32 SizeT;
|
|
236
|
+
#else
|
|
237
|
+
typedef size_t SizeT;
|
|
238
|
+
#endif
|
|
239
|
+
|
|
240
|
+
typedef int BoolInt;
|
|
241
|
+
/* typedef BoolInt Bool; */
|
|
242
|
+
#define True 1
|
|
243
|
+
#define False 0
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
#ifdef _WIN32
|
|
247
|
+
#define MY_STD_CALL __stdcall
|
|
248
|
+
#else
|
|
249
|
+
#define MY_STD_CALL
|
|
250
|
+
#endif
|
|
251
|
+
|
|
252
|
+
#ifdef _MSC_VER
|
|
253
|
+
|
|
254
|
+
#if _MSC_VER >= 1300
|
|
255
|
+
#define MY_NO_INLINE __declspec(noinline)
|
|
256
|
+
#else
|
|
257
|
+
#define MY_NO_INLINE
|
|
258
|
+
#endif
|
|
259
|
+
|
|
260
|
+
#define MY_FORCE_INLINE __forceinline
|
|
261
|
+
|
|
262
|
+
#define MY_CDECL __cdecl
|
|
263
|
+
#define MY_FAST_CALL __fastcall
|
|
264
|
+
|
|
265
|
+
#else // _MSC_VER
|
|
266
|
+
|
|
267
|
+
#if (defined(__GNUC__) && (__GNUC__ >= 4)) \
|
|
268
|
+
|| (defined(__clang__) && (__clang_major__ >= 4)) \
|
|
269
|
+
|| defined(__INTEL_COMPILER) \
|
|
270
|
+
|| defined(__xlC__)
|
|
271
|
+
#define MY_NO_INLINE __attribute__((noinline))
|
|
272
|
+
// #define MY_FORCE_INLINE __attribute__((always_inline)) inline
|
|
273
|
+
#else
|
|
274
|
+
#define MY_NO_INLINE
|
|
275
|
+
#endif
|
|
276
|
+
|
|
277
|
+
#define MY_FORCE_INLINE
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
#define MY_CDECL
|
|
281
|
+
|
|
282
|
+
#if defined(_M_IX86) \
|
|
283
|
+
|| defined(__i386__)
|
|
284
|
+
// #define MY_FAST_CALL __attribute__((fastcall))
|
|
285
|
+
// #define MY_FAST_CALL __attribute__((cdecl))
|
|
286
|
+
#define MY_FAST_CALL
|
|
287
|
+
#elif defined(MY_CPU_AMD64)
|
|
288
|
+
// #define MY_FAST_CALL __attribute__((ms_abi))
|
|
289
|
+
#define MY_FAST_CALL
|
|
290
|
+
#else
|
|
291
|
+
#define MY_FAST_CALL
|
|
292
|
+
#endif
|
|
293
|
+
|
|
294
|
+
#endif // _MSC_VER
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
/* The following interfaces use first parameter as pointer to structure */
|
|
298
|
+
|
|
299
|
+
typedef struct IByteIn IByteIn;
|
|
300
|
+
struct IByteIn
|
|
301
|
+
{
|
|
302
|
+
Byte (*Read)(const IByteIn *p); /* reads one byte, returns 0 in case of EOF or error */
|
|
303
|
+
};
|
|
304
|
+
#define IByteIn_Read(p) (p)->Read(p)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
typedef struct IByteOut IByteOut;
|
|
308
|
+
struct IByteOut
|
|
309
|
+
{
|
|
310
|
+
void (*Write)(const IByteOut *p, Byte b);
|
|
311
|
+
};
|
|
312
|
+
#define IByteOut_Write(p, b) (p)->Write(p, b)
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
typedef struct ISeqInStream ISeqInStream;
|
|
316
|
+
struct ISeqInStream
|
|
317
|
+
{
|
|
318
|
+
SRes (*Read)(const ISeqInStream *p, void *buf, size_t *size);
|
|
319
|
+
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
|
|
320
|
+
(output(*size) < input(*size)) is allowed */
|
|
321
|
+
};
|
|
322
|
+
#define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)
|
|
323
|
+
|
|
324
|
+
/* it can return SZ_ERROR_INPUT_EOF */
|
|
325
|
+
SRes SeqInStream_Read(const ISeqInStream *stream, void *buf, size_t size);
|
|
326
|
+
SRes SeqInStream_Read2(const ISeqInStream *stream, void *buf, size_t size, SRes errorType);
|
|
327
|
+
SRes SeqInStream_ReadByte(const ISeqInStream *stream, Byte *buf);
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
typedef struct ISeqOutStream ISeqOutStream;
|
|
331
|
+
struct ISeqOutStream
|
|
332
|
+
{
|
|
333
|
+
size_t (*Write)(const ISeqOutStream *p, const void *buf, size_t size);
|
|
334
|
+
/* Returns: result - the number of actually written bytes.
|
|
335
|
+
(result < size) means error */
|
|
336
|
+
};
|
|
337
|
+
#define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)
|
|
338
|
+
|
|
339
|
+
typedef enum
|
|
340
|
+
{
|
|
341
|
+
SZ_SEEK_SET = 0,
|
|
342
|
+
SZ_SEEK_CUR = 1,
|
|
343
|
+
SZ_SEEK_END = 2
|
|
344
|
+
} ESzSeek;
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
typedef struct ISeekInStream ISeekInStream;
|
|
348
|
+
struct ISeekInStream
|
|
349
|
+
{
|
|
350
|
+
SRes (*Read)(const ISeekInStream *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
|
|
351
|
+
SRes (*Seek)(const ISeekInStream *p, Int64 *pos, ESzSeek origin);
|
|
352
|
+
};
|
|
353
|
+
#define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size)
|
|
354
|
+
#define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
typedef struct ILookInStream ILookInStream;
|
|
358
|
+
struct ILookInStream
|
|
359
|
+
{
|
|
360
|
+
SRes (*Look)(const ILookInStream *p, const void **buf, size_t *size);
|
|
361
|
+
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
|
|
362
|
+
(output(*size) > input(*size)) is not allowed
|
|
363
|
+
(output(*size) < input(*size)) is allowed */
|
|
364
|
+
SRes (*Skip)(const ILookInStream *p, size_t offset);
|
|
365
|
+
/* offset must be <= output(*size) of Look */
|
|
366
|
+
|
|
367
|
+
SRes (*Read)(const ILookInStream *p, void *buf, size_t *size);
|
|
368
|
+
/* reads directly (without buffer). It's same as ISeqInStream::Read */
|
|
369
|
+
SRes (*Seek)(const ILookInStream *p, Int64 *pos, ESzSeek origin);
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
#define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size)
|
|
373
|
+
#define ILookInStream_Skip(p, offset) (p)->Skip(p, offset)
|
|
374
|
+
#define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size)
|
|
375
|
+
#define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
SRes LookInStream_LookRead(const ILookInStream *stream, void *buf, size_t *size);
|
|
379
|
+
SRes LookInStream_SeekTo(const ILookInStream *stream, UInt64 offset);
|
|
380
|
+
|
|
381
|
+
/* reads via ILookInStream::Read */
|
|
382
|
+
SRes LookInStream_Read2(const ILookInStream *stream, void *buf, size_t size, SRes errorType);
|
|
383
|
+
SRes LookInStream_Read(const ILookInStream *stream, void *buf, size_t size);
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
typedef struct
|
|
388
|
+
{
|
|
389
|
+
ILookInStream vt;
|
|
390
|
+
const ISeekInStream *realStream;
|
|
391
|
+
|
|
392
|
+
size_t pos;
|
|
393
|
+
size_t size; /* it's data size */
|
|
394
|
+
|
|
395
|
+
/* the following variables must be set outside */
|
|
396
|
+
Byte *buf;
|
|
397
|
+
size_t bufSize;
|
|
398
|
+
} CLookToRead2;
|
|
399
|
+
|
|
400
|
+
void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead);
|
|
401
|
+
|
|
402
|
+
#define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
typedef struct
|
|
406
|
+
{
|
|
407
|
+
ISeqInStream vt;
|
|
408
|
+
const ILookInStream *realStream;
|
|
409
|
+
} CSecToLook;
|
|
410
|
+
|
|
411
|
+
void SecToLook_CreateVTable(CSecToLook *p);
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
typedef struct
|
|
416
|
+
{
|
|
417
|
+
ISeqInStream vt;
|
|
418
|
+
const ILookInStream *realStream;
|
|
419
|
+
} CSecToRead;
|
|
420
|
+
|
|
421
|
+
void SecToRead_CreateVTable(CSecToRead *p);
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
typedef struct ICompressProgress ICompressProgress;
|
|
425
|
+
|
|
426
|
+
struct ICompressProgress
|
|
427
|
+
{
|
|
428
|
+
SRes (*Progress)(const ICompressProgress *p, UInt64 inSize, UInt64 outSize);
|
|
429
|
+
/* Returns: result. (result != SZ_OK) means break.
|
|
430
|
+
Value (UInt64)(Int64)-1 for size means unknown value. */
|
|
431
|
+
};
|
|
432
|
+
#define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
typedef struct ISzAlloc ISzAlloc;
|
|
437
|
+
typedef const ISzAlloc * ISzAllocPtr;
|
|
438
|
+
|
|
439
|
+
struct ISzAlloc
|
|
440
|
+
{
|
|
441
|
+
void *(*Alloc)(ISzAllocPtr p, size_t size);
|
|
442
|
+
void (*Free)(ISzAllocPtr p, void *address); /* address can be 0 */
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
#define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)
|
|
446
|
+
#define ISzAlloc_Free(p, a) (p)->Free(p, a)
|
|
447
|
+
|
|
448
|
+
/* deprecated */
|
|
449
|
+
#define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)
|
|
450
|
+
#define IAlloc_Free(p, a) ISzAlloc_Free(p, a)
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
#ifndef MY_offsetof
|
|
457
|
+
#ifdef offsetof
|
|
458
|
+
#define MY_offsetof(type, m) offsetof(type, m)
|
|
459
|
+
/*
|
|
460
|
+
#define MY_offsetof(type, m) FIELD_OFFSET(type, m)
|
|
461
|
+
*/
|
|
462
|
+
#else
|
|
463
|
+
#define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))
|
|
464
|
+
#endif
|
|
465
|
+
#endif
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
#ifndef MY_container_of
|
|
470
|
+
|
|
471
|
+
/*
|
|
472
|
+
#define MY_container_of(ptr, type, m) container_of(ptr, type, m)
|
|
473
|
+
#define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
|
|
474
|
+
#define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
|
|
475
|
+
#define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
|
|
476
|
+
*/
|
|
477
|
+
|
|
478
|
+
/*
|
|
479
|
+
GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"
|
|
480
|
+
GCC 3.4.4 : classes with constructor
|
|
481
|
+
GCC 4.8.1 : classes with non-public variable members"
|
|
482
|
+
*/
|
|
483
|
+
|
|
484
|
+
#define MY_container_of(ptr, type, m) ((type *)(void *)((char *)(void *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))
|
|
485
|
+
|
|
486
|
+
#endif
|
|
487
|
+
|
|
488
|
+
#define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(void *)(ptr))
|
|
489
|
+
|
|
490
|
+
/*
|
|
491
|
+
#define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
|
|
492
|
+
*/
|
|
493
|
+
#define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)
|
|
494
|
+
|
|
495
|
+
#define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
|
|
496
|
+
/*
|
|
497
|
+
#define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m)
|
|
498
|
+
*/
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
#define MY_memset_0_ARRAY(a) memset((a), 0, sizeof(a))
|
|
502
|
+
|
|
503
|
+
#ifdef _WIN32
|
|
504
|
+
|
|
505
|
+
#define CHAR_PATH_SEPARATOR '\\'
|
|
506
|
+
#define WCHAR_PATH_SEPARATOR L'\\'
|
|
507
|
+
#define STRING_PATH_SEPARATOR "\\"
|
|
508
|
+
#define WSTRING_PATH_SEPARATOR L"\\"
|
|
509
|
+
|
|
510
|
+
#else
|
|
511
|
+
|
|
512
|
+
#define CHAR_PATH_SEPARATOR '/'
|
|
513
|
+
#define WCHAR_PATH_SEPARATOR L'/'
|
|
514
|
+
#define STRING_PATH_SEPARATOR "/"
|
|
515
|
+
#define WSTRING_PATH_SEPARATOR L"/"
|
|
516
|
+
|
|
517
|
+
#endif
|
|
518
|
+
|
|
519
|
+
#define k_PropVar_TimePrec_0 0
|
|
520
|
+
#define k_PropVar_TimePrec_Unix 1
|
|
521
|
+
#define k_PropVar_TimePrec_DOS 2
|
|
522
|
+
#define k_PropVar_TimePrec_HighPrec 3
|
|
523
|
+
#define k_PropVar_TimePrec_Base 16
|
|
524
|
+
#define k_PropVar_TimePrec_100ns (k_PropVar_TimePrec_Base + 7)
|
|
525
|
+
#define k_PropVar_TimePrec_1ns (k_PropVar_TimePrec_Base + 9)
|
|
526
|
+
|
|
527
|
+
EXTERN_C_END
|
|
528
|
+
|
|
529
|
+
#endif
|