summaryrefslogtreecommitdiff
path: root/utils/rbutilqt/mspack/system-mspack.h
diff options
context:
space:
mode:
Diffstat (limited to 'utils/rbutilqt/mspack/system-mspack.h')
-rw-r--r--utils/rbutilqt/mspack/system-mspack.h129
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
14extern "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
68extern 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
90extern struct mspack_system *mspack_default_system;
91
92/* returns the length of a file opened for reading */
93extern int mspack_sys_filelen(struct mspack_system *system,
94 struct mspack_file *file, off_t *length);
95
96/* validates a system structure */
97extern 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
116static 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