summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2018-11-08 08:18:12 -0400
committerTavian Barnes <tavianator@tavianator.com>2018-11-08 08:18:12 -0400
commit4b60aafc1185164cf48a0627bc3b092c6a79b3bc (patch)
treebe3e50c2283607da7e0360eb2c9f4d3e61f54b90
parent5cbf11475b9135c30f1da76268dbb3b27df55cd6 (diff)
downloadbfs-4b60aafc1185164cf48a0627bc3b092c6a79b3bc.tar.xz
Check for <sys/param.h> before including it
Fixes #38.
-rw-r--r--mtab.c7
-rw-r--r--stat.h6
-rw-r--r--util.c10
-rw-r--r--util.h10
4 files changed, 24 insertions, 9 deletions
diff --git a/mtab.c b/mtab.c
index a35641d..19c8331 100644
--- a/mtab.c
+++ b/mtab.c
@@ -20,11 +20,14 @@
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/param.h>
#include <sys/stat.h>
#include <sys/types.h>
-#if __GLIBC__ || BFS_HAS_INCLUDE(<mntent.h>)
+#if BFS_HAS_SYS_PARAM
+# include <sys/param.h>
+#endif
+
+#if BFS_HAS_MNTENT
# define BFS_MNTENT 1
#elif BSD
# define BFS_MNTINFO 1
diff --git a/stat.h b/stat.h
index 2519ff3..dc24cb4 100644
--- a/stat.h
+++ b/stat.h
@@ -17,11 +17,15 @@
#ifndef BFS_STAT_H
#define BFS_STAT_H
-#include <sys/param.h>
+#include "util.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
+#if BFS_HAS_SYS_PARAM
+# include <sys/param.h>
+#endif
+
/**
* bfs_stat field bitmask.
*/
diff --git a/util.c b/util.c
index 74f9d55..93f86ca 100644
--- a/util.c
+++ b/util.c
@@ -22,17 +22,21 @@
#include <langinfo.h>
#include <regex.h>
#include <stdarg.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/param.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
-#if __GLIBC__ || BFS_HAS_INCLUDE(<sys/sysmacros.h>)
+#if BFS_HAS_SYS_PARAM
+# include <sys/param.h>
+#endif
+
+#if BFS_HAS_SYS_SYSMACROS
# include <sys/sysmacros.h>
-#elif BFS_HAS_INCLUDE(<sys/mkdev.h>)
+#elif BFS_HAS_SYS_MKDEV
# include <sys/mkdev.h>
#endif
diff --git a/util.h b/util.h
index 920d6e9..413d289 100644
--- a/util.h
+++ b/util.h
@@ -17,7 +17,6 @@
#ifndef BFS_UTIL_H
#define BFS_UTIL_H
-#include "bftw.h"
#include <dirent.h>
#include <fcntl.h>
#include <fnmatch.h>
@@ -29,11 +28,16 @@
// Some portability concerns
#ifdef __has_include
-# define BFS_HAS_INCLUDE(header) __has_include(header)
+# define BFS_HAS_INCLUDE(header, fallback) __has_include(header)
#else
-# define BFS_HAS_INCLUDE(header) false
+# define BFS_HAS_INCLUDE(header, fallback) fallback
#endif
+#define BFS_HAS_MNTENT BFS_HAS_INCLUDE(<mntent.h>, __GLIBC__)
+#define BFS_HAS_SYS_MKDEV BFS_HAS_INCLUDE(<sys/mkdev.h>, false)
+#define BFS_HAS_SYS_PARAM BFS_HAS_INCLUDE(<sys/param.h>, true)
+#define BFS_HAS_SYS_SYSMACROS BFS_HAS_INCLUDE(<sys/sysmacros.h>, __GLIBC__)
+
#if !defined(FNM_CASEFOLD) && defined(FNM_IGNORECASE)
# define FNM_CASEFOLD FNM_IGNORECASE
#endif