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 * 25228763Smm * $FreeBSD$ 26228753Smm */ 27228753Smm 28228753Smm/* 29228753Smm * This header is the first thing included in any of the bsdtar 30228753Smm * source files. As far as possible, platform-specific issues should 31228753Smm * be dealt with here and not within individual source files. 32228753Smm */ 33228753Smm 34228753Smm#ifndef BSDTAR_PLATFORM_H_INCLUDED 35228753Smm#define BSDTAR_PLATFORM_H_INCLUDED 36228753Smm 37228753Smm#if defined(PLATFORM_CONFIG_H) 38228753Smm/* Use hand-built config.h in environments that need it. */ 39228753Smm#include PLATFORM_CONFIG_H 40228753Smm#else 41228753Smm/* Not having a config.h of some sort is a serious problem. */ 42228753Smm#include "config.h" 43228753Smm#endif 44228753Smm 45302001Smm#if defined(_WIN32) && !defined(__CYGWIN__) 46302001Smm#include "bsdtar_windows.h" 47302001Smm#endif 48302001Smm 49228753Smm/* Get a real definition for __FBSDID if we can */ 50228753Smm#if HAVE_SYS_CDEFS_H 51228753Smm#include <sys/cdefs.h> 52228753Smm#endif 53228753Smm 54228753Smm/* If not, define it so as to avoid dangling semicolons. */ 55228753Smm#ifndef __FBSDID 56228753Smm#define __FBSDID(a) struct _undefined_hack 57228753Smm#endif 58228753Smm 59228753Smm#ifdef HAVE_LIBARCHIVE 60228753Smm/* If we're using the platform libarchive, include system headers. */ 61228753Smm#include <archive.h> 62228753Smm#include <archive_entry.h> 63228753Smm#else 64228753Smm/* Otherwise, include user headers. */ 65228753Smm#include "archive.h" 66228753Smm#include "archive_entry.h" 67228753Smm#endif 68228753Smm 69228753Smm#ifdef HAVE_LIBACL 70228753Smm#include <acl/libacl.h> 71228753Smm#endif 72228753Smm 73228753Smm/* 74232153Smm * Include "dirent.h" (or its equivalent on several different platforms). 75228753Smm * 76228753Smm * This is slightly modified from the GNU autoconf recipe. 77232153Smm * In particular, FreeBSD includes d_namlen in its dirent structure, 78228753Smm * so my configure script includes an explicit test for the d_namlen 79228753Smm * field. 80228753Smm */ 81228753Smm#if HAVE_DIRENT_H 82228753Smm# include <dirent.h> 83228753Smm# if HAVE_DIRENT_D_NAMLEN 84228753Smm# define DIRENT_NAMLEN(dirent) (dirent)->d_namlen 85228753Smm# else 86228753Smm# define DIRENT_NAMLEN(dirent) strlen((dirent)->d_name) 87228753Smm# endif 88228753Smm#else 89228753Smm# define dirent direct 90228753Smm# define DIRENT_NAMLEN(dirent) (dirent)->d_namlen 91228753Smm# if HAVE_SYS_NDIR_H 92228753Smm# include <sys/ndir.h> 93228753Smm# endif 94228753Smm# if HAVE_SYS_DIR_H 95228753Smm# include <sys/dir.h> 96228753Smm# endif 97228753Smm# if HAVE_NDIR_H 98228753Smm# include <ndir.h> 99228753Smm# endif 100228753Smm#endif 101228753Smm 102228753Smm#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 103228753Smm#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctimespec.tv_nsec 104228753Smm#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtimespec.tv_nsec 105228753Smm#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 106228753Smm#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctim.tv_nsec 107228753Smm#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtim.tv_nsec 108228753Smm#elif HAVE_STRUCT_STAT_ST_MTIME_N 109228753Smm#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctime_n 110228753Smm#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtime_n 111228753Smm#elif HAVE_STRUCT_STAT_ST_UMTIME 112228753Smm#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_uctime * 1000 113228753Smm#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_umtime * 1000 114228753Smm#elif HAVE_STRUCT_STAT_ST_MTIME_USEC 115228753Smm#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctime_usec * 1000 116228753Smm#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtime_usec * 1000 117228753Smm#else 118228753Smm#define ARCHIVE_STAT_CTIME_NANOS(st) (0) 119228753Smm#define ARCHIVE_STAT_MTIME_NANOS(st) (0) 120228753Smm#endif 121228753Smm 122228753Smm/* How to mark functions that don't return. */ 123228753Smm/* This facilitates use of some newer static code analysis tools. */ 124228753Smm#undef __LA_DEAD 125228753Smm#if defined(__GNUC__) && (__GNUC__ > 2 || \ 126228753Smm (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) 127228753Smm#define __LA_DEAD __attribute__((__noreturn__)) 128228753Smm#else 129228753Smm#define __LA_DEAD 130228753Smm#endif 131228753Smm 132228753Smm#endif /* !BSDTAR_PLATFORM_H_INCLUDED */ 133