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