diff options
-rw-r--r-- | parse.c | 2 | ||||
-rw-r--r-- | stat.c | 18 | ||||
-rw-r--r-- | stat.h | 8 |
3 files changed, 13 insertions, 15 deletions
@@ -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; } @@ -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) { @@ -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); |