From 5eec93b79577eccd20370bc440cad21f7592866c Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Sun, 1 Nov 2009 01:56:20 -0500 Subject: [PATCH] Make the __FBSDID() handling more platform-agnostic by using HAVE_SYS_CDEFS_H to control the inclusion of sys/cdefs.h and defining a fake __FBSDID() macro if we need one. In particular, this deals a lot more gracefully with systems that are not FreeBSD but use FreeBSD-derived system headers. See Issue 46 on libarchive.googlecode.com for discussion. Submitted by: cpr420 SVN-Revision: 1565 --- CMakeLists.txt | 1 + build/cmake/config.h.in | 3 +++ configure.ac | 2 +- cpio/config_freebsd.h | 1 + cpio/cpio_platform.h | 12 +++++++----- cpio/test/test.h | 12 ++++++------ libarchive/archive_platform.h | 12 +++++++----- libarchive/config_freebsd.h | 1 + libarchive/test/test.h | 12 ++++++------ libarchive_fe/lafe_platform.h | 12 +++++++----- tar/bsdtar_platform.h | 12 +++++++----- tar/config_freebsd.h | 1 + tar/test/test.h | 12 ++++++------ 13 files changed, 54 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed2fde01a..d549c1288 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -228,6 +228,7 @@ LA_CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H) LA_CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H) LA_CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H) LA_CHECK_INCLUDE_FILE("sys/acl.h" HAVE_SYS_ACL_H) +LA_CHECK_INCLUDE_FILE("sys/cdefs.h" HAVE_SYS_CDEFS_H) LA_CHECK_INCLUDE_FILE("sys/extattr.h" HAVE_SYS_EXTATTR_H) LA_CHECK_INCLUDE_FILE("sys/ioctl.h" HAVE_SYS_IOCTL_H) LA_CHECK_INCLUDE_FILE("sys/mkdev.h" HAVE_SYS_MKDEV_H) diff --git a/build/cmake/config.h.in b/build/cmake/config.h.in index be3e0463e..2db556c79 100644 --- a/build/cmake/config.h.in +++ b/build/cmake/config.h.in @@ -453,6 +453,9 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_ACL_H 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_CDEFS_H 1 + /* Define to 1 if you have the header file, and it defines `DIR'. */ #cmakedefine HAVE_SYS_DIR_H 1 diff --git a/configure.ac b/configure.ac index d9652336c..21b3a7215 100644 --- a/configure.ac +++ b/configure.ac @@ -196,7 +196,7 @@ AC_CHECK_HEADERS([ext2fs/ext2_fs.h fcntl.h grp.h]) AC_CHECK_HEADERS([inttypes.h io.h langinfo.h limits.h linux/fs.h]) AC_CHECK_HEADERS([locale.h paths.h poll.h pwd.h regex.h signal.h stdarg.h]) AC_CHECK_HEADERS([stdint.h stdlib.h string.h]) -AC_CHECK_HEADERS([sys/acl.h sys/extattr.h sys/ioctl.h sys/mkdev.h]) +AC_CHECK_HEADERS([sys/acl.h sys/cdefs.h sys/extattr.h sys/ioctl.h sys/mkdev.h]) AC_CHECK_HEADERS([sys/param.h sys/poll.h sys/select.h sys/time.h sys/utime.h]) AC_CHECK_HEADERS([time.h unistd.h utime.h wchar.h wctype.h windows.h]) diff --git a/cpio/config_freebsd.h b/cpio/config_freebsd.h index 0d449d993..c52ddccf9 100644 --- a/cpio/config_freebsd.h +++ b/cpio/config_freebsd.h @@ -44,6 +44,7 @@ #define HAVE_STDLIB_H 1 #define HAVE_STRING_H 1 #define HAVE_SYMLINK 1 +#define HAVE_SYS_CDEFS_H 1 #define HAVE_SYS_STAT_H 1 #define HAVE_SYS_TIME_H 1 #define HAVE_TIME_H 1 diff --git a/cpio/cpio_platform.h b/cpio/cpio_platform.h index 57e2450bf..31d9a738f 100644 --- a/cpio/cpio_platform.h +++ b/cpio/cpio_platform.h @@ -42,11 +42,13 @@ #include "config.h" #endif -/* No non-FreeBSD platform will have __FBSDID, so just define it here. */ -#ifdef __FreeBSD__ -#include /* For __FBSDID */ -#elif !defined(__FBSDID) -/* Just leaving this macro replacement empty leads to a dangling semicolon. */ +/* Get a real definition for __FBSDID if we can */ +#if HAVE_SYS_CDEFS_H +#include +#endif + +/* If not, define it so as to avoid dangling semicolons. */ +#ifndef __FBSDID #define __FBSDID(a) struct _undefined_hack #endif diff --git a/cpio/test/test.h b/cpio/test/test.h index bbab584ac..ca54b9f86 100644 --- a/cpio/test/test.h +++ b/cpio/test/test.h @@ -107,15 +107,15 @@ #include #endif -/* FreeBSD */ -#ifdef __FreeBSD__ -#include /* For __FBSDID */ -#else -/* Surprisingly, some non-FreeBSD platforms define __FBSDID. */ +/* Get a real definition for __FBSDID if we can */ +#if HAVE_SYS_CDEFS_H +#include +#endif + +/* If not, define it so as to avoid dangling semicolons. */ #ifndef __FBSDID #define __FBSDID(a) struct _undefined_hack #endif -#endif #ifndef O_BINARY #define O_BINARY 0 diff --git a/libarchive/archive_platform.h b/libarchive/archive_platform.h index 75abc1bad..6a4b08d21 100644 --- a/libarchive/archive_platform.h +++ b/libarchive/archive_platform.h @@ -66,11 +66,13 @@ * headers as required. */ -/* No non-FreeBSD platform will have __FBSDID, so just define it here. */ -#ifdef __FreeBSD__ -#include /* For __FBSDID */ -#else -/* Just leaving this macro replacement empty leads to a dangling semicolon. */ +/* Get a real definition for __FBSDID if we can */ +#if HAVE_SYS_CDEFS_H +#include +#endif + +/* If not, define it so as to avoid dangling semicolons. */ +#ifndef __FBSDID #define __FBSDID(a) struct _undefined_hack #endif diff --git a/libarchive/config_freebsd.h b/libarchive/config_freebsd.h index 2ebfe2091..f8a5b7428 100644 --- a/libarchive/config_freebsd.h +++ b/libarchive/config_freebsd.h @@ -118,6 +118,7 @@ #define HAVE_STRUCT_STAT_ST_FLAGS 1 #define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1 #define HAVE_SYMLINK 1 +#define HAVE_SYS_CDEFS_H 1 #define HAVE_SYS_IOCTL_H 1 #define HAVE_SYS_SELECT_H 1 #define HAVE_SYS_STAT_H 1 diff --git a/libarchive/test/test.h b/libarchive/test/test.h index 3e8d36e87..f6d9fe772 100644 --- a/libarchive/test/test.h +++ b/libarchive/test/test.h @@ -106,15 +106,15 @@ #include #endif -/* FreeBSD */ -#ifdef __FreeBSD__ -#include /* For __FBSDID */ -#else -/* Surprisingly, some non-FreeBSD platforms define __FBSDID. */ +/* Get a real definition for __FBSDID if we can */ +#if HAVE_SYS_CDEFS_H +#include +#endif + +/* If not, define it so as to avoid dangling semicolons. */ #ifndef __FBSDID #define __FBSDID(a) struct _undefined_hack #endif -#endif #ifndef O_BINARY #define O_BINARY 0 diff --git a/libarchive_fe/lafe_platform.h b/libarchive_fe/lafe_platform.h index dceb5aaf3..557124b9f 100644 --- a/libarchive_fe/lafe_platform.h +++ b/libarchive_fe/lafe_platform.h @@ -42,11 +42,13 @@ #include "config.h" #endif -/* No non-FreeBSD platform will have __FBSDID, so just define it here. */ -#ifdef __FreeBSD__ -#include /* For __FBSDID */ -#elif !defined(__FBSDID) -/* Just leaving this macro replacement empty leads to a dangling semicolon. */ +/* Get a real definition for __FBSDID if we can */ +#if HAVE_SYS_CDEFS_H +#include +#endif + +/* If not, define it so as to avoid dangling semicolons. */ +#ifndef __FBSDID #define __FBSDID(a) struct _undefined_hack #endif diff --git a/tar/bsdtar_platform.h b/tar/bsdtar_platform.h index d86391337..fce9c9981 100644 --- a/tar/bsdtar_platform.h +++ b/tar/bsdtar_platform.h @@ -42,11 +42,13 @@ #include "config.h" #endif -/* No non-FreeBSD platform will have __FBSDID, so just define it here. */ -#ifdef __FreeBSD__ -#include /* For __FBSDID */ -#else -/* Just leaving this macro replacement empty leads to a dangling semicolon. */ +/* Get a real definition for __FBSDID if we can */ +#if HAVE_SYS_CDEFS_H +#include +#endif + +/* If not, define it so as to avoid dangling semicolons. */ +#ifndef __FBSDID #define __FBSDID(a) struct _undefined_hack #endif diff --git a/tar/config_freebsd.h b/tar/config_freebsd.h index c0b057ade..02145efc0 100644 --- a/tar/config_freebsd.h +++ b/tar/config_freebsd.h @@ -68,6 +68,7 @@ #define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1 #undef HAVE_STRUCT_STAT_ST_UMTIME #define HAVE_SYMLINK 1 +#define HAVE_SYS_CDEFS_H 1 #undef HAVE_SYS_DIR_H #define HAVE_SYS_IOCTL_H 1 #undef HAVE_SYS_NDIR_H diff --git a/tar/test/test.h b/tar/test/test.h index de219a945..ac5940227 100644 --- a/tar/test/test.h +++ b/tar/test/test.h @@ -107,15 +107,15 @@ #include #endif -/* FreeBSD */ -#ifdef __FreeBSD__ -#include /* For __FBSDID */ -#else -/* Surprisingly, some non-FreeBSD platforms define __FBSDID. */ +/* Get a real definition for __FBSDID if we can */ +#if HAVE_SYS_CDEFS_H +#include +#endif + +/* If not, define it so as to avoid dangling semicolons. */ #ifndef __FBSDID #define __FBSDID(a) struct _undefined_hack #endif -#endif #ifndef O_BINARY #define O_BINARY 0 -- 2.47.3