Import libarchive-2.4.17. See NEWS for details.
[dragonfly.git] / contrib / libarchive-2 / tar / bsdtar_platform.h
blobccb9d3c0257e011f3bc494de84264b416da46649
1 /*-
2 * Copyright (c) 2003-2007 Tim Kientzle
3 * All rights reserved.
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.
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.
25 * $FreeBSD: src/usr.bin/tar/bsdtar_platform.h,v 1.25 2008/01/02 00:23:00 kientzle Exp $
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.
34 #ifndef BSDTAR_PLATFORM_H_INCLUDED
35 #define BSDTAR_PLATFORM_H_INCLUDED
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 */
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
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
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)?
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
77 #ifdef HAVE_LIBACL
78 #include <acl/libacl.h>
79 #endif
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
90 * Include "dirent.h" (or it's equivalent on several different platforms).
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.
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
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.
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
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 #else
141 #if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
142 #define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctim.tv_nsec
143 #define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtim.tv_nsec
144 #else
145 #define ARCHIVE_STAT_CTIME_NANOS(st) (0)
146 #define ARCHIVE_STAT_MTIME_NANOS(st) (0)
147 #endif
148 #endif
150 #endif /* !BSDTAR_PLATFORM_H_INCLUDED */