1228753Smm/*- 2228753Smm * Copyright (c) 2003-2007 Tim Kientzle 3228753Smm * All rights reserved. 4228753Smm * 5228753Smm * Redistribution and use in source and binary forms, with or without 6228753Smm * modification, are permitted provided that the following conditions 7228753Smm * are met: 8228753Smm * 1. Redistributions of source code must retain the above copyright 9228753Smm * notice, this list of conditions and the following disclaimer. 10228753Smm * 2. Redistributions in binary form must reproduce the above copyright 11228753Smm * notice, this list of conditions and the following disclaimer in the 12228753Smm * documentation and/or other materials provided with the distribution. 13228753Smm * 14228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24228753Smm * 25229592Smm * $FreeBSD$ 26228753Smm */ 27228753Smm 28228753Smm/* !!ONLY FOR USE INTERNALLY TO LIBARCHIVE!! */ 29228753Smm 30228753Smm/* 31228753Smm * This header is the first thing included in any of the libarchive 32228753Smm * source files. As far as possible, platform-specific issues should 33228753Smm * be dealt with here and not within individual source files. I'm 34228753Smm * actively trying to minimize #if blocks within the main source, 35228753Smm * since they obfuscate the code. 36228753Smm */ 37228753Smm 38228753Smm#ifndef ARCHIVE_PLATFORM_H_INCLUDED 39228753Smm#define ARCHIVE_PLATFORM_H_INCLUDED 40228753Smm 41228753Smm/* archive.h and archive_entry.h require this. */ 42228753Smm#define __LIBARCHIVE_BUILD 1 43228753Smm 44228753Smm#if defined(PLATFORM_CONFIG_H) 45228753Smm/* Use hand-built config.h in environments that need it. */ 46228753Smm#include PLATFORM_CONFIG_H 47228753Smm#elif defined(HAVE_CONFIG_H) 48228753Smm/* Most POSIX platforms use the 'configure' script to build config.h */ 49228753Smm#include "config.h" 50228753Smm#else 51228753Smm/* Warn if the library hasn't been (automatically or manually) configured. */ 52228753Smm#error Oops: No config.h and no pre-built configuration in archive_platform.h. 53228753Smm#endif 54228753Smm 55228753Smm/* It should be possible to get rid of this by extending the feature-test 56228753Smm * macros to cover Windows API functions, probably along with non-trivial 57228753Smm * refactoring of code to find structures that sit more cleanly on top of 58228753Smm * either Windows or Posix APIs. */ 59228753Smm#if (defined(__WIN32__) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__) 60228753Smm#include "archive_windows.h" 61228753Smm#endif 62228753Smm 63228753Smm/* 64228753Smm * The config files define a lot of feature macros. The following 65228753Smm * uses those macros to select/define replacements and include key 66228753Smm * headers as required. 67228753Smm */ 68228753Smm 69228753Smm/* Get a real definition for __FBSDID if we can */ 70228753Smm#if HAVE_SYS_CDEFS_H 71228753Smm#include <sys/cdefs.h> 72228753Smm#endif 73228753Smm 74228753Smm/* If not, define it so as to avoid dangling semicolons. */ 75228753Smm#ifndef __FBSDID 76228753Smm#define __FBSDID(a) struct _undefined_hack 77228753Smm#endif 78228753Smm 79228753Smm/* Try to get standard C99-style integer type definitions. */ 80228753Smm#if HAVE_INTTYPES_H 81228753Smm#include <inttypes.h> 82228753Smm#endif 83228753Smm#if HAVE_STDINT_H 84228753Smm#include <stdint.h> 85228753Smm#endif 86228753Smm 87228753Smm/* Borland warns about its own constants! */ 88228753Smm#if defined(__BORLANDC__) 89228753Smm# if HAVE_DECL_UINT64_MAX 90228753Smm# undef UINT64_MAX 91228753Smm# undef HAVE_DECL_UINT64_MAX 92228753Smm# endif 93228753Smm# if HAVE_DECL_UINT64_MIN 94228753Smm# undef UINT64_MIN 95228753Smm# undef HAVE_DECL_UINT64_MIN 96228753Smm# endif 97228753Smm# if HAVE_DECL_INT64_MAX 98228753Smm# undef INT64_MAX 99228753Smm# undef HAVE_DECL_INT64_MAX 100228753Smm# endif 101228753Smm# if HAVE_DECL_INT64_MIN 102228753Smm# undef INT64_MIN 103228753Smm# undef HAVE_DECL_INT64_MIN 104228753Smm# endif 105228753Smm#endif 106228753Smm 107228753Smm/* Some platforms lack the standard *_MAX definitions. */ 108228753Smm#if !HAVE_DECL_SIZE_MAX 109228753Smm#define SIZE_MAX (~(size_t)0) 110228753Smm#endif 111228753Smm#if !HAVE_DECL_SSIZE_MAX 112228753Smm#define SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1)) 113228753Smm#endif 114228753Smm#if !HAVE_DECL_UINT32_MAX 115228753Smm#define UINT32_MAX (~(uint32_t)0) 116228753Smm#endif 117228753Smm#if !HAVE_DECL_UINT64_MAX 118228753Smm#define UINT64_MAX (~(uint64_t)0) 119228753Smm#endif 120228753Smm#if !HAVE_DECL_INT64_MAX 121228753Smm#define INT64_MAX ((int64_t)(UINT64_MAX >> 1)) 122228753Smm#endif 123228753Smm#if !HAVE_DECL_INT64_MIN 124228753Smm#define INT64_MIN ((int64_t)(~INT64_MAX)) 125228753Smm#endif 126228753Smm 127228753Smm/* 128228753Smm * If this platform has <sys/acl.h>, acl_create(), acl_init(), 129228753Smm * acl_set_file(), and ACL_USER, we assume it has the rest of the 130228753Smm * POSIX.1e draft functions used in archive_read_extract.c. 131228753Smm */ 132228753Smm#if HAVE_SYS_ACL_H && HAVE_ACL_CREATE_ENTRY && HAVE_ACL_INIT && HAVE_ACL_SET_FILE && HAVE_ACL_USER 133228753Smm#define HAVE_POSIX_ACL 1 134228753Smm#endif 135228753Smm 136228753Smm/* 137228753Smm * If we can't restore metadata using a file descriptor, then 138228753Smm * for compatibility's sake, close files before trying to restore metadata. 139228753Smm */ 140228753Smm#if defined(HAVE_FCHMOD) || defined(HAVE_FUTIMES) || defined(HAVE_ACL_SET_FD) || defined(HAVE_ACL_SET_FD_NP) || defined(HAVE_FCHOWN) 141228753Smm#define CAN_RESTORE_METADATA_FD 142228753Smm#endif 143228753Smm 144228753Smm/* Set up defaults for internal error codes. */ 145228753Smm#ifndef ARCHIVE_ERRNO_FILE_FORMAT 146228753Smm#if HAVE_EFTYPE 147228753Smm#define ARCHIVE_ERRNO_FILE_FORMAT EFTYPE 148228753Smm#else 149228753Smm#if HAVE_EILSEQ 150228753Smm#define ARCHIVE_ERRNO_FILE_FORMAT EILSEQ 151228753Smm#else 152228753Smm#define ARCHIVE_ERRNO_FILE_FORMAT EINVAL 153228753Smm#endif 154228753Smm#endif 155228753Smm#endif 156228753Smm 157228753Smm#ifndef ARCHIVE_ERRNO_PROGRAMMER 158228753Smm#define ARCHIVE_ERRNO_PROGRAMMER EINVAL 159228753Smm#endif 160228753Smm 161228753Smm#ifndef ARCHIVE_ERRNO_MISC 162228753Smm#define ARCHIVE_ERRNO_MISC (-1) 163228753Smm#endif 164228753Smm 165228753Smm#endif /* !ARCHIVE_PLATFORM_H_INCLUDED */ 166