Import libarchive-2.5.5.
[dragonfly.git] / contrib / libarchive-2.0 / tar / bsdtar_platform.h
blob56e17d7f734a45dc716ca839cbc5d689a1330611
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.23 2007/03/11 10:36:42 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 HAVE_CONFIG_H
38 #include "../config.h"
39 #else
41 #ifdef __FreeBSD__
42 #include "config_freebsd.h"
43 #else /* !__FreeBSD__ */
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 /* !__FreeBSD__ */
48 #endif /* !HAVE_CONFIG_H */
50 /* No non-FreeBSD platform will have __FBSDID, so just define it here. */
51 #ifdef __FreeBSD__
52 #include <sys/cdefs.h> /* For __FBSDID */
53 #else
54 #define __FBSDID(a) /* null */
55 #endif
57 #ifdef HAVE_LIBARCHIVE
58 /* If we're using the platform libarchive, include system headers. */
59 #include <archive.h>
60 #include <archive_entry.h>
61 #else
62 /* Otherwise, include user headers. */
63 #include "archive.h"
64 #include "archive_entry.h"
65 #endif
68 * Does this platform have complete-looking POSIX-style ACL support,
69 * including some variant of the acl_get_perm() function (which was
70 * omitted from the POSIX.1e draft)?
72 #if HAVE_SYS_ACL_H && HAVE_ACL_PERMSET_T && HAVE_ACL_USER
73 #if HAVE_ACL_GET_PERM || HAVE_ACL_GET_PERM_NP
74 #define HAVE_POSIX_ACL 1
75 #endif
76 #endif
78 #ifdef HAVE_LIBACL
79 #include <acl/libacl.h>
80 #endif
82 #if HAVE_ACL_GET_PERM
83 #define ACL_GET_PERM acl_get_perm
84 #else
85 #if HAVE_ACL_GET_PERM_NP
86 #define ACL_GET_PERM acl_get_perm_np
87 #endif
88 #endif
91 * Include "dirent.h" (or it's equivalent on several different platforms).
93 * This is slightly modified from the GNU autoconf recipe.
94 * In particular, FreeBSD includes d_namlen in it's dirent structure,
95 * so my configure script includes an explicit test for the d_namlen
96 * field.
98 #if HAVE_DIRENT_H
99 # include <dirent.h>
100 # if HAVE_DIRENT_D_NAMLEN
101 # define DIRENT_NAMLEN(dirent) (dirent)->d_namlen
102 # else
103 # define DIRENT_NAMLEN(dirent) strlen((dirent)->d_name)
104 # endif
105 #else
106 # define dirent direct
107 # define DIRENT_NAMLEN(dirent) (dirent)->d_namlen
108 # if HAVE_SYS_NDIR_H
109 # include <sys/ndir.h>
110 # endif
111 # if HAVE_SYS_DIR_H
112 # include <sys/dir.h>
113 # endif
114 # if HAVE_NDIR_H
115 # include <ndir.h>
116 # endif
117 #endif
121 * We need to be able to display a filesize using printf(). The type
122 * and format string here must be compatible with one another and
123 * large enough for any file.
125 #if HAVE_UINTMAX_T
126 #define BSDTAR_FILESIZE_TYPE uintmax_t
127 #define BSDTAR_FILESIZE_PRINTF "%ju"
128 #else
129 #if HAVE_UNSIGNED_LONG_LONG
130 #define BSDTAR_FILESIZE_TYPE unsigned long long
131 #define BSDTAR_FILESIZE_PRINTF "%llu"
132 #else
133 #define BSDTAR_FILESIZE_TYPE unsigned long
134 #define BSDTAR_FILESIZE_PRINTF "%lu"
135 #endif
136 #endif
138 #if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
139 #define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctimespec.tv_nsec
140 #define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtimespec.tv_nsec
141 #else
142 #if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
143 #define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctim.tv_nsec
144 #define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtim.tv_nsec
145 #else
146 #define ARCHIVE_STAT_CTIME_NANOS(st) (0)
147 #define ARCHIVE_STAT_MTIME_NANOS(st) (0)
148 #endif
149 #endif
151 #endif /* !BSDTAR_PLATFORM_H_INCLUDED */