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__CLOSE)
78 #if defined(HAVE__DUP)
81 /* crashes reported when using fdopen instead of _fdopen on Windows/Visual Studio 10/Win64 */
82 #if defined(HAVE__FDOPEN)
83 #define fdopen _fdopen
85 #if !defined(HAVE_FILENO) && defined(HAVE__FILENO)
86 #define fileno _fileno
88 /* Windows' open() doesn't understand Unix permissions */
89 #if defined(HAVE__OPEN)
90 #define open(a, b, c) _open((a), (b))
92 #if defined(HAVE__SNPRINTF)
93 #define snprintf _snprintf
95 #if defined(HAVE__STRDUP)
96 #if !defined(HAVE_STRDUP) || defined(_WIN32)
98 #define strdup _strdup
101 #if !defined(HAVE__SETMODE) && defined(HAVE_SETMODE)
102 #define _setmode setmode
107 #define fseeko(s, o, w) (fseek((s), (long int)(o), (w)))
111 #define ftello(s) ((long)ftell((s)))
115 int _zip_mkstemp(char *);
116 #define mkstemp _zip_mkstemp
119 #if !defined(HAVE_STRCASECMP)
120 #if defined(HAVE__STRICMP)
121 #define strcasecmp _stricmp
122 #elif defined(HAVE_STRICMP)
123 #define strcasecmp stricmp
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
137 #error unsupported size of off_t
140 #if defined(HAVE_FTELLO) && defined(HAVE_FSEEKO)
141 #define ZIP_FSEEK_MAX ZIP_OFF_MAX
142 #define ZIP_FSEEK_MIN ZIP_OFF_MIN
145 #define ZIP_FSEEK_MAX LONG_MAX
146 #define ZIP_FSEEK_MIN LONG_MIN
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
157 #error unsupported size of size_t
163 #define PRId64 "I64d"
171 #define PRIu64 "I64u"
178 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
181 #endif /* compat.h */