archive_platform.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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: src/lib/libarchive/archive_platform.h,v 1.32 2008/12/06 05:53:05 kientzle Exp $
  26. */
  27. /*
  28. * This header is the first thing included in any of the libarchive
  29. * source files. As far as possible, platform-specific issues should
  30. * be dealt with here and not within individual source files. I'm
  31. * actively trying to minimize #if blocks within the main source,
  32. * since they obfuscate the code.
  33. */
  34. #ifndef ARCHIVE_PLATFORM_H_INCLUDED
  35. #define ARCHIVE_PLATFORM_H_INCLUDED
  36. /* archive.h and archive_entry.h require this. */
  37. #define __LIBARCHIVE_BUILD 1
  38. #if defined(PLATFORM_CONFIG_H)
  39. /* Use hand-built config.h in environments that need it. */
  40. #include PLATFORM_CONFIG_H
  41. #elif defined(HAVE_CONFIG_H)
  42. /* Most POSIX platforms use the 'configure' script to build config.h */
  43. #include "config.h"
  44. #else
  45. /* Warn if the library hasn't been (automatically or manually) configured. */
  46. #error Oops: No config.h and no pre-built configuration in archive_platform.h.
  47. #endif
  48. /*
  49. * The config files define a lot of feature macros. The following
  50. * uses those macros to select/define replacements and include key
  51. * headers as required.
  52. */
  53. /* Get a real definition for __FBSDID if we can */
  54. #if HAVE_SYS_CDEFS_H
  55. #include <sys/cdefs.h>
  56. #endif
  57. /* If not, define it so as to avoid dangling semicolons. */
  58. #ifndef __FBSDID
  59. #define __FBSDID(a) struct _undefined_hack
  60. #endif
  61. /* Try to get standard C99-style integer type definitions. */
  62. #if HAVE_INTTYPES_H
  63. #include <inttypes.h>
  64. #endif
  65. #if HAVE_STDINT_H
  66. #include <stdint.h>
  67. #endif
  68. /* Some platforms lack the standard *_MAX definitions. */
  69. #if !HAVE_DECL_SIZE_MAX
  70. #define SIZE_MAX (~(size_t)0)
  71. #endif
  72. #if !HAVE_DECL_SSIZE_MAX
  73. #define SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1))
  74. #endif
  75. #if !HAVE_DECL_UINT32_MAX
  76. #define UINT32_MAX (~(uint32_t)0)
  77. #endif
  78. #if !HAVE_DECL_UINT64_MAX
  79. #define UINT64_MAX (~(uint64_t)0)
  80. #endif
  81. #if !HAVE_DECL_INT64_MAX
  82. #define INT64_MAX ((int64_t)(UINT64_MAX >> 1))
  83. #endif
  84. #if !HAVE_DECL_INT64_MIN
  85. #define INT64_MIN ((int64_t)(~INT64_MAX))
  86. #endif
  87. /*
  88. * If this platform has <sys/acl.h>, acl_create(), acl_init(),
  89. * acl_set_file(), and ACL_USER, we assume it has the rest of the
  90. * POSIX.1e draft functions used in archive_read_extract.c.
  91. */
  92. #if HAVE_SYS_ACL_H && HAVE_ACL_CREATE_ENTRY && HAVE_ACL_INIT && HAVE_ACL_SET_FILE && HAVE_ACL_USER
  93. #define HAVE_POSIX_ACL 1
  94. #endif
  95. /*
  96. * If we can't restore metadata using a file descriptor, then
  97. * for compatibility's sake, close files before trying to restore metadata.
  98. */
  99. #if defined(HAVE_FCHMOD) || defined(HAVE_FUTIMES) || defined(HAVE_ACL_SET_FD) || defined(HAVE_ACL_SET_FD_NP) || defined(HAVE_FCHOWN)
  100. #define CAN_RESTORE_METADATA_FD
  101. #endif
  102. /* Set up defaults for internal error codes. */
  103. #ifndef ARCHIVE_ERRNO_FILE_FORMAT
  104. #if HAVE_EFTYPE
  105. #define ARCHIVE_ERRNO_FILE_FORMAT EFTYPE
  106. #else
  107. #if HAVE_EILSEQ
  108. #define ARCHIVE_ERRNO_FILE_FORMAT EILSEQ
  109. #else
  110. #define ARCHIVE_ERRNO_FILE_FORMAT EINVAL
  111. #endif
  112. #endif
  113. #endif
  114. #ifndef ARCHIVE_ERRNO_PROGRAMMER
  115. #define ARCHIVE_ERRNO_PROGRAMMER EINVAL
  116. #endif
  117. #ifndef ARCHIVE_ERRNO_MISC
  118. #define ARCHIVE_ERRNO_MISC (-1)
  119. #endif
  120. #endif /* !ARCHIVE_PLATFORM_H_INCLUDED */