summaryrefslogtreecommitdiffstats
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
parentd40691e31e2674d7d95ec9160b9897805ce3f43b (diff)
downloadbfs-d8e10d648b12b8595e9f177ec8f1a71d24aecea5.tar.xz
stat: Get rid of bfs_fstat()
We can just use bfs_stat() with a NULL at_path.
-rw-r--r--parse.c2
-rw-r--r--stat.c18
-rw-r--r--stat.h8
3 files changed, 13 insertions, 15 deletions
diff --git a/parse.c b/parse.c
index 10a7300..4be493b 100644
--- a/parse.c
+++ b/parse.c
@@ -419,7 +419,7 @@ static int expr_open(struct parser_state *state, struct expr *expr, const char *
}
struct bfs_stat sb;
- if (bfs_fstat(fileno(cfile->file), &sb) != 0) {
+ if (bfs_stat(fileno(cfile->file), NULL, 0, &sb) != 0) {
parse_error(state, "'%s': %m.\n", path);
goto out_close;
}
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) {
diff --git a/stat.h b/stat.h
index 6c915da..4e4cbaf 100644
--- a/stat.h
+++ b/stat.h
@@ -121,7 +121,8 @@ struct bfs_stat {
* @param at_fd
* The base file descriptor for the lookup.
* @param at_path
- * The path to stat, relative to at_fd.
+ * The path to stat, relative to at_fd. Pass NULL to fstat() at_fd
+ * itself.
* @param flags
* Flags that affect the lookup.
* @param[out] buf
@@ -132,11 +133,6 @@ struct bfs_stat {
int bfs_stat(int at_fd, const char *at_path, enum bfs_stat_flag flags, struct bfs_stat *buf);
/**
- * Facade over fstat().
- */
-int bfs_fstat(int fd, struct bfs_stat *buf);
-
-/**
* Get a particular time field from a bfs_stat() buffer.
*/
const struct timespec *bfs_stat_time(const struct bfs_stat *buf, enum bfs_stat_field field);