archive_platform.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*-
  2. * Copyright (c) 2003-2007 Tim Kientzle
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. *
  25. * $FreeBSD: head/lib/libarchive/archive_platform.h 201090 2009-12-28 02:22:04Z kientzle $
  26. */
  27. /* !!ONLY FOR USE INTERNALLY TO LIBARCHIVE!! */
  28. /*
  29. * This header is the first thing included in any of the libarchive
  30. * source files. As far as possible, platform-specific issues should
  31. * be dealt with here and not within individual source files. I'm
  32. * actively trying to minimize #if blocks within the main source,
  33. * since they obfuscate the code.
  34. */
  35. #ifndef ARCHIVE_PLATFORM_H_INCLUDED
  36. #define ARCHIVE_PLATFORM_H_INCLUDED
  37. /* archive.h and archive_entry.h require this. */
  38. #define __LIBARCHIVE_BUILD 1
  39. #if defined(PLATFORM_CONFIG_H)
  40. /* Use hand-built config.h in environments that need it. */
  41. #include PLATFORM_CONFIG_H
  42. #elif defined(HAVE_CONFIG_H)
  43. /* Most POSIX platforms use the 'configure' script to build config.h */
  44. #include "config.h"
  45. #else
  46. /* Warn if the library hasn't been (automatically or manually) configured. */
  47. #error Oops: No config.h and no pre-built configuration in archive_platform.h.
  48. #endif
  49. /* On macOS check for some symbols based on the deployment target version. */
  50. #if defined(__APPLE__)
  51. # undef HAVE_FUTIMENS
  52. # undef HAVE_UTIMENSAT
  53. # include <AvailabilityMacros.h>
  54. # if MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
  55. # define HAVE_FUTIMENS 1
  56. # define HAVE_UTIMENSAT 1
  57. # endif
  58. #endif
  59. /* It should be possible to get rid of this by extending the feature-test
  60. * macros to cover Windows API functions, probably along with non-trivial
  61. * refactoring of code to find structures that sit more cleanly on top of
  62. * either Windows or Posix APIs. */
  63. #if (defined(__WIN32__) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__)
  64. #include "archive_windows.h"
  65. #endif
  66. /*
  67. * The config files define a lot of feature macros. The following
  68. * uses those macros to select/define replacements and include key
  69. * headers as required.
  70. */
  71. /* Get a real definition for __FBSDID or __RCSID if we can */
  72. #if HAVE_SYS_CDEFS_H
  73. #include <sys/cdefs.h>
  74. #endif
  75. /* If not, define them so as to avoid dangling semicolons. */
  76. #ifndef __FBSDID
  77. #define __FBSDID(a) struct _undefined_hack
  78. #endif
  79. #ifndef __RCSID
  80. #define __RCSID(a) struct _undefined_hack
  81. #endif
  82. /* Old glibc mbsnrtowcs fails assertions in our use case. */
  83. #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 1
  84. # undef HAVE_MBSNRTOWCS
  85. #endif
  86. /* Try to get standard C99-style integer type definitions. */
  87. #if HAVE_INTTYPES_H
  88. #include <inttypes.h>
  89. #endif
  90. #if HAVE_STDINT_H
  91. #include <stdint.h>
  92. #endif
  93. /* Borland warns about its own constants! */
  94. #if defined(__BORLANDC__)
  95. # if HAVE_DECL_UINT64_MAX
  96. # undef UINT64_MAX
  97. # undef HAVE_DECL_UINT64_MAX
  98. # endif
  99. # if HAVE_DECL_UINT64_MIN
  100. # undef UINT64_MIN
  101. # undef HAVE_DECL_UINT64_MIN
  102. # endif
  103. # if HAVE_DECL_INT64_MAX
  104. # undef INT64_MAX
  105. # undef HAVE_DECL_INT64_MAX
  106. # endif
  107. # if HAVE_DECL_INT64_MIN
  108. # undef INT64_MIN
  109. # undef HAVE_DECL_INT64_MIN
  110. # endif
  111. #endif
  112. /* Some platforms lack the standard *_MAX definitions. */
  113. #if !HAVE_DECL_SIZE_MAX
  114. #define SIZE_MAX (~(size_t)0)
  115. #endif
  116. #if !HAVE_DECL_SSIZE_MAX
  117. #define SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1))
  118. #endif
  119. #if !HAVE_DECL_UINT32_MAX
  120. #define UINT32_MAX (~(uint32_t)0)
  121. #endif
  122. #if !HAVE_DECL_INT32_MAX
  123. #define INT32_MAX ((int32_t)(UINT32_MAX >> 1))
  124. #endif
  125. #if !HAVE_DECL_INT32_MIN
  126. #define INT32_MIN ((int32_t)(~INT32_MAX))
  127. #endif
  128. #if !HAVE_DECL_UINT64_MAX
  129. #define UINT64_MAX (~(uint64_t)0)
  130. #endif
  131. #if !HAVE_DECL_INT64_MAX
  132. #define INT64_MAX ((int64_t)(UINT64_MAX >> 1))
  133. #endif
  134. #if !HAVE_DECL_INT64_MIN
  135. #define INT64_MIN ((int64_t)(~INT64_MAX))
  136. #endif
  137. #if !HAVE_DECL_UINTMAX_MAX
  138. #define UINTMAX_MAX (~(uintmax_t)0)
  139. #endif
  140. #if !HAVE_DECL_INTMAX_MAX
  141. #define INTMAX_MAX ((intmax_t)(UINTMAX_MAX >> 1))
  142. #endif
  143. #if !HAVE_DECL_INTMAX_MIN
  144. #define INTMAX_MIN ((intmax_t)(~INTMAX_MAX))
  145. #endif
  146. /*
  147. * If we can't restore metadata using a file descriptor, then
  148. * for compatibility's sake, close files before trying to restore metadata.
  149. */
  150. #if defined(HAVE_FCHMOD) || defined(HAVE_FUTIMES) || defined(HAVE_ACL_SET_FD) || defined(HAVE_ACL_SET_FD_NP) || defined(HAVE_FCHOWN)
  151. #define CAN_RESTORE_METADATA_FD
  152. #endif
  153. /*
  154. * glibc 2.24 deprecates readdir_r
  155. */
  156. #if defined(HAVE_READDIR_R) && (!defined(__GLIBC__) || !defined(__GLIBC_MINOR__) || __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 24))
  157. #define USE_READDIR_R 1
  158. #else
  159. #undef USE_READDIR_R
  160. #endif
  161. /* Set up defaults for internal error codes. */
  162. #ifndef ARCHIVE_ERRNO_FILE_FORMAT
  163. #if HAVE_EFTYPE
  164. #define ARCHIVE_ERRNO_FILE_FORMAT EFTYPE
  165. #else
  166. #if HAVE_EILSEQ
  167. #define ARCHIVE_ERRNO_FILE_FORMAT EILSEQ
  168. #else
  169. #define ARCHIVE_ERRNO_FILE_FORMAT EINVAL
  170. #endif
  171. #endif
  172. #endif
  173. #ifndef ARCHIVE_ERRNO_PROGRAMMER
  174. #define ARCHIVE_ERRNO_PROGRAMMER EINVAL
  175. #endif
  176. #ifndef ARCHIVE_ERRNO_MISC
  177. #define ARCHIVE_ERRNO_MISC (-1)
  178. #endif
  179. #endif /* !ARCHIVE_PLATFORM_H_INCLUDED */