1 #ifndef _HAD_LIBZIP_COMPAT_H
2 #define _HAD_LIBZIP_COMPAT_H
5 compat.h -- compatibility defines.
6 Copyright (C) 1999-2016 Dieter Baron and Thomas Klausner
8 This file is part of libzip, a library to manipulate ZIP archives.
9 The authors can be contacted at <libzip@nih.at>
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions
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
20 3. The names of the authors may not be used to endorse or promote
21 products derived from this software without specific prior
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.
41 /* to have *_MAX definitions for all types when compiling with g++ */
42 #define __STDC_LIMIT_MACROS
45 #define ZIP_EXTERN __declspec(dllexport)
46 /* for dup(), close(), etc. */
60 /* at least MinGW does not provide EOPNOTSUPP, see
61 * http://sourceforge.net/p/mingw/bugs/263/
64 #define EOPNOTSUPP EINVAL
67 /* at least MinGW does not provide EOVERFLOW, see
68 * http://sourceforge.net/p/mingw/bugs/242/
71 #define EOVERFLOW EFBIG
75 #if defined(HAVE__CHMOD)
78 #if defined(HAVE__CLOSE)
81 #if defined(HAVE__DUP)
84 /* crashes reported when using fdopen instead of _fdopen on Windows/Visual Studio 10/Win64 */
85 #if defined(HAVE__FDOPEN)
86 #define fdopen _fdopen
88 #if !defined(HAVE_FILENO) && defined(HAVE__FILENO)
89 #define fileno _fileno
91 /* Windows' open() doesn't understand Unix permissions */
92 #if defined(HAVE__OPEN)
93 #define open(a, b, c) _open((a), (b))
95 #if defined(HAVE__SNPRINTF)
96 #define snprintf _snprintf
98 #if defined(HAVE__STRDUP)
99 #if !defined(HAVE_STRDUP) || defined(_WIN32)
101 #define strdup _strdup
104 #if !defined(HAVE__SETMODE) && defined(HAVE_SETMODE)
105 #define _setmode setmode
107 #if !defined(HAVE_STRTOLL) && defined(HAVE__STRTOI64)
108 #define strtoll _strtoi64
110 #if !defined(HAVE_STRTOULL) && defined(HAVE__STRTOUI64)
111 #define strtoull _strtoui64
113 #if defined(HAVE__UMASK)
116 #if defined(HAVE__UNLINK)
117 #define unlink _unlink
122 #define fseeko(s, o, w) (fseek((s), (long int)(o), (w)))
126 #define ftello(s) ((long)ftell((s)))
130 int _zip_mkstemp(char *);
131 #define mkstemp _zip_mkstemp
134 #if !defined(HAVE_STRCASECMP)
135 #if defined(HAVE__STRICMP)
136 #define strcasecmp _stricmp
137 #elif defined(HAVE_STRICMP)
138 #define strcasecmp stricmp
142 #if SIZEOF_OFF_T == 8
143 #define ZIP_OFF_MAX ZIP_INT64_MAX
144 #define ZIP_OFF_MIN ZIP_INT64_MIN
145 #elif SIZEOF_OFF_T == 4
146 #define ZIP_OFF_MAX ZIP_INT32_MAX
147 #define ZIP_OFF_MIN ZIP_INT32_MIN
148 #elif SIZEOF_OFF_T == 2
149 #define ZIP_OFF_MAX ZIP_INT16_MAX
150 #define ZIP_OFF_MIN ZIP_INT16_MIN
152 #error unsupported size of off_t
155 #if defined(HAVE_FTELLO) && defined(HAVE_FSEEKO)
156 #define ZIP_FSEEK_MAX ZIP_OFF_MAX
157 #define ZIP_FSEEK_MIN ZIP_OFF_MIN
160 #define ZIP_FSEEK_MAX LONG_MAX
161 #define ZIP_FSEEK_MIN LONG_MIN
165 #if SIZEOF_SIZE_T == 8
166 #define SIZE_MAX ZIP_INT64_MAX
167 #elif SIZEOF_SIZE_T == 4
168 #define SIZE_MAX ZIP_INT32_MAX
169 #elif SIZEOF_SIZE_T == 2
170 #define SIZE_MAX ZIP_INT16_MAX
172 #error unsupported size of size_t
178 #define PRId64 "I64d"
186 #define PRIu64 "I64u"
193 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
196 #endif /* compat.h */