archive_platform.h revision 306379
166458Sdfr/*-
266458Sdfr * Copyright (c) 2003-2007 Tim Kientzle
366458Sdfr * All rights reserved.
466458Sdfr *
566458Sdfr * Redistribution and use in source and binary forms, with or without
666458Sdfr * modification, are permitted provided that the following conditions
766458Sdfr * are met:
866458Sdfr * 1. Redistributions of source code must retain the above copyright
966458Sdfr *    notice, this list of conditions and the following disclaimer.
1066458Sdfr * 2. Redistributions in binary form must reproduce the above copyright
1166458Sdfr *    notice, this list of conditions and the following disclaimer in the
1266458Sdfr *    documentation and/or other materials provided with the distribution.
1366458Sdfr *
1466458Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
1566458Sdfr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1666458Sdfr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1766458Sdfr * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
1866458Sdfr * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1966458Sdfr * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2066458Sdfr * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2166458Sdfr * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2266458Sdfr * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2366458Sdfr * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2466458Sdfr *
2566458Sdfr * $FreeBSD: releng/11.0/contrib/libarchive/libarchive/archive_platform.h 306379 2016-09-27 19:36:12Z emaste $
2666458Sdfr */
2766458Sdfr
2866458Sdfr/* !!ONLY FOR USE INTERNALLY TO LIBARCHIVE!! */
29131840Sbrian
3071785Speter/*
3166458Sdfr * This header is the first thing included in any of the libarchive
3266458Sdfr * source files.  As far as possible, platform-specific issues should
3366458Sdfr * be dealt with here and not within individual source files.  I'm
3466458Sdfr * actively trying to minimize #if blocks within the main source,
3566458Sdfr * since they obfuscate the code.
3666458Sdfr */
3766458Sdfr
3866458Sdfr#ifndef ARCHIVE_PLATFORM_H_INCLUDED
3966458Sdfr#define	ARCHIVE_PLATFORM_H_INCLUDED
4066458Sdfr
4166458Sdfr/* archive.h and archive_entry.h require this. */
4266458Sdfr#define	__LIBARCHIVE_BUILD 1
4366458Sdfr
4466458Sdfr#if defined(PLATFORM_CONFIG_H)
4566458Sdfr/* Use hand-built config.h in environments that need it. */
4666458Sdfr#include PLATFORM_CONFIG_H
4766458Sdfr#elif defined(HAVE_CONFIG_H)
4866458Sdfr/* Most POSIX platforms use the 'configure' script to build config.h */
4966458Sdfr#include "config.h"
5066458Sdfr#else
5166458Sdfr/* Warn if the library hasn't been (automatically or manually) configured. */
52143796Siedowse#error Oops: No config.h and no pre-built configuration in archive_platform.h.
5392843Salfred#endif
54143796Siedowse
5566458Sdfr/* It should be possible to get rid of this by extending the feature-test
56143796Siedowse * macros to cover Windows API functions, probably along with non-trivial
57143796Siedowse * refactoring of code to find structures that sit more cleanly on top of
58143796Siedowse * either Windows or Posix APIs. */
59143796Siedowse#if (defined(__WIN32__) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__)
60143796Siedowse#include "archive_windows.h"
61143796Siedowse#endif
62131840Sbrian
6393997Smarcel/*
64131840Sbrian * The config files define a lot of feature macros.  The following
6593997Smarcel * uses those macros to select/define replacements and include key
6671785Speter * headers as required.
6766458Sdfr */
6866458Sdfr
6966458Sdfr/* Get a real definition for __FBSDID or __RCSID if we can */
7066458Sdfr#if HAVE_SYS_CDEFS_H
7166458Sdfr#include <sys/cdefs.h>
7266458Sdfr#endif
7366458Sdfr
7466458Sdfr/* If not, define them so as to avoid dangling semicolons. */
75143796Siedowse#ifndef __FBSDID
76143796Siedowse#define	__FBSDID(a)     struct _undefined_hack
77143796Siedowse#endif
78143796Siedowse#ifndef __RCSID
79143796Siedowse#define	__RCSID(a)     struct _undefined_hack
8066458Sdfr#endif
8166458Sdfr
82146791Smarcel/* Try to get standard C99-style integer type definitions. */
8366458Sdfr#if HAVE_INTTYPES_H
8466458Sdfr#include <inttypes.h>
8566458Sdfr#endif
8666458Sdfr#if HAVE_STDINT_H
8766458Sdfr#include <stdint.h>
8866458Sdfr#endif
8966458Sdfr
9071785Speter/* Borland warns about its own constants!  */
9166458Sdfr#if defined(__BORLANDC__)
9266458Sdfr# if HAVE_DECL_UINT64_MAX
9366458Sdfr#  undef	UINT64_MAX
94143796Siedowse#  undef	HAVE_DECL_UINT64_MAX
9566458Sdfr# endif
96143796Siedowse# if HAVE_DECL_UINT64_MIN
97143796Siedowse#  undef	UINT64_MIN
98143796Siedowse#  undef	HAVE_DECL_UINT64_MIN
99143796Siedowse# endif
10066458Sdfr# if HAVE_DECL_INT64_MAX
10166458Sdfr#  undef	INT64_MAX
10266458Sdfr#  undef	HAVE_DECL_INT64_MAX
10366458Sdfr# endif
10467032Sdfr# if HAVE_DECL_INT64_MIN
10566458Sdfr#  undef	INT64_MIN
106146791Smarcel#  undef	HAVE_DECL_INT64_MIN
10766458Sdfr# endif
10866458Sdfr#endif
109
110/* Some platforms lack the standard *_MAX definitions. */
111#if !HAVE_DECL_SIZE_MAX
112#define	SIZE_MAX (~(size_t)0)
113#endif
114#if !HAVE_DECL_SSIZE_MAX
115#define	SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1))
116#endif
117#if !HAVE_DECL_UINT32_MAX
118#define	UINT32_MAX (~(uint32_t)0)
119#endif
120#if !HAVE_DECL_INT32_MAX
121#define	INT32_MAX ((int32_t)(UINT32_MAX >> 1))
122#endif
123#if !HAVE_DECL_INT32_MIN
124#define	INT32_MIN ((int32_t)(~INT32_MAX))
125#endif
126#if !HAVE_DECL_UINT64_MAX
127#define	UINT64_MAX (~(uint64_t)0)
128#endif
129#if !HAVE_DECL_INT64_MAX
130#define	INT64_MAX ((int64_t)(UINT64_MAX >> 1))
131#endif
132#if !HAVE_DECL_INT64_MIN
133#define	INT64_MIN ((int64_t)(~INT64_MAX))
134#endif
135#if !HAVE_DECL_UINTMAX_MAX
136#define	UINTMAX_MAX (~(uintmax_t)0)
137#endif
138#if !HAVE_DECL_INTMAX_MAX
139#define	INTMAX_MAX ((intmax_t)(UINTMAX_MAX >> 1))
140#endif
141#if !HAVE_DECL_INTMAX_MIN
142#define	INTMAX_MIN ((intmax_t)(~INTMAX_MAX))
143#endif
144
145/*
146 * If this platform has <sys/acl.h>, acl_create(), acl_init(),
147 * acl_set_file(), and ACL_USER, we assume it has the rest of the
148 * POSIX.1e draft functions used in archive_read_extract.c.
149 */
150#if HAVE_SYS_ACL_H && HAVE_ACL_CREATE_ENTRY && HAVE_ACL_INIT && HAVE_ACL_SET_FILE && HAVE_ACL_USER
151#define	HAVE_POSIX_ACL	1
152#endif
153
154/*
155 * If we can't restore metadata using a file descriptor, then
156 * for compatibility's sake, close files before trying to restore metadata.
157 */
158#if defined(HAVE_FCHMOD) || defined(HAVE_FUTIMES) || defined(HAVE_ACL_SET_FD) || defined(HAVE_ACL_SET_FD_NP) || defined(HAVE_FCHOWN)
159#define	CAN_RESTORE_METADATA_FD
160#endif
161
162/*
163 * glibc 2.24 deprecates readdir_r
164 */
165#if defined(HAVE_READDIR_R) && (!defined(__GLIBC__) || !defined(__GLIBC_MINOR__) || __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 24))
166#define	USE_READDIR_R	1
167#else
168#undef	USE_READDIR_R
169#endif
170
171/* Set up defaults for internal error codes. */
172#ifndef ARCHIVE_ERRNO_FILE_FORMAT
173#if HAVE_EFTYPE
174#define	ARCHIVE_ERRNO_FILE_FORMAT EFTYPE
175#else
176#if HAVE_EILSEQ
177#define	ARCHIVE_ERRNO_FILE_FORMAT EILSEQ
178#else
179#define	ARCHIVE_ERRNO_FILE_FORMAT EINVAL
180#endif
181#endif
182#endif
183
184#ifndef ARCHIVE_ERRNO_PROGRAMMER
185#define	ARCHIVE_ERRNO_PROGRAMMER EINVAL
186#endif
187
188#ifndef ARCHIVE_ERRNO_MISC
189#define	ARCHIVE_ERRNO_MISC (-1)
190#endif
191
192#endif /* !ARCHIVE_PLATFORM_H_INCLUDED */
193