summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-09-02 14:27:32 -0400
committerTavian Barnes <tavianator@tavianator.com>2017-09-02 14:28:15 -0400
commite5627cd680838ad2217d4ba107a7e6d9aff26c2c (patch)
tree6b3e4f3caf00a009b06405264abdb3078881a187
parentc6cf5ec6ae6420e902441289a5b7524a2322a664 (diff)
downloadbfs-e5627cd680838ad2217d4ba107a7e6d9aff26c2c.tar.xz
mtab: Use __has_include() to check for <mntent.h>
This fixes the build against musl, as long as you have a new enough compiler for __has_include.
-rw-r--r--mtab.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/mtab.c b/mtab.c
index 5eccec5..a43e662 100644
--- a/mtab.c
+++ b/mtab.c
@@ -22,9 +22,20 @@
#include <sys/stat.h>
#include <sys/types.h>
-#if __GLIBC__
-# include <mntent.h>
+#ifndef __has_include
+# define __has_include(header) 0
+#endif
+
+#if __GLIBC__ || __has_include(<mntent.h>)
+# define BFS_MNTENT 1
#elif BSD
+# define BFS_MNTINFO 1
+#endif
+
+#if BFS_MNTENT
+# include <mntent.h>
+# include <paths.h>
+#elif BFS_MNTINFO
# include <sys/mount.h>
# include <sys/ucred.h>
#endif
@@ -76,7 +87,7 @@ static int bfs_mtab_push(struct bfs_mtab *mtab, dev_t dev, const char *type) {
}
struct bfs_mtab *parse_bfs_mtab() {
-#if __GLIBC__
+#if BFS_MNTENT
FILE *file = setmntent(_PATH_MOUNTED, "r");
if (!file) {
@@ -113,7 +124,7 @@ fail_file:
fail:
return NULL;
-#elif BSD
+#elif BFS_MNTINFO
struct statfs *mntbuf;
int size = getmntinfo(&mntbuf, MNT_WAIT);