From e5627cd680838ad2217d4ba107a7e6d9aff26c2c Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 2 Sep 2017 14:27:32 -0400 Subject: mtab: Use __has_include() to check for This fixes the build against musl, as long as you have a new enough compiler for __has_include. --- mtab.c | 19 +++++++++++++++---- 1 file 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 #include -#if __GLIBC__ -# include +#ifndef __has_include +# define __has_include(header) 0 +#endif + +#if __GLIBC__ || __has_include() +# define BFS_MNTENT 1 #elif BSD +# define BFS_MNTINFO 1 +#endif + +#if BFS_MNTENT +# include +# include +#elif BFS_MNTINFO # include # include #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); -- cgit v1.2.3