From d8e10d648b12b8595e9f177ec8f1a71d24aecea5 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 4 May 2019 11:51:56 -0400 Subject: stat: Get rid of bfs_fstat() We can just use bfs_stat() with a NULL at_path. --- stat.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'stat.c') 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) { -- cgit v1.2.3