|
| 1 | +#ifndef _HAD_LIBZIP_COMPAT_H |
| 2 | +#define _HAD_LIBZIP_COMPAT_H |
| 3 | + |
| 4 | +/* |
| 5 | + compat.h -- compatibility defines. |
| 6 | + Copyright (C) 1999-2018 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 | +#include "zipconf.h" |
| 38 | + |
| 39 | +#ifdef HAVE_CONFIG_H |
| 40 | +#include "config.h" |
| 41 | +#endif |
| 42 | + |
| 43 | +/* to have *_MAX definitions for all types when compiling with g++ */ |
| 44 | +#define __STDC_LIMIT_MACROS |
| 45 | + |
| 46 | +#ifdef _WIN32 |
| 47 | +#ifndef ZIP_EXTERN |
| 48 | +#ifndef ZIP_STATIC |
| 49 | +#define ZIP_EXTERN __declspec(dllexport) |
| 50 | +#endif |
| 51 | +#endif |
| 52 | +/* for dup(), close(), etc. */ |
| 53 | +#include <io.h> |
| 54 | +#endif |
| 55 | + |
| 56 | +#ifdef HAVE_STDBOOL_H |
| 57 | +#include <stdbool.h> |
| 58 | +#else |
| 59 | +typedef char bool; |
| 60 | +#define true 1 |
| 61 | +#define false 0 |
| 62 | +#endif |
| 63 | + |
| 64 | +#include <errno.h> |
| 65 | + |
| 66 | +/* at least MinGW does not provide EOPNOTSUPP, see |
| 67 | + * http://sourceforge.net/p/mingw/bugs/263/ |
| 68 | + */ |
| 69 | +#ifndef EOPNOTSUPP |
| 70 | +#define EOPNOTSUPP EINVAL |
| 71 | +#endif |
| 72 | + |
| 73 | +/* at least MinGW does not provide EOVERFLOW, see |
| 74 | + * http://sourceforge.net/p/mingw/bugs/242/ |
| 75 | + */ |
| 76 | +#ifndef EOVERFLOW |
| 77 | +#define EOVERFLOW EFBIG |
| 78 | +#endif |
| 79 | + |
| 80 | +#ifdef _WIN32 |
| 81 | +#if defined(HAVE__CHMOD) |
| 82 | +#define chmod _chmod |
| 83 | +#endif |
| 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 | +/* Windows' open() doesn't understand Unix permissions */ |
| 98 | +#if defined(HAVE__OPEN) |
| 99 | +#define open(a, b, c) _open((a), (b)) |
| 100 | +#endif |
| 101 | +#if defined(HAVE__SNPRINTF) |
| 102 | +#define snprintf _snprintf |
| 103 | +#endif |
| 104 | +#if defined(HAVE__STRDUP) |
| 105 | +#if !defined(HAVE_STRDUP) || defined(_WIN32) |
| 106 | +#undef strdup |
| 107 | +#define strdup _strdup |
| 108 | +#endif |
| 109 | +#endif |
| 110 | +#if !defined(HAVE__SETMODE) && defined(HAVE_SETMODE) |
| 111 | +#define _setmode setmode |
| 112 | +#endif |
| 113 | +#if !defined(HAVE_STRTOLL) && defined(HAVE__STRTOI64) |
| 114 | +#define strtoll _strtoi64 |
| 115 | +#endif |
| 116 | +#if !defined(HAVE_STRTOULL) && defined(HAVE__STRTOUI64) |
| 117 | +#define strtoull _strtoui64 |
| 118 | +#endif |
| 119 | +#if defined(HAVE__UMASK) |
| 120 | +#define umask _umask |
| 121 | +#endif |
| 122 | +#if defined(HAVE__UNLINK) |
| 123 | +#define unlink _unlink |
| 124 | +#endif |
| 125 | +#endif |
| 126 | + |
| 127 | +#ifndef HAVE_FSEEKO |
| 128 | +#define fseeko(s, o, w) (fseek((s), (long int)(o), (w))) |
| 129 | +#endif |
| 130 | + |
| 131 | +#ifndef HAVE_FTELLO |
| 132 | +#define ftello(s) ((long)ftell((s))) |
| 133 | +#endif |
| 134 | + |
| 135 | +#ifndef HAVE_MKSTEMP |
| 136 | +int _zip_mkstemp(char *); |
| 137 | +#define mkstemp _zip_mkstemp |
| 138 | +#endif |
| 139 | + |
| 140 | +#if !defined(HAVE_STRCASECMP) |
| 141 | +#if defined(HAVE__STRICMP) |
| 142 | +#define strcasecmp _stricmp |
| 143 | +#elif defined(HAVE_STRICMP) |
| 144 | +#define strcasecmp stricmp |
| 145 | +#endif |
| 146 | +#endif |
| 147 | + |
| 148 | +#if SIZEOF_OFF_T == 8 |
| 149 | +#define ZIP_OFF_MAX ZIP_INT64_MAX |
| 150 | +#define ZIP_OFF_MIN ZIP_INT64_MIN |
| 151 | +#elif SIZEOF_OFF_T == 4 |
| 152 | +#define ZIP_OFF_MAX ZIP_INT32_MAX |
| 153 | +#define ZIP_OFF_MIN ZIP_INT32_MIN |
| 154 | +#elif SIZEOF_OFF_T == 2 |
| 155 | +#define ZIP_OFF_MAX ZIP_INT16_MAX |
| 156 | +#define ZIP_OFF_MIN ZIP_INT16_MIN |
| 157 | +#else |
| 158 | +#error unsupported size of off_t |
| 159 | +#endif |
| 160 | + |
| 161 | +#if defined(HAVE_FTELLO) && defined(HAVE_FSEEKO) |
| 162 | +#define ZIP_FSEEK_MAX ZIP_OFF_MAX |
| 163 | +#define ZIP_FSEEK_MIN ZIP_OFF_MIN |
| 164 | +#else |
| 165 | +#include <limits.h> |
| 166 | +#define ZIP_FSEEK_MAX LONG_MAX |
| 167 | +#define ZIP_FSEEK_MIN LONG_MIN |
| 168 | +#endif |
| 169 | + |
| 170 | +#ifndef SIZE_MAX |
| 171 | +#if SIZEOF_SIZE_T == 8 |
| 172 | +#define SIZE_MAX ZIP_INT64_MAX |
| 173 | +#elif SIZEOF_SIZE_T == 4 |
| 174 | +#define SIZE_MAX ZIP_INT32_MAX |
| 175 | +#elif SIZEOF_SIZE_T == 2 |
| 176 | +#define SIZE_MAX ZIP_INT16_MAX |
| 177 | +#else |
| 178 | +#error unsupported size of size_t |
| 179 | +#endif |
| 180 | +#endif |
| 181 | + |
| 182 | +#ifndef PRId64 |
| 183 | +#ifdef _MSC_VER |
| 184 | +#define PRId64 "I64d" |
| 185 | +#else |
| 186 | +#define PRId64 "lld" |
| 187 | +#endif |
| 188 | +#endif |
| 189 | + |
| 190 | +#ifndef PRIu64 |
| 191 | +#ifdef _MSC_VER |
| 192 | +#define PRIu64 "I64u" |
| 193 | +#else |
| 194 | +#define PRIu64 "llu" |
| 195 | +#endif |
| 196 | +#endif |
| 197 | + |
| 198 | +#ifndef S_ISDIR |
| 199 | +#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR) |
| 200 | +#endif |
| 201 | + |
| 202 | +#endif /* compat.h */ |
0 commit comments