summaryrefslogtreecommitdiffstats
path: root/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-03-16 23:30:21 -0400
committerTavian Barnes <tavianator@tavianator.com>2017-03-16 23:30:21 -0400
commit4da8ba603b588bef38f772c18d883fbf5ddc9e65 (patch)
tree583b6182ebc22baf1c1ce39a4686da0375ff0f04 /bftw.c
parentc85f569daf3e0e99c9e8941d0234711afdb58cd7 (diff)
downloadbfs-4da8ba603b588bef38f772c18d883fbf5ddc9e65.tar.xz
Color link targets for -ls
Fixes #18.
Diffstat (limited to 'bftw.c')
-rw-r--r--bftw.c20
1 files changed, 1 insertions, 19 deletions
diff --git a/bftw.c b/bftw.c
index a3f3345..6d0c849 100644
--- a/bftw.c
+++ b/bftw.c
@@ -761,24 +761,6 @@ static void bftw_set_error(struct bftw_state *state, int error) {
}
/**
- * Figure out the name offset in a path.
- */
-static size_t basename_offset(const char *path) {
- size_t i;
-
- // Strip trailing slashes
- for (i = strlen(path); i > 0 && path[i - 1] == '/'; --i);
-
- // Find the beginning of the name
- for (; i > 0 && path[i - 1] != '/'; --i);
-
- // Strip leading slashes
- for (; path[i] == '/' && path[i + 1]; ++i);
-
- return i;
-}
-
-/**
* Initialize the buffers with data about the current path.
*/
static void bftw_init_buffers(struct bftw_state *state, const struct dirent *de) {
@@ -811,7 +793,7 @@ static void bftw_init_buffers(struct bftw_state *state, const struct dirent *de)
if (ftwbuf->depth == 0) {
// Compute the name offset for root paths like "foo/bar"
- ftwbuf->nameoff = basename_offset(ftwbuf->path);
+ ftwbuf->nameoff = xbasename(ftwbuf->path) - ftwbuf->path;
}
ftwbuf->typeflag = BFTW_UNKNOWN;