Remove old versions of libarchive.
[dragonfly.git] / contrib / libarchive-2 / libarchive / archive_platform.h
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/lib/libarchive/archive_platform.h,v 1.30 2008/05/26 17:00:22 kientzle Exp $
26  */
27
28 /*
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.
34  */
35
36 #ifndef ARCHIVE_PLATFORM_H_INCLUDED
37 #define ARCHIVE_PLATFORM_H_INCLUDED
38
39 /* archive.h and archive_entry.h require this. */
40 #define __LIBARCHIVE_BUILD 1
41
42 #ifdef _WIN32
43 #include "config_windows.h"
44 #include "archive_windows.h"
45 #elif defined(PLATFORM_CONFIG_H)
46 /* Use hand-built config.h in environments that need it. */
47 #include PLATFORM_CONFIG_H
48 #elif defined(HAVE_CONFIG_H)
49 /* Most POSIX platforms use the 'configure' script to build config.h */
50 #include "../config.h"
51 #else
52 /* Warn if the library hasn't been (automatically or manually) configured. */
53 #error Oops: No config.h and no pre-built configuration in archive_platform.h.
54 #endif
55
56 /*
57  * The config files define a lot of feature macros.  The following
58  * uses those macros to select/define replacements and include key
59  * headers as required.
60  */
61
62 /* No non-FreeBSD platform will have __FBSDID, so just define it here. */
63 #ifdef __FreeBSD__
64 #include <sys/cdefs.h>  /* For __FBSDID */
65 #else
66 /* Just leaving this macro replacement empty leads to a dangling semicolon. */
67 #define __FBSDID(a)     struct _undefined_hack
68 #endif
69
70 /* Try to get standard C99-style integer type definitions. */
71 #if HAVE_INTTYPES_H
72 #include <inttypes.h>
73 #elif HAVE_STDINT_H
74 #include <stdint.h>
75 #endif
76
77 /* Some platforms lack the standard *_MAX definitions. */
78 #if !HAVE_DECL_SIZE_MAX
79 #define SIZE_MAX (~(size_t)0)
80 #endif
81 #if !HAVE_DECL_UINT32_MAX
82 #define UINT32_MAX (~(uint32_t)0)
83 #endif
84 #if !HAVE_DECL_UINT64_MAX
85 #define UINT64_MAX (~(uint64_t)0)
86 #endif
87 #if !HAVE_DECL_INT64_MAX
88 #define INT64_MAX ((int64_t)(UINT64_MAX >> 1))
89 #endif
90 #if !HAVE_DECL_INT64_MIN
91 #define INT64_MIN ((int64_t)(~INT64_MAX))
92 #endif
93
94 /*
95  * If this platform has <sys/acl.h>, acl_create(), acl_init(),
96  * acl_set_file(), and ACL_USER, we assume it has the rest of the
97  * POSIX.1e draft functions used in archive_read_extract.c.
98  */
99 #if HAVE_SYS_ACL_H && HAVE_ACL_CREATE_ENTRY && HAVE_ACL_INIT && HAVE_ACL_SET_FILE && HAVE_ACL_USER
100 #define HAVE_POSIX_ACL  1
101 #endif
102
103 /*
104  * If we can't restore metadata using a file descriptor, then
105  * for compatibility's sake, close files before trying to restore metadata.
106  */
107 #if defined(HAVE_FCHMOD) || defined(HAVE_FUTIMES) || defined(HAVE_ACL_SET_FD) || defined(HAVE_ACL_SET_FD_NP) || defined(HAVE_FCHOWN)
108 #define CAN_RESTORE_METADATA_FD
109 #endif
110
111 /* Set up defaults for internal error codes. */
112 #ifndef ARCHIVE_ERRNO_FILE_FORMAT
113 #if HAVE_EFTYPE
114 #define ARCHIVE_ERRNO_FILE_FORMAT EFTYPE
115 #else
116 #if HAVE_EILSEQ
117 #define ARCHIVE_ERRNO_FILE_FORMAT EILSEQ
118 #else
119 #define ARCHIVE_ERRNO_FILE_FORMAT EINVAL
120 #endif
121 #endif
122 #endif
123
124 #ifndef ARCHIVE_ERRNO_PROGRAMMER
125 #define ARCHIVE_ERRNO_PROGRAMMER EINVAL
126 #endif
127
128 #ifndef ARCHIVE_ERRNO_MISC
129 #define ARCHIVE_ERRNO_MISC (-1)
130 #endif
131
132 #endif /* !ARCHIVE_PLATFORM_H_INCLUDED */