Merge from vendor branch LESS:
[dragonfly.git] / contrib / libarchive-2 / tar / bsdtar_platform.h
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  * $FreeBSD: src/usr.bin/tar/bsdtar_platform.h,v 1.24 2007/04/12 04:45:32 kientzle Exp $
26  */
27
28 /*
29  * This header is the first thing included in any of the bsdtar
30  * source files.  As far as possible, platform-specific issues should
31  * be dealt with here and not within individual source files.
32  */
33
34 #ifndef BSDTAR_PLATFORM_H_INCLUDED
35 #define BSDTAR_PLATFORM_H_INCLUDED
36
37 #if defined(PLATFORM_CONFIG_H)
38 /* Use hand-built config.h in environments that need it. */
39 #include PLATFORM_CONFIG_H
40 #elif defined(HAVE_CONFIG_H)
41 /* Most POSIX platforms use the 'configure' script to build config.h */
42 #include "../config.h"
43 #else
44 /* Warn if bsdtar hasn't been (automatically or manually) configured. */
45 #error Oops: No config.h and no built-in configuration in bsdtar_platform.h.
46 #endif /* !HAVE_CONFIG_H */
47
48 /* No non-FreeBSD platform will have __FBSDID, so just define it here. */
49 #ifdef __FreeBSD__
50 #include <sys/cdefs.h>  /* For __FBSDID */
51 #else
52 #define __FBSDID(a)     /* null */
53 #endif
54
55 #ifdef HAVE_LIBARCHIVE
56 /* If we're using the platform libarchive, include system headers. */
57 #include <archive.h>
58 #include <archive_entry.h>
59 #else
60 /* Otherwise, include user headers. */
61 #include "archive.h"
62 #include "archive_entry.h"
63 #endif
64
65 /*
66  * Does this platform have complete-looking POSIX-style ACL support,
67  * including some variant of the acl_get_perm() function (which was
68  * omitted from the POSIX.1e draft)?
69  */
70 #if HAVE_SYS_ACL_H && HAVE_ACL_PERMSET_T && HAVE_ACL_USER
71 #if HAVE_ACL_GET_PERM || HAVE_ACL_GET_PERM_NP
72 #define HAVE_POSIX_ACL  1
73 #endif
74 #endif
75
76 #ifdef HAVE_LIBACL
77 #include <acl/libacl.h>
78 #endif
79
80 #if HAVE_ACL_GET_PERM
81 #define ACL_GET_PERM acl_get_perm
82 #else
83 #if HAVE_ACL_GET_PERM_NP
84 #define ACL_GET_PERM acl_get_perm_np
85 #endif
86 #endif
87
88 /*
89  * Include "dirent.h" (or it's equivalent on several different platforms).
90  *
91  * This is slightly modified from the GNU autoconf recipe.
92  * In particular, FreeBSD includes d_namlen in it's dirent structure,
93  * so my configure script includes an explicit test for the d_namlen
94  * field.
95  */
96 #if HAVE_DIRENT_H
97 # include <dirent.h>
98 # if HAVE_DIRENT_D_NAMLEN
99 #  define DIRENT_NAMLEN(dirent) (dirent)->d_namlen
100 # else
101 #  define DIRENT_NAMLEN(dirent) strlen((dirent)->d_name)
102 # endif
103 #else
104 # define dirent direct
105 # define DIRENT_NAMLEN(dirent) (dirent)->d_namlen
106 # if HAVE_SYS_NDIR_H
107 #  include <sys/ndir.h>
108 # endif
109 # if HAVE_SYS_DIR_H
110 #  include <sys/dir.h>
111 # endif
112 # if HAVE_NDIR_H
113 #  include <ndir.h>
114 # endif
115 #endif
116
117
118 /*
119  * We need to be able to display a filesize using printf().  The type
120  * and format string here must be compatible with one another and
121  * large enough for any file.
122  */
123 #if HAVE_UINTMAX_T
124 #define BSDTAR_FILESIZE_TYPE    uintmax_t
125 #define BSDTAR_FILESIZE_PRINTF  "%ju"
126 #else
127 #if HAVE_UNSIGNED_LONG_LONG
128 #define BSDTAR_FILESIZE_TYPE    unsigned long long
129 #define BSDTAR_FILESIZE_PRINTF  "%llu"
130 #else
131 #define BSDTAR_FILESIZE_TYPE    unsigned long
132 #define BSDTAR_FILESIZE_PRINTF  "%lu"
133 #endif
134 #endif
135
136 #if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
137 #define ARCHIVE_STAT_CTIME_NANOS(st)    (st)->st_ctimespec.tv_nsec
138 #define ARCHIVE_STAT_MTIME_NANOS(st)    (st)->st_mtimespec.tv_nsec
139 #else
140 #if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
141 #define ARCHIVE_STAT_CTIME_NANOS(st)    (st)->st_ctim.tv_nsec
142 #define ARCHIVE_STAT_MTIME_NANOS(st)    (st)->st_mtim.tv_nsec
143 #else
144 #define ARCHIVE_STAT_CTIME_NANOS(st)    (0)
145 #define ARCHIVE_STAT_MTIME_NANOS(st)    (0)
146 #endif
147 #endif
148
149 #endif /* !BSDTAR_PLATFORM_H_INCLUDED */