bsdtar_platform.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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/usr.bin/tar/bsdtar_platform.h,v 1.26 2008/12/06 07:37:14 kientzle Exp $
  26. */
  27. /*
  28. * This header is the first thing included in any of the bsdtar
  29. * source files. As far as possible, platform-specific issues should
  30. * be dealt with here and not within individual source files.
  31. */
  32. #ifndef BSDTAR_PLATFORM_H_INCLUDED
  33. #define BSDTAR_PLATFORM_H_INCLUDED
  34. #if defined(PLATFORM_CONFIG_H)
  35. /* Use hand-built config.h in environments that need it. */
  36. #include PLATFORM_CONFIG_H
  37. #elif defined(HAVE_CONFIG_H)
  38. /* Most POSIX platforms use the 'configure' script to build config.h */
  39. #include "config.h"
  40. #else
  41. /* Warn if bsdtar hasn't been (automatically or manually) configured. */
  42. #error Oops: No config.h and no built-in configuration in bsdtar_platform.h.
  43. #endif /* !HAVE_CONFIG_H */
  44. /* Get a real definition for __FBSDID if we can */
  45. #if HAVE_SYS_CDEFS_H
  46. #include <sys/cdefs.h>
  47. #endif
  48. /* If not, define it so as to avoid dangling semicolons. */
  49. #ifndef __FBSDID
  50. #define __FBSDID(a) struct _undefined_hack
  51. #endif
  52. #ifdef HAVE_LIBARCHIVE
  53. /* If we're using the platform libarchive, include system headers. */
  54. #include <archive.h>
  55. #include <archive_entry.h>
  56. #else
  57. /* Otherwise, include user headers. */
  58. #include "archive.h"
  59. #include "archive_entry.h"
  60. #endif
  61. /*
  62. * Does this platform have complete-looking POSIX-style ACL support,
  63. * including some variant of the acl_get_perm() function (which was
  64. * omitted from the POSIX.1e draft)?
  65. */
  66. #if HAVE_SYS_ACL_H && HAVE_ACL_PERMSET_T && HAVE_ACL_USER
  67. #if HAVE_ACL_GET_PERM || HAVE_ACL_GET_PERM_NP
  68. #define HAVE_POSIX_ACL 1
  69. #endif
  70. #endif
  71. #ifdef HAVE_LIBACL
  72. #include <acl/libacl.h>
  73. #endif
  74. #if HAVE_ACL_GET_PERM
  75. #define ACL_GET_PERM acl_get_perm
  76. #else
  77. #if HAVE_ACL_GET_PERM_NP
  78. #define ACL_GET_PERM acl_get_perm_np
  79. #endif
  80. #endif
  81. /*
  82. * Include "dirent.h" (or its equivalent on several different platforms).
  83. *
  84. * This is slightly modified from the GNU autoconf recipe.
  85. * In particular, FreeBSD includes d_namlen in its dirent structure,
  86. * so my configure script includes an explicit test for the d_namlen
  87. * field.
  88. */
  89. #if HAVE_DIRENT_H
  90. # include <dirent.h>
  91. # if HAVE_DIRENT_D_NAMLEN
  92. # define DIRENT_NAMLEN(dirent) (dirent)->d_namlen
  93. # else
  94. # define DIRENT_NAMLEN(dirent) strlen((dirent)->d_name)
  95. # endif
  96. #else
  97. # define dirent direct
  98. # define DIRENT_NAMLEN(dirent) (dirent)->d_namlen
  99. # if HAVE_SYS_NDIR_H
  100. # include <sys/ndir.h>
  101. # endif
  102. # if HAVE_SYS_DIR_H
  103. # include <sys/dir.h>
  104. # endif
  105. # if HAVE_NDIR_H
  106. # include <ndir.h>
  107. # endif
  108. #endif
  109. /*
  110. * We need to be able to display a filesize using printf(). The type
  111. * and format string here must be compatible with one another and
  112. * large enough for any file.
  113. */
  114. #if HAVE_UINTMAX_T
  115. #define BSDTAR_FILESIZE_TYPE uintmax_t
  116. #define BSDTAR_FILESIZE_PRINTF "%ju"
  117. #else
  118. #if HAVE_UNSIGNED_LONG_LONG
  119. #define BSDTAR_FILESIZE_TYPE unsigned long long
  120. #define BSDTAR_FILESIZE_PRINTF "%llu"
  121. #else
  122. #define BSDTAR_FILESIZE_TYPE unsigned long
  123. #define BSDTAR_FILESIZE_PRINTF "%lu"
  124. #endif
  125. #endif
  126. #if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
  127. #define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctimespec.tv_nsec
  128. #define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtimespec.tv_nsec
  129. #elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
  130. #define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctim.tv_nsec
  131. #define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtim.tv_nsec
  132. #elif HAVE_STRUCT_STAT_ST_MTIME_N
  133. #define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctime_n
  134. #define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtime_n
  135. #elif HAVE_STRUCT_STAT_ST_UMTIME
  136. #define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_uctime * 1000
  137. #define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_umtime * 1000
  138. #elif HAVE_STRUCT_STAT_ST_MTIME_USEC
  139. #define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctime_usec * 1000
  140. #define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtime_usec * 1000
  141. #else
  142. #define ARCHIVE_STAT_CTIME_NANOS(st) (0)
  143. #define ARCHIVE_STAT_MTIME_NANOS(st) (0)
  144. #endif
  145. /* How to mark functions that don't return. */
  146. /* This facilitates use of some newer static code analysis tools. */
  147. #undef __LA_DEAD
  148. #if defined(__GNUC__) && (__GNUC__ > 2 || \
  149. (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
  150. #define __LA_DEAD __attribute__((__noreturn__))
  151. #else
  152. #define __LA_DEAD
  153. #endif
  154. #if defined(__CYGWIN__)
  155. #include "bsdtar_cygwin.h"
  156. #elif defined(_WIN32) /* && !__CYGWIN__ */
  157. #include "bsdtar_windows.h"
  158. #else
  159. #define bsdtar_is_privileged(bsdtar) (bsdtar->user_uid == 0)
  160. #endif
  161. #endif /* !BSDTAR_PLATFORM_H_INCLUDED */