summaryrefslogtreecommitdiffstats
path: root/src/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-01-13 12:42:42 -0500
committerTavian Barnes <tavianator@tavianator.com>2024-01-13 12:42:42 -0500
commite9588c49d5539ded993f720fc6855d6fa878c997 (patch)
treed827157c37f59335252ba874fd41604984775471 /src/bftw.c
parentd6cae04b54c1d58223e1719101b7c54d348e8d80 (diff)
downloadbfs-e9588c49d5539ded993f720fc6855d6fa878c997.tar.xz
bfstd: New {error,errno}_is_like() functions
We used to have is_nonexistence_error() to consistently treat ENOENT and ENOTDIR the same. Recently, we started considering EFAULT the same as ENAMETOOLONG on DragonFly BSD to work around a kernel bug. Unify both of these behind a more generic interface.
Diffstat (limited to 'src/bftw.c')
-rw-r--r--src/bftw.c18
1 files changed, 3 insertions, 15 deletions
diff --git a/src/bftw.c b/src/bftw.c
index 355cb54..49f07df 100644
--- a/src/bftw.c
+++ b/src/bftw.c
@@ -68,7 +68,7 @@ const struct bfs_stat *bftw_stat(const struct BFTW *ftwbuf, enum bfs_stat_flags
}
} else {
ret = bftw_stat_impl(mutbuf, &mutbuf->stat_cache, BFS_STAT_FOLLOW);
- if (!ret && (flags & BFS_STAT_TRYFOLLOW) && is_nonexistence_error(errno)) {
+ if (!ret && (flags & BFS_STAT_TRYFOLLOW) && errno_is_like(ENOENT)) {
ret = bftw_stat_impl(mutbuf, &mutbuf->lstat_cache, BFS_STAT_NOFOLLOW);
}
}
@@ -81,7 +81,7 @@ const struct bfs_stat *bftw_cached_stat(const struct BFTW *ftwbuf, enum bfs_stat
return ftwbuf->lstat_cache.buf;
} else if (ftwbuf->stat_cache.buf) {
return ftwbuf->stat_cache.buf;
- } else if ((flags & BFS_STAT_TRYFOLLOW) && is_nonexistence_error(ftwbuf->stat_cache.error)) {
+ } else if ((flags & BFS_STAT_TRYFOLLOW) && error_is_like(ftwbuf->stat_cache.error, ENOENT)) {
return ftwbuf->lstat_cache.buf;
} else {
return NULL;
@@ -739,22 +739,10 @@ static int bftw_file_open(struct bftw_state *state, struct bftw_file *file, cons
}
int fd = bftw_file_openat(state, file, base, at_path);
- if (fd >= 0) {
+ if (fd >= 0 || !errno_is_like(ENAMETOOLONG)) {
return fd;
}
- switch (errno) {
- case ENAMETOOLONG:
-#if __DragonFly__
- // https://twitter.com/tavianator/status/1742991411203485713
- case EFAULT:
-#endif
- break;
-
- default:
- return -1;
- }
-
// Handle ENAMETOOLONG by manually traversing the path component-by-component
struct bftw_list parents;
SLIST_INIT(&parents);