diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2021-12-15 21:04:28 +0100 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2021-12-24 18:05:53 +0100 |
commit | c876d3bbefe0dc00c27ca0c12d29da5874946962 (patch) | |
tree | 69f468a185a369b01998314bc3ecc19b70f4fcaa /utils/rbutilqt/mspack/system-mspack.h | |
parent | 6c6f0757d7a902feb293be165d1490c42bc8e7ad (diff) | |
download | rockbox-c876d3bbefe0dc00c27ca0c12d29da5874946962.tar.gz rockbox-c876d3bbefe0dc00c27ca0c12d29da5874946962.zip |
rbutil: Merge rbutil with utils folder.
rbutil uses several components from the utils folder, and can be
considered part of utils too. Having it in a separate folder is an
arbitrary split that doesn't help anymore these days, so merge them.
This also allows other utils to easily use libtools.make without the
need to navigate to a different folder.
Change-Id: I3fc2f4de19e3e776553efb5dea5f779dfec0dc21
Diffstat (limited to 'utils/rbutilqt/mspack/system-mspack.h')
-rw-r--r-- | utils/rbutilqt/mspack/system-mspack.h | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/utils/rbutilqt/mspack/system-mspack.h b/utils/rbutilqt/mspack/system-mspack.h new file mode 100644 index 0000000000..a0e6cf3ca8 --- /dev/null +++ b/utils/rbutilqt/mspack/system-mspack.h | |||
@@ -0,0 +1,129 @@ | |||
1 | /* This file is part of libmspack. | ||
2 | * (C) 2003-2004 Stuart Caie. | ||
3 | * | ||
4 | * libmspack is free software; you can redistribute it and/or modify it under | ||
5 | * the terms of the GNU Lesser General Public License (LGPL) version 2.1 | ||
6 | * | ||
7 | * For further details, see the file COPYING.LIB distributed with libmspack | ||
8 | */ | ||
9 | |||
10 | #ifndef MSPACK_SYSTEM_H | ||
11 | #define MSPACK_SYSTEM_H 1 | ||
12 | |||
13 | #ifdef __cplusplus | ||
14 | extern "C" { | ||
15 | #endif | ||
16 | |||
17 | /* ensure config.h is read before mspack.h */ | ||
18 | #ifdef HAVE_CONFIG_H | ||
19 | # include "config.h" | ||
20 | #endif | ||
21 | |||
22 | #include "mspack.h" | ||
23 | |||
24 | /* fix for problem with GCC 4 and glibc (thanks to Ville Skytta) | ||
25 | * http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=150429 | ||
26 | */ | ||
27 | #ifdef read | ||
28 | # undef read | ||
29 | #endif | ||
30 | |||
31 | #ifdef DEBUG | ||
32 | # include <stdio.h> | ||
33 | /* Old GCCs don't have __func__, but __FUNCTION__: | ||
34 | * http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html | ||
35 | */ | ||
36 | # if __STDC_VERSION__ < 199901L | ||
37 | # if __GNUC__ >= 2 | ||
38 | # define __func__ __FUNCTION__ | ||
39 | # else | ||
40 | # define __func__ "<unknown>" | ||
41 | # endif | ||
42 | # endif | ||
43 | # define D(x) do { printf("%s:%d (%s) ",__FILE__, __LINE__, __func__); \ | ||
44 | printf x ; fputc('\n', stdout); fflush(stdout);} while (0); | ||
45 | #else | ||
46 | # define D(x) | ||
47 | #endif | ||
48 | |||
49 | /* CAB supports searching through files over 4GB in size, and the CHM file | ||
50 | * format actively uses 64-bit offsets. These can only be fully supported | ||
51 | * if the system the code runs on supports large files. If not, the library | ||
52 | * will work as normal using only 32-bit arithmetic, but if an offset | ||
53 | * greater than 2GB is detected, an error message indicating the library | ||
54 | * can't support the file should be printed. | ||
55 | */ | ||
56 | #ifdef HAVE_LIMITS_H | ||
57 | # include <limits.h> | ||
58 | #endif | ||
59 | |||
60 | #if ((defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS >= 64) || \ | ||
61 | (defined(FILESIZEBITS) && FILESIZEBITS >= 64) || \ | ||
62 | (defined(SIZEOF_OFF_T) && SIZEOF_OFF_T >= 8) || \ | ||
63 | defined(_LARGEFILE_SOURCE) || defined(_LARGEFILE64_SOURCE)) | ||
64 | # define LARGEFILE_SUPPORT 1 | ||
65 | # define LD "lld" | ||
66 | # define LU "llu" | ||
67 | #else | ||
68 | extern const char *largefile_msg; | ||
69 | # define LD "ld" | ||
70 | # define LU "lu" | ||
71 | #endif | ||
72 | |||
73 | /* endian-neutral reading of little-endian data */ | ||
74 | #define __egi32(a,n) ( ((((unsigned char *) a)[n+3]) << 24) | \ | ||
75 | ((((unsigned char *) a)[n+2]) << 16) | \ | ||
76 | ((((unsigned char *) a)[n+1]) << 8) | \ | ||
77 | ((((unsigned char *) a)[n+0]))) | ||
78 | #define EndGetI64(a) ((((unsigned long long int) __egi32(a,4)) << 32) | \ | ||
79 | ((unsigned int) __egi32(a,0))) | ||
80 | #define EndGetI32(a) __egi32(a,0) | ||
81 | #define EndGetI16(a) ((((a)[1])<<8)|((a)[0])) | ||
82 | |||
83 | /* endian-neutral reading of big-endian data */ | ||
84 | #define EndGetM32(a) (((((unsigned char *) a)[0]) << 24) | \ | ||
85 | ((((unsigned char *) a)[1]) << 16) | \ | ||
86 | ((((unsigned char *) a)[2]) << 8) | \ | ||
87 | ((((unsigned char *) a)[3]))) | ||
88 | #define EndGetM16(a) ((((a)[0])<<8)|((a)[1])) | ||
89 | |||
90 | extern struct mspack_system *mspack_default_system; | ||
91 | |||
92 | /* returns the length of a file opened for reading */ | ||
93 | extern int mspack_sys_filelen(struct mspack_system *system, | ||
94 | struct mspack_file *file, off_t *length); | ||
95 | |||
96 | /* validates a system structure */ | ||
97 | extern int mspack_valid_system(struct mspack_system *sys); | ||
98 | |||
99 | #if HAVE_STRINGS_H | ||
100 | # include <strings.h> | ||
101 | #endif | ||
102 | |||
103 | #if HAVE_STRING_H | ||
104 | # include <string.h> | ||
105 | #endif | ||
106 | |||
107 | #if HAVE_MEMCMP | ||
108 | # define mspack_memcmp memcmp | ||
109 | #else | ||
110 | /* inline memcmp() */ | ||
111 | #ifdef _MSC_VER /* MSVC requires use of __inline instead of inline */ | ||
112 | #define INLINE __inline | ||
113 | #else | ||
114 | #define INLINE inline | ||
115 | #endif | ||
116 | static INLINE int mspack_memcmp(const void *s1, const void *s2, size_t n) { | ||
117 | unsigned char *c1 = (unsigned char *) s1; | ||
118 | unsigned char *c2 = (unsigned char *) s2; | ||
119 | if (n == 0) return 0; | ||
120 | while (--n && (*c1 == *c2)) c1++, c2++; | ||
121 | return *c1 - *c2; | ||
122 | } | ||
123 | #endif | ||
124 | |||
125 | #ifdef __cplusplus | ||
126 | } | ||
127 | #endif | ||
128 | |||
129 | #endif | ||