Mercurial > embed
comparison libzip/lib/compat.h @ 20:3b18afe43c9d
libzip: reimport version 1.1.3
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 29 Jun 2016 09:24:55 +0200 |
parents | |
children | 056ee6b5913e |
comparison
equal
deleted
inserted
replaced
19:07f2cdc6e430 | 20:3b18afe43c9d |
---|---|
1 #ifndef _HAD_LIBZIP_COMPAT_H | |
2 #define _HAD_LIBZIP_COMPAT_H | |
3 | |
4 /* | |
5 compat.h -- compatibility defines. | |
6 Copyright (C) 1999-2016 Dieter Baron and Thomas Klausner | |
7 | |
8 This file is part of libzip, a library to manipulate ZIP archives. | |
9 The authors can be contacted at <libzip@nih.at> | |
10 | |
11 Redistribution and use in source and binary forms, with or without | |
12 modification, are permitted provided that the following conditions | |
13 are met: | |
14 1. Redistributions of source code must retain the above copyright | |
15 notice, this list of conditions and the following disclaimer. | |
16 2. Redistributions in binary form must reproduce the above copyright | |
17 notice, this list of conditions and the following disclaimer in | |
18 the documentation and/or other materials provided with the | |
19 distribution. | |
20 3. The names of the authors may not be used to endorse or promote | |
21 products derived from this software without specific prior | |
22 written permission. | |
23 | |
24 THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS | |
25 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY | |
28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | |
30 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | |
32 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
33 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | |
34 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
35 */ | |
36 | |
37 #ifdef HAVE_CONFIG_H | |
38 #include "config.h" | |
39 #endif | |
40 | |
41 /* to have *_MAX definitions for all types when compiling with g++ */ | |
42 #define __STDC_LIMIT_MACROS | |
43 | |
44 #ifdef _WIN32 | |
45 #define ZIP_EXTERN __declspec(dllexport) | |
46 /* for dup(), close(), etc. */ | |
47 #include <io.h> | |
48 #endif | |
49 | |
50 #ifdef HAVE_STDBOOL_H | |
51 #include <stdbool.h> | |
52 #else | |
53 typedef char bool; | |
54 #define true 1 | |
55 #define false 0 | |
56 #endif | |
57 | |
58 #include <errno.h> | |
59 | |
60 /* at least MinGW does not provide EOPNOTSUPP, see | |
61 * http://sourceforge.net/p/mingw/bugs/263/ | |
62 */ | |
63 #ifndef EOPNOTSUPP | |
64 #define EOPNOTSUPP EINVAL | |
65 #endif | |
66 | |
67 /* at least MinGW does not provide EOVERFLOW, see | |
68 * http://sourceforge.net/p/mingw/bugs/242/ | |
69 */ | |
70 #ifndef EOVERFLOW | |
71 #define EOVERFLOW EFBIG | |
72 #endif | |
73 | |
74 #ifdef _WIN32 | |
75 #if defined(HAVE__CLOSE) | |
76 #define close _close | |
77 #endif | |
78 #if defined(HAVE__DUP) | |
79 #define dup _dup | |
80 #endif | |
81 /* crashes reported when using fdopen instead of _fdopen on Windows/Visual Studio 10/Win64 */ | |
82 #if defined(HAVE__FDOPEN) | |
83 #define fdopen _fdopen | |
84 #endif | |
85 #if !defined(HAVE_FILENO) && defined(HAVE__FILENO) | |
86 #define fileno _fileno | |
87 #endif | |
88 /* Windows' open() doesn't understand Unix permissions */ | |
89 #if defined(HAVE__OPEN) | |
90 #define open(a, b, c) _open((a), (b)) | |
91 #endif | |
92 #if defined(HAVE__SNPRINTF) | |
93 #define snprintf _snprintf | |
94 #endif | |
95 #if defined(HAVE__STRDUP) | |
96 #if !defined(HAVE_STRDUP) || defined(_WIN32) | |
97 #undef strdup | |
98 #define strdup _strdup | |
99 #endif | |
100 #endif | |
101 #if !defined(HAVE__SETMODE) && defined(HAVE_SETMODE) | |
102 #define _setmode setmode | |
103 #endif | |
104 #endif | |
105 | |
106 #ifndef HAVE_FSEEKO | |
107 #define fseeko(s, o, w) (fseek((s), (long int)(o), (w))) | |
108 #endif | |
109 | |
110 #ifndef HAVE_FTELLO | |
111 #define ftello(s) ((long)ftell((s))) | |
112 #endif | |
113 | |
114 #ifndef HAVE_MKSTEMP | |
115 int _zip_mkstemp(char *); | |
116 #define mkstemp _zip_mkstemp | |
117 #endif | |
118 | |
119 #if !defined(HAVE_STRCASECMP) | |
120 #if defined(HAVE__STRICMP) | |
121 #define strcasecmp _stricmp | |
122 #elif defined(HAVE_STRICMP) | |
123 #define strcasecmp stricmp | |
124 #endif | |
125 #endif | |
126 | |
127 #if SIZEOF_OFF_T == 8 | |
128 #define ZIP_OFF_MAX ZIP_INT64_MAX | |
129 #define ZIP_OFF_MIN ZIP_INT64_MIN | |
130 #elif SIZEOF_OFF_T == 4 | |
131 #define ZIP_OFF_MAX ZIP_INT32_MAX | |
132 #define ZIP_OFF_MIN ZIP_INT32_MIN | |
133 #elif SIZEOF_OFF_T == 2 | |
134 #define ZIP_OFF_MAX ZIP_INT16_MAX | |
135 #define ZIP_OFF_MIN ZIP_INT16_MIN | |
136 #else | |
137 #error unsupported size of off_t | |
138 #endif | |
139 | |
140 #if defined(HAVE_FTELLO) && defined(HAVE_FSEEKO) | |
141 #define ZIP_FSEEK_MAX ZIP_OFF_MAX | |
142 #define ZIP_FSEEK_MIN ZIP_OFF_MIN | |
143 #else | |
144 #include <limits.h> | |
145 #define ZIP_FSEEK_MAX LONG_MAX | |
146 #define ZIP_FSEEK_MIN LONG_MIN | |
147 #endif | |
148 | |
149 #ifndef SIZE_MAX | |
150 #if SIZEOF_SIZE_T == 8 | |
151 #define SIZE_MAX ZIP_INT64_MAX | |
152 #elif SIZEOF_SIZE_T == 4 | |
153 #define SIZE_MAX ZIP_INT32_MAX | |
154 #elif SIZEOF_SIZE_T == 2 | |
155 #define SIZE_MAX ZIP_INT16_MAX | |
156 #else | |
157 #error unsupported size of size_t | |
158 #endif | |
159 #endif | |
160 | |
161 #ifndef PRId64 | |
162 #ifdef _MSC_VER | |
163 #define PRId64 "I64d" | |
164 #else | |
165 #define PRId64 "lld" | |
166 #endif | |
167 #endif | |
168 | |
169 #ifndef PRIu64 | |
170 #ifdef _MSC_VER | |
171 #define PRIu64 "I64u" | |
172 #else | |
173 #define PRIu64 "llu" | |
174 #endif | |
175 #endif | |
176 | |
177 #ifndef S_ISDIR | |
178 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) | |
179 #endif | |
180 | |
181 #endif /* compat.h */ |