diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2013-03-11 18:46:03 +0100 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2013-11-04 22:14:17 +0100 |
commit | 739a7ae0e9acb27227f5473a003833ea5a9c97ef (patch) | |
tree | 81f6dfd81b4343745b21a6c00c286791827175e4 /rbutil/rbutilqt/mspack/system.h | |
parent | 27111d83be815602ac35354e6a8e4e158c5968f9 (diff) | |
download | rockbox-739a7ae0e9acb27227f5473a003833ea5a9c97ef.tar.gz rockbox-739a7ae0e9acb27227f5473a003833ea5a9c97ef.zip |
Add libmspack to rbutil
Change-Id: I520c14131ec1e12013f106c13cba00aac058ad83
Reviewed-on: http://gerrit.rockbox.org/391
Reviewed-by: Dominik Riebeling <Dominik.Riebeling@gmail.com>
Diffstat (limited to 'rbutil/rbutilqt/mspack/system.h')
-rw-r--r-- | rbutil/rbutilqt/mspack/system.h | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/mspack/system.h b/rbutil/rbutilqt/mspack/system.h new file mode 100644 index 0000000000..4a400850aa --- /dev/null +++ b/rbutil/rbutilqt/mspack/system.h | |||
@@ -0,0 +1,124 @@ | |||
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 | ||
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 | static inline int mspack_memcmp(const void *s1, const void *s2, size_t n) { | ||
112 | unsigned char *c1 = (unsigned char *) s1; | ||
113 | unsigned char *c2 = (unsigned char *) s2; | ||
114 | if (n == 0) return 0; | ||
115 | while (--n && (*c1 == *c2)) c1++, c2++; | ||
116 | return *c1 - *c2; | ||
117 | } | ||
118 | #endif | ||
119 | |||
120 | #ifdef __cplusplus | ||
121 | } | ||
122 | #endif | ||
123 | |||
124 | #endif | ||