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