xref: /freebsd/contrib/libarchive/tar/bsdtar_platform.h (revision caf54c4f6ce7f1612a528170c1aa3c3fe4f8b153)
1*caf54c4fSMartin Matuska /*-
2*caf54c4fSMartin Matuska  * Copyright (c) 2003-2007 Tim Kientzle
3*caf54c4fSMartin Matuska  * All rights reserved.
4*caf54c4fSMartin Matuska  *
5*caf54c4fSMartin Matuska  * Redistribution and use in source and binary forms, with or without
6*caf54c4fSMartin Matuska  * modification, are permitted provided that the following conditions
7*caf54c4fSMartin Matuska  * are met:
8*caf54c4fSMartin Matuska  * 1. Redistributions of source code must retain the above copyright
9*caf54c4fSMartin Matuska  *    notice, this list of conditions and the following disclaimer.
10*caf54c4fSMartin Matuska  * 2. Redistributions in binary form must reproduce the above copyright
11*caf54c4fSMartin Matuska  *    notice, this list of conditions and the following disclaimer in the
12*caf54c4fSMartin Matuska  *    documentation and/or other materials provided with the distribution.
13*caf54c4fSMartin Matuska  *
14*caf54c4fSMartin Matuska  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15*caf54c4fSMartin Matuska  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16*caf54c4fSMartin Matuska  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17*caf54c4fSMartin Matuska  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18*caf54c4fSMartin Matuska  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19*caf54c4fSMartin Matuska  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20*caf54c4fSMartin Matuska  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21*caf54c4fSMartin Matuska  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22*caf54c4fSMartin Matuska  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23*caf54c4fSMartin Matuska  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*caf54c4fSMartin Matuska  *
25*caf54c4fSMartin Matuska  * $FreeBSD: src/usr.bin/tar/bsdtar_platform.h,v 1.26 2008/12/06 07:37:14 kientzle Exp $
26*caf54c4fSMartin Matuska  */
27*caf54c4fSMartin Matuska 
28*caf54c4fSMartin Matuska /*
29*caf54c4fSMartin Matuska  * This header is the first thing included in any of the bsdtar
30*caf54c4fSMartin Matuska  * source files.  As far as possible, platform-specific issues should
31*caf54c4fSMartin Matuska  * be dealt with here and not within individual source files.
32*caf54c4fSMartin Matuska  */
33*caf54c4fSMartin Matuska 
34*caf54c4fSMartin Matuska #ifndef BSDTAR_PLATFORM_H_INCLUDED
35*caf54c4fSMartin Matuska #define	BSDTAR_PLATFORM_H_INCLUDED
36*caf54c4fSMartin Matuska 
37*caf54c4fSMartin Matuska #if defined(PLATFORM_CONFIG_H)
38*caf54c4fSMartin Matuska /* Use hand-built config.h in environments that need it. */
39*caf54c4fSMartin Matuska #include PLATFORM_CONFIG_H
40*caf54c4fSMartin Matuska #else
41*caf54c4fSMartin Matuska /* Not having a config.h of some sort is a serious problem. */
42*caf54c4fSMartin Matuska #include "config.h"
43*caf54c4fSMartin Matuska #endif
44*caf54c4fSMartin Matuska 
45*caf54c4fSMartin Matuska /* Get a real definition for __FBSDID if we can */
46*caf54c4fSMartin Matuska #if HAVE_SYS_CDEFS_H
47*caf54c4fSMartin Matuska #include <sys/cdefs.h>
48*caf54c4fSMartin Matuska #endif
49*caf54c4fSMartin Matuska 
50*caf54c4fSMartin Matuska /* If not, define it so as to avoid dangling semicolons. */
51*caf54c4fSMartin Matuska #ifndef __FBSDID
52*caf54c4fSMartin Matuska #define	__FBSDID(a)     struct _undefined_hack
53*caf54c4fSMartin Matuska #endif
54*caf54c4fSMartin Matuska 
55*caf54c4fSMartin Matuska #ifdef HAVE_LIBARCHIVE
56*caf54c4fSMartin Matuska /* If we're using the platform libarchive, include system headers. */
57*caf54c4fSMartin Matuska #include <archive.h>
58*caf54c4fSMartin Matuska #include <archive_entry.h>
59*caf54c4fSMartin Matuska #else
60*caf54c4fSMartin Matuska /* Otherwise, include user headers. */
61*caf54c4fSMartin Matuska #include "archive.h"
62*caf54c4fSMartin Matuska #include "archive_entry.h"
63*caf54c4fSMartin Matuska #endif
64*caf54c4fSMartin Matuska 
65*caf54c4fSMartin Matuska #ifdef HAVE_LIBACL
66*caf54c4fSMartin Matuska #include <acl/libacl.h>
67*caf54c4fSMartin Matuska #endif
68*caf54c4fSMartin Matuska 
69*caf54c4fSMartin Matuska /*
70*caf54c4fSMartin Matuska  * Include "dirent.h" (or it's equivalent on several different platforms).
71*caf54c4fSMartin Matuska  *
72*caf54c4fSMartin Matuska  * This is slightly modified from the GNU autoconf recipe.
73*caf54c4fSMartin Matuska  * In particular, FreeBSD includes d_namlen in it's dirent structure,
74*caf54c4fSMartin Matuska  * so my configure script includes an explicit test for the d_namlen
75*caf54c4fSMartin Matuska  * field.
76*caf54c4fSMartin Matuska  */
77*caf54c4fSMartin Matuska #if HAVE_DIRENT_H
78*caf54c4fSMartin Matuska # include <dirent.h>
79*caf54c4fSMartin Matuska # if HAVE_DIRENT_D_NAMLEN
80*caf54c4fSMartin Matuska #  define DIRENT_NAMLEN(dirent) (dirent)->d_namlen
81*caf54c4fSMartin Matuska # else
82*caf54c4fSMartin Matuska #  define DIRENT_NAMLEN(dirent) strlen((dirent)->d_name)
83*caf54c4fSMartin Matuska # endif
84*caf54c4fSMartin Matuska #else
85*caf54c4fSMartin Matuska # define dirent direct
86*caf54c4fSMartin Matuska # define DIRENT_NAMLEN(dirent) (dirent)->d_namlen
87*caf54c4fSMartin Matuska # if HAVE_SYS_NDIR_H
88*caf54c4fSMartin Matuska #  include <sys/ndir.h>
89*caf54c4fSMartin Matuska # endif
90*caf54c4fSMartin Matuska # if HAVE_SYS_DIR_H
91*caf54c4fSMartin Matuska #  include <sys/dir.h>
92*caf54c4fSMartin Matuska # endif
93*caf54c4fSMartin Matuska # if HAVE_NDIR_H
94*caf54c4fSMartin Matuska #  include <ndir.h>
95*caf54c4fSMartin Matuska # endif
96*caf54c4fSMartin Matuska #endif
97*caf54c4fSMartin Matuska 
98*caf54c4fSMartin Matuska #if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
99*caf54c4fSMartin Matuska #define	ARCHIVE_STAT_CTIME_NANOS(st)	(st)->st_ctimespec.tv_nsec
100*caf54c4fSMartin Matuska #define	ARCHIVE_STAT_MTIME_NANOS(st)	(st)->st_mtimespec.tv_nsec
101*caf54c4fSMartin Matuska #elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
102*caf54c4fSMartin Matuska #define	ARCHIVE_STAT_CTIME_NANOS(st)	(st)->st_ctim.tv_nsec
103*caf54c4fSMartin Matuska #define	ARCHIVE_STAT_MTIME_NANOS(st)	(st)->st_mtim.tv_nsec
104*caf54c4fSMartin Matuska #elif HAVE_STRUCT_STAT_ST_MTIME_N
105*caf54c4fSMartin Matuska #define	ARCHIVE_STAT_CTIME_NANOS(st)	(st)->st_ctime_n
106*caf54c4fSMartin Matuska #define	ARCHIVE_STAT_MTIME_NANOS(st)	(st)->st_mtime_n
107*caf54c4fSMartin Matuska #elif HAVE_STRUCT_STAT_ST_UMTIME
108*caf54c4fSMartin Matuska #define	ARCHIVE_STAT_CTIME_NANOS(st)	(st)->st_uctime * 1000
109*caf54c4fSMartin Matuska #define	ARCHIVE_STAT_MTIME_NANOS(st)	(st)->st_umtime * 1000
110*caf54c4fSMartin Matuska #elif HAVE_STRUCT_STAT_ST_MTIME_USEC
111*caf54c4fSMartin Matuska #define	ARCHIVE_STAT_CTIME_NANOS(st)	(st)->st_ctime_usec * 1000
112*caf54c4fSMartin Matuska #define	ARCHIVE_STAT_MTIME_NANOS(st)	(st)->st_mtime_usec * 1000
113*caf54c4fSMartin Matuska #else
114*caf54c4fSMartin Matuska #define	ARCHIVE_STAT_CTIME_NANOS(st)	(0)
115*caf54c4fSMartin Matuska #define	ARCHIVE_STAT_MTIME_NANOS(st)	(0)
116*caf54c4fSMartin Matuska #endif
117*caf54c4fSMartin Matuska 
118*caf54c4fSMartin Matuska /* How to mark functions that don't return. */
119*caf54c4fSMartin Matuska /* This facilitates use of some newer static code analysis tools. */
120*caf54c4fSMartin Matuska #undef __LA_DEAD
121*caf54c4fSMartin Matuska #if defined(__GNUC__) && (__GNUC__ > 2 || \
122*caf54c4fSMartin Matuska 			  (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
123*caf54c4fSMartin Matuska #define	__LA_DEAD	__attribute__((__noreturn__))
124*caf54c4fSMartin Matuska #else
125*caf54c4fSMartin Matuska #define	__LA_DEAD
126*caf54c4fSMartin Matuska #endif
127*caf54c4fSMartin Matuska 
128*caf54c4fSMartin Matuska #if defined(_WIN32) && !defined(__CYGWIN__)
129*caf54c4fSMartin Matuska #include "bsdtar_windows.h"
130*caf54c4fSMartin Matuska #endif
131*caf54c4fSMartin Matuska 
132*caf54c4fSMartin Matuska #endif /* !BSDTAR_PLATFORM_H_INCLUDED */
133