2 * Copyright (c) 2003-2006 Tim Kientzle
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * This header is the first thing included in any of the libarchive
31 * source files. As far as possible, platform-specific issues should
32 * be dealt with here and not within individual source files. I'm
33 * actively trying to minimize #if blocks within the main source,
34 * since they obfuscate the code.
37 #ifndef ARCHIVE_PLATFORM_H_INCLUDED
38 #define ARCHIVE_PLATFORM_H_INCLUDED
40 #if defined(HAVE_CONFIG_H)
41 /* Most POSIX platforms use the 'configure' script to build config.h */
42 #include "../config.h"
43 #elif defined(__FreeBSD__)
44 /* Building as part of FreeBSD system requires a pre-built config.h. */
45 #include "config_freebsd.h"
47 /* Warn if the library hasn't been (automatically or manually) configured. */
48 #error Oops: No config.h and no pre-built configuration in archive_platform.h.
52 * The config files define a lot of feature macros. The following
53 * uses those macros to select/define replacements and include key
54 * headers as required.
57 /* No non-FreeBSD platform will have __FBSDID, so just define it here. */
59 #include <sys/cdefs.h> /* For __FBSDID */
61 #define __FBSDID(a) /* null */
64 /* Try to get standard C99-style integer type definitions. */
72 * If this platform has <sys/acl.h>, acl_create(), acl_init(),
73 * acl_set_file(), and ACL_USER, we assume it has the rest of the
74 * POSIX.1e draft functions used in archive_read_extract.c.
76 #if HAVE_SYS_ACL_H && HAVE_ACL_CREATE_ENTRY && HAVE_ACL_INIT && HAVE_ACL_SET_FILE && HAVE_ACL_USER
77 #define HAVE_POSIX_ACL 1
81 * If we can't restore metadata using a file descriptor, then
82 * for compatibility's sake, close files before trying to restore metadata.
84 #if defined(HAVE_FCHMOD) || defined(HAVE_FUTIMES) || defined(HAVE_ACL_SET_FD) || defined(HAVE_ACL_SET_FD_NP) || defined(HAVE_FCHOWN)
85 #define CAN_RESTORE_METADATA_FD
88 /* Set up defaults for internal error codes. */
89 #ifndef ARCHIVE_ERRNO_FILE_FORMAT
91 #define ARCHIVE_ERRNO_FILE_FORMAT EFTYPE
94 #define ARCHIVE_ERRNO_FILE_FORMAT EILSEQ
96 #define ARCHIVE_ERRNO_FILE_FORMAT EINVAL
101 #ifndef ARCHIVE_ERRNO_PROGRAMMER
102 #define ARCHIVE_ERRNO_PROGRAMMER EINVAL
105 #ifndef ARCHIVE_ERRNO_MISC
106 #define ARCHIVE_ERRNO_MISC (-1)
109 /* Select the best way to set/get hi-res timestamps. */
110 #if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
111 /* FreeBSD uses "timespec" members. */
112 #define ARCHIVE_STAT_ATIME_NANOS(st) (st)->st_atimespec.tv_nsec
113 #define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctimespec.tv_nsec
114 #define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtimespec.tv_nsec
115 #define ARCHIVE_STAT_SET_ATIME_NANOS(st, n) (st)->st_atimespec.tv_nsec = (n)
116 #define ARCHIVE_STAT_SET_CTIME_NANOS(st, n) (st)->st_ctimespec.tv_nsec = (n)
117 #define ARCHIVE_STAT_SET_MTIME_NANOS(st, n) (st)->st_mtimespec.tv_nsec = (n)
119 #if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
120 /* Linux uses "tim" members. */
121 #define ARCHIVE_STAT_ATIME_NANOS(pstat) (pstat)->st_atim.tv_nsec
122 #define ARCHIVE_STAT_CTIME_NANOS(pstat) (pstat)->st_ctim.tv_nsec
123 #define ARCHIVE_STAT_MTIME_NANOS(pstat) (pstat)->st_mtim.tv_nsec
124 #define ARCHIVE_STAT_SET_ATIME_NANOS(st, n) (st)->st_atim.tv_nsec = (n)
125 #define ARCHIVE_STAT_SET_CTIME_NANOS(st, n) (st)->st_ctim.tv_nsec = (n)
126 #define ARCHIVE_STAT_SET_MTIME_NANOS(st, n) (st)->st_mtim.tv_nsec = (n)
128 /* If we can't find a better way, just use stubs. */
129 #define ARCHIVE_STAT_ATIME_NANOS(pstat) 0
130 #define ARCHIVE_STAT_CTIME_NANOS(pstat) 0
131 #define ARCHIVE_STAT_MTIME_NANOS(pstat) 0
132 #define ARCHIVE_STAT_SET_ATIME_NANOS(st, n) ((void)(n))
133 #define ARCHIVE_STAT_SET_CTIME_NANOS(st, n) ((void)(n))
134 #define ARCHIVE_STAT_SET_MTIME_NANOS(st, n) ((void)(n))
138 #endif /* !ARCHIVE_H_INCLUDED */