From 7e0cafb70135a68066ff72227613df9eeb2512fb Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 2 Jul 2018 21:55:02 -0400 Subject: stat: Handle platforms that don't support AT_EMPTY_PATH for fstatat() In particular, this caused -fprint to break on Hurd since AT_EMPTY_PATH is defined and works for some syscalls but not fstatat(). Should fix: https://buildd.debian.org/status/fetch.php?pkg=bfs&arch=hurd-i386&ver=1.2.2-1&stamp=1529920401&raw=0 --- stat.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/stat.c b/stat.c index 3b90d04..1897bb3 100644 --- a/stat.c +++ b/stat.c @@ -231,13 +231,22 @@ int bfs_stat(int at_fd, const char *at_path, int at_flags, enum bfs_stat_flag fl int bfs_fstat(int fd, struct bfs_stat *buf) { #ifdef AT_EMPTY_PATH - return bfs_stat(fd, "", AT_EMPTY_PATH, 0, buf); -#else + static bool has_at_ep = true; + + if (has_at_ep) { + int ret = bfs_stat(fd, "", AT_EMPTY_PATH, 0, buf); + if (ret != 0 && errno == EINVAL) { + has_at_ep = false; + } else { + return ret; + } + } +#endif + struct stat statbuf; int ret = fstat(fd, &statbuf); if (ret == 0) { bfs_stat_convert(&statbuf, buf); } return ret; -#endif } -- cgit v1.2.3