160b4ad09SPeter Avalos /*- 260b4ad09SPeter Avalos * Copyright (c) 2003-2007 Tim Kientzle 360b4ad09SPeter Avalos * All rights reserved. 460b4ad09SPeter Avalos * 560b4ad09SPeter Avalos * Redistribution and use in source and binary forms, with or without 660b4ad09SPeter Avalos * modification, are permitted provided that the following conditions 760b4ad09SPeter Avalos * are met: 860b4ad09SPeter Avalos * 1. Redistributions of source code must retain the above copyright 960b4ad09SPeter Avalos * notice, this list of conditions and the following disclaimer. 1060b4ad09SPeter Avalos * 2. Redistributions in binary form must reproduce the above copyright 1160b4ad09SPeter Avalos * notice, this list of conditions and the following disclaimer in the 1260b4ad09SPeter Avalos * documentation and/or other materials provided with the distribution. 1360b4ad09SPeter Avalos * 1460b4ad09SPeter Avalos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 1560b4ad09SPeter Avalos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1660b4ad09SPeter Avalos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1760b4ad09SPeter Avalos * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 1860b4ad09SPeter Avalos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1960b4ad09SPeter Avalos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2060b4ad09SPeter Avalos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2160b4ad09SPeter Avalos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2260b4ad09SPeter Avalos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2360b4ad09SPeter Avalos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2460b4ad09SPeter Avalos * 258029ab02SPeter Avalos * $FreeBSD: src/usr.bin/tar/bsdtar_platform.h,v 1.26 2008/12/06 07:37:14 kientzle Exp $ 2660b4ad09SPeter Avalos */ 2760b4ad09SPeter Avalos 2860b4ad09SPeter Avalos /* 2960b4ad09SPeter Avalos * This header is the first thing included in any of the bsdtar 3060b4ad09SPeter Avalos * source files. As far as possible, platform-specific issues should 3160b4ad09SPeter Avalos * be dealt with here and not within individual source files. 3260b4ad09SPeter Avalos */ 3360b4ad09SPeter Avalos 3460b4ad09SPeter Avalos #ifndef BSDTAR_PLATFORM_H_INCLUDED 3560b4ad09SPeter Avalos #define BSDTAR_PLATFORM_H_INCLUDED 3660b4ad09SPeter Avalos 3760b4ad09SPeter Avalos #if defined(PLATFORM_CONFIG_H) 3860b4ad09SPeter Avalos /* Use hand-built config.h in environments that need it. */ 3960b4ad09SPeter Avalos #include PLATFORM_CONFIG_H 409c82a63eSPeter Avalos #else 419c82a63eSPeter Avalos /* Not having a config.h of some sort is a serious problem. */ 428029ab02SPeter Avalos #include "config.h" 439c82a63eSPeter Avalos #endif 4460b4ad09SPeter Avalos 45*6b384f39SPeter Avalos #if defined(_WIN32) && !defined(__CYGWIN__) 46*6b384f39SPeter Avalos #include "bsdtar_windows.h" 47*6b384f39SPeter Avalos #endif 48*6b384f39SPeter Avalos 499c82a63eSPeter Avalos /* Get a real definition for __FBSDID if we can */ 509c82a63eSPeter Avalos #if HAVE_SYS_CDEFS_H 519c82a63eSPeter Avalos #include <sys/cdefs.h> 529c82a63eSPeter Avalos #endif 539c82a63eSPeter Avalos 549c82a63eSPeter Avalos /* If not, define it so as to avoid dangling semicolons. */ 559c82a63eSPeter Avalos #ifndef __FBSDID 5660b4ad09SPeter Avalos #define __FBSDID(a) struct _undefined_hack 5760b4ad09SPeter Avalos #endif 5860b4ad09SPeter Avalos 5960b4ad09SPeter Avalos #ifdef HAVE_LIBARCHIVE 6060b4ad09SPeter Avalos /* If we're using the platform libarchive, include system headers. */ 6160b4ad09SPeter Avalos #include <archive.h> 6260b4ad09SPeter Avalos #include <archive_entry.h> 6360b4ad09SPeter Avalos #else 6460b4ad09SPeter Avalos /* Otherwise, include user headers. */ 6560b4ad09SPeter Avalos #include "archive.h" 6660b4ad09SPeter Avalos #include "archive_entry.h" 6760b4ad09SPeter Avalos #endif 6860b4ad09SPeter Avalos 6960b4ad09SPeter Avalos #ifdef HAVE_LIBACL 7060b4ad09SPeter Avalos #include <acl/libacl.h> 7160b4ad09SPeter Avalos #endif 7260b4ad09SPeter Avalos 7360b4ad09SPeter Avalos /* 74c09f92d2SPeter Avalos * Include "dirent.h" (or its equivalent on several different platforms). 7560b4ad09SPeter Avalos * 7660b4ad09SPeter Avalos * This is slightly modified from the GNU autoconf recipe. 77c09f92d2SPeter Avalos * In particular, FreeBSD includes d_namlen in its dirent structure, 7860b4ad09SPeter Avalos * so my configure script includes an explicit test for the d_namlen 7960b4ad09SPeter Avalos * field. 8060b4ad09SPeter Avalos */ 8160b4ad09SPeter Avalos #if HAVE_DIRENT_H 8260b4ad09SPeter Avalos # include <dirent.h> 8360b4ad09SPeter Avalos # if HAVE_DIRENT_D_NAMLEN 8460b4ad09SPeter Avalos # define DIRENT_NAMLEN(dirent) (dirent)->d_namlen 8560b4ad09SPeter Avalos # else 8660b4ad09SPeter Avalos # define DIRENT_NAMLEN(dirent) strlen((dirent)->d_name) 8760b4ad09SPeter Avalos # endif 8860b4ad09SPeter Avalos #else 8960b4ad09SPeter Avalos # define dirent direct 9060b4ad09SPeter Avalos # define DIRENT_NAMLEN(dirent) (dirent)->d_namlen 9160b4ad09SPeter Avalos # if HAVE_SYS_NDIR_H 9260b4ad09SPeter Avalos # include <sys/ndir.h> 9360b4ad09SPeter Avalos # endif 9460b4ad09SPeter Avalos # if HAVE_SYS_DIR_H 9560b4ad09SPeter Avalos # include <sys/dir.h> 9660b4ad09SPeter Avalos # endif 9760b4ad09SPeter Avalos # if HAVE_NDIR_H 9860b4ad09SPeter Avalos # include <ndir.h> 9960b4ad09SPeter Avalos # endif 10060b4ad09SPeter Avalos #endif 10160b4ad09SPeter Avalos 10260b4ad09SPeter Avalos #if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 10360b4ad09SPeter Avalos #define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctimespec.tv_nsec 10460b4ad09SPeter Avalos #define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtimespec.tv_nsec 1058029ab02SPeter Avalos #elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 10660b4ad09SPeter Avalos #define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctim.tv_nsec 10760b4ad09SPeter Avalos #define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtim.tv_nsec 1088029ab02SPeter Avalos #elif HAVE_STRUCT_STAT_ST_MTIME_N 1098029ab02SPeter Avalos #define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctime_n 1108029ab02SPeter Avalos #define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtime_n 1118029ab02SPeter Avalos #elif HAVE_STRUCT_STAT_ST_UMTIME 1128029ab02SPeter Avalos #define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_uctime * 1000 1138029ab02SPeter Avalos #define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_umtime * 1000 1148029ab02SPeter Avalos #elif HAVE_STRUCT_STAT_ST_MTIME_USEC 1158029ab02SPeter Avalos #define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctime_usec * 1000 1168029ab02SPeter Avalos #define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtime_usec * 1000 11760b4ad09SPeter Avalos #else 11860b4ad09SPeter Avalos #define ARCHIVE_STAT_CTIME_NANOS(st) (0) 11960b4ad09SPeter Avalos #define ARCHIVE_STAT_MTIME_NANOS(st) (0) 12060b4ad09SPeter Avalos #endif 1218029ab02SPeter Avalos 1228029ab02SPeter Avalos /* How to mark functions that don't return. */ 1238029ab02SPeter Avalos /* This facilitates use of some newer static code analysis tools. */ 1248029ab02SPeter Avalos #undef __LA_DEAD 1258029ab02SPeter Avalos #if defined(__GNUC__) && (__GNUC__ > 2 || \ 1268029ab02SPeter Avalos (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) 1278029ab02SPeter Avalos #define __LA_DEAD __attribute__((__noreturn__)) 1288029ab02SPeter Avalos #else 1298029ab02SPeter Avalos #define __LA_DEAD 1308029ab02SPeter Avalos #endif 1318029ab02SPeter Avalos 13260b4ad09SPeter Avalos #endif /* !BSDTAR_PLATFORM_H_INCLUDED */ 133