archive_platform.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. /* It should be possible to get rid of this by extending the feature-test
  50. * macros to cover Windows API functions, probably along with non-trivial
  51. * refactoring of code to find structures that sit more cleanly on top of
  52. * either Windows or Posix APIs. */
  53. #if (defined(__WIN32__) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__)
  54. #include "archive_windows.h"
  55. #endif
  56. /*
  57. * The config files define a lot of feature macros. The following
  58. * uses those macros to select/define replacements and include key
  59. * headers as required.
  60. */
  61. /* Get a real definition for __FBSDID or __RCSID if we can */
  62. #if HAVE_SYS_CDEFS_H
  63. #include <sys/cdefs.h>
  64. #endif
  65. /* If not, define them so as to avoid dangling semicolons. */
  66. #ifndef __FBSDID
  67. #define __FBSDID(a) struct _undefined_hack
  68. #endif
  69. #ifndef __RCSID
  70. #define __RCSID(a) struct _undefined_hack
  71. #endif
  72. /* Old glibc mbsnrtowcs fails assertions in our use case. */
  73. #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 1
  74. # undef HAVE_MBSNRTOWCS
  75. #endif
  76. /* Try to get standard C99-style integer type definitions. */
  77. #if HAVE_INTTYPES_H
  78. #include <inttypes.h>
  79. #endif
  80. #if HAVE_STDINT_H
  81. #include <stdint.h>
  82. #endif
  83. /* Borland warns about its own constants! */
  84. #if defined(__BORLANDC__)
  85. # if HAVE_DECL_UINT64_MAX
  86. # undef UINT64_MAX
  87. # undef HAVE_DECL_UINT64_MAX
  88. # endif
  89. # if HAVE_DECL_UINT64_MIN
  90. # undef UINT64_MIN
  91. # undef HAVE_DECL_UINT64_MIN
  92. # endif
  93. # if HAVE_DECL_INT64_MAX
  94. # undef INT64_MAX
  95. # undef HAVE_DECL_INT64_MAX
  96. # endif
  97. # if HAVE_DECL_INT64_MIN
  98. # undef INT64_MIN
  99. # undef HAVE_DECL_INT64_MIN
  100. # endif
  101. #endif
  102. /* Some platforms lack the standard *_MAX definitions. */
  103. #if !HAVE_DECL_SIZE_MAX
  104. #define SIZE_MAX (~(size_t)0)
  105. #endif
  106. #if !HAVE_DECL_SSIZE_MAX
  107. #define SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1))
  108. #endif
  109. #if !HAVE_DECL_UINT32_MAX
  110. #define UINT32_MAX (~(uint32_t)0)
  111. #endif
  112. #if !HAVE_DECL_UINT64_MAX
  113. #define UINT64_MAX (~(uint64_t)0)
  114. #endif
  115. #if !HAVE_DECL_INT64_MAX
  116. #define INT64_MAX ((int64_t)(UINT64_MAX >> 1))
  117. #endif
  118. #if !HAVE_DECL_INT64_MIN
  119. #define INT64_MIN ((int64_t)(~INT64_MAX))
  120. #endif
  121. /*
  122. * If this platform has <sys/acl.h>, acl_create(), acl_init(),
  123. * acl_set_file(), and ACL_USER, we assume it has the rest of the
  124. * POSIX.1e draft functions used in archive_read_extract.c.
  125. */
  126. #if HAVE_SYS_ACL_H && HAVE_ACL_CREATE_ENTRY && HAVE_ACL_INIT && HAVE_ACL_SET_FILE && HAVE_ACL_USER
  127. #define HAVE_POSIX_ACL 1
  128. #endif
  129. /*
  130. * If we can't restore metadata using a file descriptor, then
  131. * for compatibility's sake, close files before trying to restore metadata.
  132. */
  133. #if defined(HAVE_FCHMOD) || defined(HAVE_FUTIMES) || defined(HAVE_ACL_SET_FD) || defined(HAVE_ACL_SET_FD_NP) || defined(HAVE_FCHOWN)
  134. #define CAN_RESTORE_METADATA_FD
  135. #endif
  136. /* Set up defaults for internal error codes. */
  137. #ifndef ARCHIVE_ERRNO_FILE_FORMAT
  138. #if HAVE_EFTYPE
  139. #define ARCHIVE_ERRNO_FILE_FORMAT EFTYPE
  140. #else
  141. #if HAVE_EILSEQ
  142. #define ARCHIVE_ERRNO_FILE_FORMAT EILSEQ
  143. #else
  144. #define ARCHIVE_ERRNO_FILE_FORMAT EINVAL
  145. #endif
  146. #endif
  147. #endif
  148. #ifndef ARCHIVE_ERRNO_PROGRAMMER
  149. #define ARCHIVE_ERRNO_PROGRAMMER EINVAL
  150. #endif
  151. #ifndef ARCHIVE_ERRNO_MISC
  152. #define ARCHIVE_ERRNO_MISC (-1)
  153. #endif
  154. #endif /* !ARCHIVE_PLATFORM_H_INCLUDED */