summaryrefslogtreecommitdiffstats
path: root/stat.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2019-05-04 11:51:56 -0400
committerTavian Barnes <tavianator@tavianator.com>2019-05-04 11:55:07 -0400
commitd8e10d648b12b8595e9f177ec8f1a71d24aecea5 (patch)
tree2a14407a2ae5ff5efa01ff25d89de8a94d553e34 /stat.c
parentd40691e31e2674d7d95ec9160b9897805ce3f43b (diff)
downloadbfs-d8e10d648b12b8595e9f177ec8f1a71d24aecea5.tar.xz
stat: Get rid of bfs_fstat()
We can just use bfs_stat() with a NULL at_path.
Diffstat (limited to 'stat.c')
-rw-r--r--stat.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/stat.c b/stat.c
index d96717a..e3d5400 100644
--- a/stat.c
+++ b/stat.c
@@ -298,15 +298,16 @@ int bfs_stat(int at_fd, const char *at_path, enum bfs_stat_flag flags, struct bf
if (flags & BFS_STAT_NOFOLLOW) {
at_flags |= AT_SYMLINK_NOFOLLOW;
}
- return bfs_stat_explicit(at_fd, at_path, at_flags, flags, buf);
-}
-int bfs_fstat(int fd, struct bfs_stat *buf) {
+ if (at_path) {
+ return bfs_stat_explicit(at_fd, at_path, at_flags, flags, buf);
+ }
+
#ifdef AT_EMPTY_PATH
static bool has_at_ep = true;
-
if (has_at_ep) {
- int ret = bfs_stat_explicit(fd, "", AT_EMPTY_PATH, 0, buf);
+ at_flags |= AT_EMPTY_PATH;
+ int ret = bfs_stat_explicit(at_fd, "", at_flags, flags, buf);
if (ret != 0 && errno == EINVAL) {
has_at_ep = false;
} else {
@@ -316,11 +317,12 @@ int bfs_fstat(int fd, struct bfs_stat *buf) {
#endif
struct stat statbuf;
- int ret = fstat(fd, &statbuf);
- if (ret == 0) {
+ if (fstat(at_fd, &statbuf) == 0) {
bfs_stat_convert(&statbuf, buf);
+ return 0;
+ } else {
+ return -1;
}
- return ret;
}
const struct timespec *bfs_stat_time(const struct bfs_stat *buf, enum bfs_stat_field field) {