summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bftw.c6
-rwxr-xr-xtests.sh6
-rw-r--r--tests/test_0138.out1
3 files changed, 11 insertions, 2 deletions
diff --git a/bftw.c b/bftw.c
index 70826ea..4ac1240 100644
--- a/bftw.c
+++ b/bftw.c
@@ -777,10 +777,14 @@ static void bftw_init_buffers(struct bftw_state *state, const struct dirent *de)
dircache_entry_base(&state->cache, current, &ftwbuf->at_fd, &ftwbuf->at_path);
}
} else {
- ftwbuf->nameoff = basename_offset(ftwbuf->path);
ftwbuf->depth = 0;
}
+ if (ftwbuf->depth == 0) {
+ // Compute the name offset for root paths like "foo/bar"
+ ftwbuf->nameoff = basename_offset(ftwbuf->path);
+ }
+
ftwbuf->typeflag = BFTW_UNKNOWN;
if (de) {
ftwbuf_use_dirent(ftwbuf, de);
diff --git a/tests.sh b/tests.sh
index 7e85cff..001fea4 100755
--- a/tests.sh
+++ b/tests.sh
@@ -837,9 +837,13 @@ function test_0137() {
bfs_diff basic -maxdepth 0 -printf '\18\118\1118\11118\n\cfoo'
}
+function test_0138() {
+ bfs_diff basic/g -depth -name g
+}
+
result=0
-for i in {1..137}; do
+for i in {1..138}; do
test="test_$(printf '%04d' $i)"
if [ -t 1 ]; then
diff --git a/tests/test_0138.out b/tests/test_0138.out
new file mode 100644
index 0000000..cf4d5a9
--- /dev/null
+++ b/tests/test_0138.out
@@ -0,0 +1 @@
+basic/g