diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2017-09-02 14:27:32 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2017-09-02 14:28:15 -0400 |
commit | e5627cd680838ad2217d4ba107a7e6d9aff26c2c (patch) | |
tree | 6b3e4f3caf00a009b06405264abdb3078881a187 | |
parent | c6cf5ec6ae6420e902441289a5b7524a2322a664 (diff) | |
download | bfs-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.c | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -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); |