Import libarchive-2.5.5.
[dragonfly.git] / contrib / libarchive-2.0 / libarchive / archive_platform.h
bloba7e771af128c8faa6c681c543de72a6f8e6e9266
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/lib/libarchive/archive_platform.h,v 1.24 2007/01/09 08:05:54 kientzle Exp $
29 * This header is the first thing included in any of the libarchive
30 * source files. As far as possible, platform-specific issues should
31 * be dealt with here and not within individual source files. I'm
32 * actively trying to minimize #if blocks within the main source,
33 * since they obfuscate the code.
36 #ifndef ARCHIVE_PLATFORM_H_INCLUDED
37 #define ARCHIVE_PLATFORM_H_INCLUDED
39 #if defined(HAVE_CONFIG_H)
40 /* Most POSIX platforms use the 'configure' script to build config.h */
41 #include "../config.h"
42 #elif defined(__FreeBSD__)
43 /* Building as part of FreeBSD system requires a pre-built config.h. */
44 #include "config_freebsd.h"
45 #elif defined(_WIN32)
46 /* Win32 can't run the 'configure' script. */
47 #include "config_windows.h"
48 #else
49 /* Warn if the library hasn't been (automatically or manually) configured. */
50 #error Oops: No config.h and no pre-built configuration in archive_platform.h.
51 #endif
54 * The config files define a lot of feature macros. The following
55 * uses those macros to select/define replacements and include key
56 * headers as required.
59 /* No non-FreeBSD platform will have __FBSDID, so just define it here. */
60 #ifdef __FreeBSD__
61 #include <sys/cdefs.h> /* For __FBSDID */
62 #else
63 #define __FBSDID(a) /* null */
64 #endif
66 /* Try to get standard C99-style integer type definitions. */
67 #if HAVE_INTTYPES_H
68 #include <inttypes.h>
69 #elif HAVE_STDINT_H
70 #include <stdint.h>
71 #endif
74 * If this platform has <sys/acl.h>, acl_create(), acl_init(),
75 * acl_set_file(), and ACL_USER, we assume it has the rest of the
76 * POSIX.1e draft functions used in archive_read_extract.c.
78 #if HAVE_SYS_ACL_H && HAVE_ACL_CREATE_ENTRY && HAVE_ACL_INIT && HAVE_ACL_SET_FILE && HAVE_ACL_USER
79 #define HAVE_POSIX_ACL 1
80 #endif
83 * If we can't restore metadata using a file descriptor, then
84 * for compatibility's sake, close files before trying to restore metadata.
86 #if defined(HAVE_FCHMOD) || defined(HAVE_FUTIMES) || defined(HAVE_ACL_SET_FD) || defined(HAVE_ACL_SET_FD_NP) || defined(HAVE_FCHOWN)
87 #define CAN_RESTORE_METADATA_FD
88 #endif
90 /* Set up defaults for internal error codes. */
91 #ifndef ARCHIVE_ERRNO_FILE_FORMAT
92 #if HAVE_EFTYPE
93 #define ARCHIVE_ERRNO_FILE_FORMAT EFTYPE
94 #else
95 #if HAVE_EILSEQ
96 #define ARCHIVE_ERRNO_FILE_FORMAT EILSEQ
97 #else
98 #define ARCHIVE_ERRNO_FILE_FORMAT EINVAL
99 #endif
100 #endif
101 #endif
103 #ifndef ARCHIVE_ERRNO_PROGRAMMER
104 #define ARCHIVE_ERRNO_PROGRAMMER EINVAL
105 #endif
107 #ifndef ARCHIVE_ERRNO_MISC
108 #define ARCHIVE_ERRNO_MISC (-1)
109 #endif
111 /* Select the best way to set/get hi-res timestamps. */
112 #if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
113 /* FreeBSD uses "timespec" members. */
114 #define ARCHIVE_STAT_ATIME_NANOS(st) (st)->st_atimespec.tv_nsec
115 #define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctimespec.tv_nsec
116 #define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtimespec.tv_nsec
117 #define ARCHIVE_STAT_SET_ATIME_NANOS(st, n) (st)->st_atimespec.tv_nsec = (n)
118 #define ARCHIVE_STAT_SET_CTIME_NANOS(st, n) (st)->st_ctimespec.tv_nsec = (n)
119 #define ARCHIVE_STAT_SET_MTIME_NANOS(st, n) (st)->st_mtimespec.tv_nsec = (n)
120 #else
121 #if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
122 /* Linux uses "tim" members. */
123 #define ARCHIVE_STAT_ATIME_NANOS(pstat) (pstat)->st_atim.tv_nsec
124 #define ARCHIVE_STAT_CTIME_NANOS(pstat) (pstat)->st_ctim.tv_nsec
125 #define ARCHIVE_STAT_MTIME_NANOS(pstat) (pstat)->st_mtim.tv_nsec
126 #define ARCHIVE_STAT_SET_ATIME_NANOS(st, n) (st)->st_atim.tv_nsec = (n)
127 #define ARCHIVE_STAT_SET_CTIME_NANOS(st, n) (st)->st_ctim.tv_nsec = (n)
128 #define ARCHIVE_STAT_SET_MTIME_NANOS(st, n) (st)->st_mtim.tv_nsec = (n)
129 #else
130 /* If we can't find a better way, just use stubs. */
131 #define ARCHIVE_STAT_ATIME_NANOS(pstat) 0
132 #define ARCHIVE_STAT_CTIME_NANOS(pstat) 0
133 #define ARCHIVE_STAT_MTIME_NANOS(pstat) 0
134 #define ARCHIVE_STAT_SET_ATIME_NANOS(st, n) ((void)(n))
135 #define ARCHIVE_STAT_SET_CTIME_NANOS(st, n) ((void)(n))
136 #define ARCHIVE_STAT_SET_MTIME_NANOS(st, n) ((void)(n))
137 #endif
138 #endif
140 #endif /* !ARCHIVE_H_INCLUDED */