Rizin
unix-like reverse engineering framework and cli tools
compat.h
Go to the documentation of this file.
1 #ifndef _HAD_LIBZIP_COMPAT_H
2 #define _HAD_LIBZIP_COMPAT_H
3 
4 /*
5  compat.h -- compatibility defines.
6  Copyright (C) 1999-2021 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 <info@libzip.org>
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 #include "zipconf.h"
38 
39 #include "config.h"
40 
41 /* to have *_MAX definitions for all types when compiling with g++ */
42 #define __STDC_LIMIT_MACROS
43 
44 #ifdef _WIN32
45 #ifndef ZIP_EXTERN
46 #ifndef ZIP_STATIC
47 #define ZIP_EXTERN __declspec(dllexport)
48 #endif
49 #endif
50 /* for dup(), close(), etc. */
51 #include <io.h>
52 #endif
53 
54 #ifdef HAVE_STDBOOL_H
55 #include <stdbool.h>
56 #else
57 typedef char bool;
58 #define true 1
59 #define false 0
60 #endif
61 
62 #include <errno.h>
63 
64 /* at least MinGW does not provide EOPNOTSUPP, see
65  * http://sourceforge.net/p/mingw/bugs/263/
66  */
67 #ifndef EOPNOTSUPP
68 #define EOPNOTSUPP EINVAL
69 #endif
70 
71 /* at least MinGW does not provide EOVERFLOW, see
72  * http://sourceforge.net/p/mingw/bugs/242/
73  */
74 #ifndef EOVERFLOW
75 #define EOVERFLOW EFBIG
76 #endif
77 
78 /* not supported on at least Windows */
79 #ifndef O_CLOEXEC
80 #define O_CLOEXEC 0
81 #endif
82 
83 #ifdef _WIN32
84 #if defined(HAVE__CLOSE)
85 #define close _close
86 #endif
87 #if defined(HAVE__DUP)
88 #define dup _dup
89 #endif
90 /* crashes reported when using fdopen instead of _fdopen on Windows/Visual Studio 10/Win64 */
91 #if defined(HAVE__FDOPEN)
92 #define fdopen _fdopen
93 #endif
94 #if !defined(HAVE_FILENO) && defined(HAVE__FILENO)
95 #define fileno _fileno
96 #endif
97 #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
98 #define snprintf _snprintf
99 #endif
100 #if defined(HAVE__STRDUP)
101 #if !defined(HAVE_STRDUP) || defined(_WIN32)
102 #undef strdup
103 #define strdup _strdup
104 #endif
105 #endif
106 #if !defined(HAVE__SETMODE) && defined(HAVE_SETMODE)
107 #define _setmode setmode
108 #endif
109 #if !defined(HAVE_STRTOLL) && defined(HAVE__STRTOI64)
110 #define strtoll _strtoi64
111 #endif
112 #if !defined(HAVE_STRTOULL) && defined(HAVE__STRTOUI64)
113 #define strtoull _strtoui64
114 #endif
115 #if defined(HAVE__UNLINK)
116 #define unlink _unlink
117 #endif
118 #endif
119 
120 #ifndef HAVE_FSEEKO
121 #define fseeko(s, o, w) (fseek((s), (long int)(o), (w)))
122 #endif
123 
124 #ifndef HAVE_FTELLO
125 #define ftello(s) ((long)ftell((s)))
126 #endif
127 
128 #if !defined(HAVE_STRCASECMP)
129 #if defined(HAVE__STRICMP)
130 #define strcasecmp _stricmp
131 #elif defined(HAVE_STRICMP)
132 #define strcasecmp stricmp
133 #endif
134 #endif
135 
136 #if SIZEOF_OFF_T == 8
137 #define ZIP_OFF_MAX ZIP_INT64_MAX
138 #define ZIP_OFF_MIN ZIP_INT64_MIN
139 #elif SIZEOF_OFF_T == 4
140 #define ZIP_OFF_MAX ZIP_INT32_MAX
141 #define ZIP_OFF_MIN ZIP_INT32_MIN
142 #elif SIZEOF_OFF_T == 2
143 #define ZIP_OFF_MAX ZIP_INT16_MAX
144 #define ZIP_OFF_MIN ZIP_INT16_MIN
145 #else
146 #error unsupported size of off_t
147 #endif
148 
149 #if defined(HAVE_FTELLO) && defined(HAVE_FSEEKO)
150 #define ZIP_FSEEK_MAX ZIP_OFF_MAX
151 #define ZIP_FSEEK_MIN ZIP_OFF_MIN
152 #else
153 #include <limits.h>
154 #define ZIP_FSEEK_MAX LONG_MAX
155 #define ZIP_FSEEK_MIN LONG_MIN
156 #endif
157 
158 #ifndef SIZE_MAX
159 #if SIZEOF_SIZE_T == 8
160 #define SIZE_MAX ZIP_INT64_MAX
161 #elif SIZEOF_SIZE_T == 4
162 #define SIZE_MAX ZIP_INT32_MAX
163 #elif SIZEOF_SIZE_T == 2
164 #define SIZE_MAX ZIP_INT16_MAX
165 #else
166 #error unsupported size of size_t
167 #endif
168 #endif
169 
170 #ifndef PRId64
171 #ifdef _MSC_VER
172 #define PRId64 "I64d"
173 #else
174 #define PRId64 "lld"
175 #endif
176 #endif
177 
178 #ifndef PRIu64
179 #ifdef _MSC_VER
180 #define PRIu64 "I64u"
181 #else
182 #define PRIu64 "llu"
183 #endif
184 #endif
185 
186 #ifndef S_ISDIR
187 #define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
188 #endif
189 
190 #ifndef S_ISREG
191 #define S_ISREG(mode) (((mode)&S_IFMT) == S_IFREG)
192 #endif
193 
194 #endif /* compat.h */
char bool
Definition: compat.h:57