bsdtar_platform.h revision 228759
1168404Spjd/*- 2168404Spjd * Copyright (c) 2003-2007 Tim Kientzle 3168404Spjd * All rights reserved. 4168404Spjd * 5168404Spjd * Redistribution and use in source and binary forms, with or without 6168404Spjd * modification, are permitted provided that the following conditions 7168404Spjd * are met: 8168404Spjd * 1. Redistributions of source code must retain the above copyright 9168404Spjd * notice, this list of conditions and the following disclaimer. 10168404Spjd * 2. Redistributions in binary form must reproduce the above copyright 11168404Spjd * notice, this list of conditions and the following disclaimer in the 12168404Spjd * documentation and/or other materials provided with the distribution. 13168404Spjd * 14168404Spjd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15168404Spjd * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16168404Spjd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17168404Spjd * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18168404Spjd * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19168404Spjd * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20168404Spjd * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21168404Spjd * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22168404Spjd * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23168404Spjd * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24168404Spjd * 25168404Spjd * $FreeBSD: src/usr.bin/tar/bsdtar_platform.h,v 1.26 2008/12/06 07:37:14 kientzle Exp $ 26168404Spjd */ 27168404Spjd 28168404Spjd/* 29168404Spjd * This header is the first thing included in any of the bsdtar 30168404Spjd * source files. As far as possible, platform-specific issues should 31168404Spjd * be dealt with here and not within individual source files. 32168404Spjd */ 33168508Spjd 34168404Spjd#ifndef BSDTAR_PLATFORM_H_INCLUDED 35168404Spjd#define BSDTAR_PLATFORM_H_INCLUDED 36168404Spjd 37168404Spjd#if defined(PLATFORM_CONFIG_H) 38168404Spjd/* Use hand-built config.h in environments that need it. */ 39168508Spjd#include PLATFORM_CONFIG_H 40168404Spjd#else 41168404Spjd/* Not having a config.h of some sort is a serious problem. */ 42168404Spjd#include "config.h" 43168404Spjd#endif 44168404Spjd 45168404Spjd/* Get a real definition for __FBSDID if we can */ 46168404Spjd#if HAVE_SYS_CDEFS_H 47168404Spjd#include <sys/cdefs.h> 48168404Spjd#endif 49168404Spjd 50168404Spjd/* If not, define it so as to avoid dangling semicolons. */ 51168404Spjd#ifndef __FBSDID 52168404Spjd#define __FBSDID(a) struct _undefined_hack 53168404Spjd#endif 54168404Spjd 55168404Spjd#ifdef HAVE_LIBARCHIVE 56168404Spjd/* If we're using the platform libarchive, include system headers. */ 57168404Spjd#include <archive.h> 58168404Spjd#include <archive_entry.h> 59168404Spjd#else 60168404Spjd/* Otherwise, include user headers. */ 61168404Spjd#include "archive.h" 62168404Spjd#include "archive_entry.h" 63168404Spjd#endif 64168404Spjd 65168404Spjd#ifdef HAVE_LIBACL 66168508Spjd#include <acl/libacl.h> 67168508Spjd#endif 68168404Spjd 69168404Spjd/* 70185319Spjd * Include "dirent.h" (or it's equivalent on several different platforms). 71168404Spjd * 72196966Skib * This is slightly modified from the GNU autoconf recipe. 73168404Spjd * In particular, FreeBSD includes d_namlen in it's dirent structure, 74185319Spjd * so my configure script includes an explicit test for the d_namlen 75185319Spjd * field. 76185319Spjd */ 77185319Spjd#if HAVE_DIRENT_H 78185319Spjd# include <dirent.h> 79185319Spjd# if HAVE_DIRENT_D_NAMLEN 80185319Spjd# define DIRENT_NAMLEN(dirent) (dirent)->d_namlen 81185319Spjd# else 82185319Spjd# define DIRENT_NAMLEN(dirent) strlen((dirent)->d_name) 83185319Spjd# endif 84185319Spjd#else 85168404Spjd# define dirent direct 86194617Skib# define DIRENT_NAMLEN(dirent) (dirent)->d_namlen 87185319Spjd# if HAVE_SYS_NDIR_H 88194617Skib# include <sys/ndir.h> 89168404Spjd# endif 90168508Spjd# if HAVE_SYS_DIR_H 91196966Skib# include <sys/dir.h> 92196966Skib# endif 93168404Spjd# if HAVE_NDIR_H 94175294Sattilio# include <ndir.h> 95196966Skib# endif 96168508Spjd#endif 97168404Spjd 98168404Spjd#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 99168508Spjd#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctimespec.tv_nsec 100168508Spjd#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtimespec.tv_nsec 101168404Spjd#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 102168508Spjd#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctim.tv_nsec 103168508Spjd#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtim.tv_nsec 104168508Spjd#elif HAVE_STRUCT_STAT_ST_MTIME_N 105168508Spjd#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctime_n 106168508Spjd#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtime_n 107168508Spjd#elif HAVE_STRUCT_STAT_ST_UMTIME 108168508Spjd#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_uctime * 1000 109168508Spjd#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_umtime * 1000 110168508Spjd#elif HAVE_STRUCT_STAT_ST_MTIME_USEC 111168508Spjd#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctime_usec * 1000 112168508Spjd#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtime_usec * 1000 113168508Spjd#else 114168508Spjd#define ARCHIVE_STAT_CTIME_NANOS(st) (0) 115168508Spjd#define ARCHIVE_STAT_MTIME_NANOS(st) (0) 116168508Spjd#endif 117168508Spjd 118168508Spjd/* How to mark functions that don't return. */ 119168508Spjd/* This facilitates use of some newer static code analysis tools. */ 120168508Spjd#undef __LA_DEAD 121168508Spjd#if defined(__GNUC__) && (__GNUC__ > 2 || \ 122168508Spjd (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) 123168508Spjd#define __LA_DEAD __attribute__((__noreturn__)) 124168508Spjd#else 125168508Spjd#define __LA_DEAD 126168508Spjd#endif 127168508Spjd 128168508Spjd#if defined(_WIN32) && !defined(__CYGWIN__) 129168508Spjd#include "bsdtar_windows.h" 130168508Spjd#endif 131168508Spjd 132168404Spjd#endif /* !BSDTAR_PLATFORM_H_INCLUDED */ 133185319Spjd