summaryrefslogtreecommitdiffstats
path: root/stat.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2018-07-02 21:55:02 -0400
committerTavian Barnes <tavianator@tavianator.com>2018-07-02 21:55:02 -0400
commit7e0cafb70135a68066ff72227613df9eeb2512fb (patch)
tree92abdd07fe5070eda794c03b291ba9b05b1dbb49 /stat.c
parent6d9f3667bb9c73b775ded64f8ea43f23b5c2d1af (diff)
downloadbfs-7e0cafb70135a68066ff72227613df9eeb2512fb.tar.xz
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
Diffstat (limited to 'stat.c')
-rw-r--r--stat.c15
1 files 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
}