Home | History | Annotate | Line # | Download | only in tar
      1 /*-
      2  * SPDX-License-Identifier: BSD-2-Clause
      3  *
      4  * Copyright (c) 2003-2007 Tim Kientzle
      5  * All rights reserved.
      6  */
      7 
      8 /*
      9  * This header is the first thing included in any of the bsdtar
     10  * source files.  As far as possible, platform-specific issues should
     11  * be dealt with here and not within individual source files.
     12  */
     13 
     14 #ifndef BSDTAR_PLATFORM_H_INCLUDED
     15 #define	BSDTAR_PLATFORM_H_INCLUDED
     16 
     17 #if defined(PLATFORM_CONFIG_H)
     18 /* Use hand-built config.h in environments that need it. */
     19 #include PLATFORM_CONFIG_H
     20 #else
     21 /* Not having a config.h of some sort is a serious problem. */
     22 #include "config.h"
     23 #endif
     24 
     25 #if defined(_WIN32) && !defined(__CYGWIN__)
     26 #include "bsdtar_windows.h"
     27 #endif
     28 
     29 #ifdef HAVE_LIBARCHIVE
     30 /* If we're using the platform libarchive, include system headers. */
     31 #include <archive.h>
     32 #include <archive_entry.h>
     33 #else
     34 /* Otherwise, include user headers. */
     35 #include "archive.h"
     36 #include "archive_entry.h"
     37 #endif
     38 
     39 #ifdef HAVE_LIBACL
     40 #include <acl/libacl.h>
     41 #endif
     42 
     43 /*
     44  * Include "dirent.h" (or its equivalent on several different platforms).
     45  *
     46  * This is slightly modified from the GNU autoconf recipe.
     47  * In particular, FreeBSD includes d_namlen in its dirent structure,
     48  * so my configure script includes an explicit test for the d_namlen
     49  * field.
     50  */
     51 #if HAVE_DIRENT_H
     52 # include <dirent.h>
     53 # if HAVE_DIRENT_D_NAMLEN
     54 #  define DIRENT_NAMLEN(dirent) (dirent)->d_namlen
     55 # else
     56 #  define DIRENT_NAMLEN(dirent) strlen((dirent)->d_name)
     57 # endif
     58 #else
     59 # define dirent direct
     60 # define DIRENT_NAMLEN(dirent) (dirent)->d_namlen
     61 # if HAVE_SYS_NDIR_H
     62 #  include <sys/ndir.h>
     63 # endif
     64 # if HAVE_SYS_DIR_H
     65 #  include <sys/dir.h>
     66 # endif
     67 # if HAVE_NDIR_H
     68 #  include <ndir.h>
     69 # endif
     70 #endif
     71 
     72 #if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
     73 #define	ARCHIVE_STAT_CTIME_NANOS(st)	(st)->st_ctimespec.tv_nsec
     74 #define	ARCHIVE_STAT_MTIME_NANOS(st)	(st)->st_mtimespec.tv_nsec
     75 #elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
     76 #define	ARCHIVE_STAT_CTIME_NANOS(st)	(st)->st_ctim.tv_nsec
     77 #define	ARCHIVE_STAT_MTIME_NANOS(st)	(st)->st_mtim.tv_nsec
     78 #elif HAVE_STRUCT_STAT_ST_MTIME_N
     79 #define	ARCHIVE_STAT_CTIME_NANOS(st)	(st)->st_ctime_n
     80 #define	ARCHIVE_STAT_MTIME_NANOS(st)	(st)->st_mtime_n
     81 #elif HAVE_STRUCT_STAT_ST_UMTIME
     82 #define	ARCHIVE_STAT_CTIME_NANOS(st)	(st)->st_uctime * 1000
     83 #define	ARCHIVE_STAT_MTIME_NANOS(st)	(st)->st_umtime * 1000
     84 #elif HAVE_STRUCT_STAT_ST_MTIME_USEC
     85 #define	ARCHIVE_STAT_CTIME_NANOS(st)	(st)->st_ctime_usec * 1000
     86 #define	ARCHIVE_STAT_MTIME_NANOS(st)	(st)->st_mtime_usec * 1000
     87 #else
     88 #define	ARCHIVE_STAT_CTIME_NANOS(st)	(0)
     89 #define	ARCHIVE_STAT_MTIME_NANOS(st)	(0)
     90 #endif
     91 
     92 /* How to mark functions that don't return. */
     93 /* This facilitates use of some newer static code analysis tools. */
     94 #undef __LA_NORETURN
     95 #if defined(__GNUC__) && (__GNUC__ > 2 || \
     96                           (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
     97 #define __LA_NORETURN       __attribute__((__noreturn__))
     98 #elif defined(_MSC_VER)
     99 #define __LA_NORETURN __declspec(noreturn)
    100 #else
    101 #define __LA_NORETURN
    102 #endif
    103 
    104 #endif /* !BSDTAR_PLATFORM_H_INCLUDED */
    105