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
45228753Smm/* Get a real definition for __FBSDID if we can */
46228753Smm#if HAVE_SYS_CDEFS_H
47228753Smm#include <sys/cdefs.h>
48228753Smm#endif
49228753Smm
50228753Smm/* If not, define it so as to avoid dangling semicolons. */
51228753Smm#ifndef __FBSDID
52228753Smm#define	__FBSDID(a)     struct _undefined_hack
53228753Smm#endif
54228753Smm
55228753Smm#ifdef HAVE_LIBARCHIVE
56228753Smm/* If we're using the platform libarchive, include system headers. */
57228753Smm#include <archive.h>
58228753Smm#include <archive_entry.h>
59228753Smm#else
60228753Smm/* Otherwise, include user headers. */
61228753Smm#include "archive.h"
62228753Smm#include "archive_entry.h"
63228753Smm#endif
64228753Smm
65228753Smm#ifdef HAVE_LIBACL
66228753Smm#include <acl/libacl.h>
67228753Smm#endif
68228753Smm
69228753Smm/*
70232153Smm * Include "dirent.h" (or its equivalent on several different platforms).
71228753Smm *
72228753Smm * This is slightly modified from the GNU autoconf recipe.
73232153Smm * In particular, FreeBSD includes d_namlen in its dirent structure,
74228753Smm * so my configure script includes an explicit test for the d_namlen
75228753Smm * field.
76228753Smm */
77228753Smm#if HAVE_DIRENT_H
78228753Smm# include <dirent.h>
79228753Smm# if HAVE_DIRENT_D_NAMLEN
80228753Smm#  define DIRENT_NAMLEN(dirent) (dirent)->d_namlen
81228753Smm# else
82228753Smm#  define DIRENT_NAMLEN(dirent) strlen((dirent)->d_name)
83228753Smm# endif
84228753Smm#else
85228753Smm# define dirent direct
86228753Smm# define DIRENT_NAMLEN(dirent) (dirent)->d_namlen
87228753Smm# if HAVE_SYS_NDIR_H
88228753Smm#  include <sys/ndir.h>
89228753Smm# endif
90228753Smm# if HAVE_SYS_DIR_H
91228753Smm#  include <sys/dir.h>
92228753Smm# endif
93228753Smm# if HAVE_NDIR_H
94228753Smm#  include <ndir.h>
95228753Smm# endif
96228753Smm#endif
97228753Smm
98228753Smm#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
99228753Smm#define	ARCHIVE_STAT_CTIME_NANOS(st)	(st)->st_ctimespec.tv_nsec
100228753Smm#define	ARCHIVE_STAT_MTIME_NANOS(st)	(st)->st_mtimespec.tv_nsec
101228753Smm#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
102228753Smm#define	ARCHIVE_STAT_CTIME_NANOS(st)	(st)->st_ctim.tv_nsec
103228753Smm#define	ARCHIVE_STAT_MTIME_NANOS(st)	(st)->st_mtim.tv_nsec
104228753Smm#elif HAVE_STRUCT_STAT_ST_MTIME_N
105228753Smm#define	ARCHIVE_STAT_CTIME_NANOS(st)	(st)->st_ctime_n
106228753Smm#define	ARCHIVE_STAT_MTIME_NANOS(st)	(st)->st_mtime_n
107228753Smm#elif HAVE_STRUCT_STAT_ST_UMTIME
108228753Smm#define	ARCHIVE_STAT_CTIME_NANOS(st)	(st)->st_uctime * 1000
109228753Smm#define	ARCHIVE_STAT_MTIME_NANOS(st)	(st)->st_umtime * 1000
110228753Smm#elif HAVE_STRUCT_STAT_ST_MTIME_USEC
111228753Smm#define	ARCHIVE_STAT_CTIME_NANOS(st)	(st)->st_ctime_usec * 1000
112228753Smm#define	ARCHIVE_STAT_MTIME_NANOS(st)	(st)->st_mtime_usec * 1000
113228753Smm#else
114228753Smm#define	ARCHIVE_STAT_CTIME_NANOS(st)	(0)
115228753Smm#define	ARCHIVE_STAT_MTIME_NANOS(st)	(0)
116228753Smm#endif
117228753Smm
118228753Smm/* How to mark functions that don't return. */
119228753Smm/* This facilitates use of some newer static code analysis tools. */
120228753Smm#undef __LA_DEAD
121228753Smm#if defined(__GNUC__) && (__GNUC__ > 2 || \
122228753Smm			  (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
123228753Smm#define	__LA_DEAD	__attribute__((__noreturn__))
124228753Smm#else
125228753Smm#define	__LA_DEAD
126228753Smm#endif
127228753Smm
128228753Smm#if defined(_WIN32) && !defined(__CYGWIN__)
129228753Smm#include "bsdtar_windows.h"
130228753Smm#endif
131228753Smm
132228753Smm#endif /* !BSDTAR_PLATFORM_H_INCLUDED */
133