compat.h 4.7 KB

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