summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-02-09 20:25:59 -0500
committerTavian Barnes <tavianator@tavianator.com>2017-02-09 20:25:59 -0500
commit924826a817e397c89509963a1d13d951c9d51ce5 (patch)
treed9eb1cd82578c46ffed3a20897331dc82847437d /eval.c
parent65af85882ae46cd8750b7f03519c3b291fc693db (diff)
downloadbfs-924826a817e397c89509963a1d13d951c9d51ce5.tar.xz
bftw: Make the nameoff of "///" point to "/"
This simplifies a few things such as -name handling for ///.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/eval.c b/eval.c
index 3a97585..512a05a 100644
--- a/eval.c
+++ b/eval.c
@@ -286,7 +286,6 @@ static const char *exec_format_path(const struct expr *expr, const struct BFTW *
if (name[0] == '/') {
// Must be a root path ("/", "//", etc.)
- assert(ftwbuf->nameoff == 0);
return name;
}
@@ -311,7 +310,7 @@ err:
}
static void exec_free_path(const char *path, const struct BFTW *ftwbuf) {
- if (path != ftwbuf->path) {
+ if (path != ftwbuf->path && path != ftwbuf->path + ftwbuf->nameoff) {
dstrfree((char *)path);
}
}
@@ -630,16 +629,12 @@ bool eval_name(const struct expr *expr, struct eval_state *state) {
// Any trailing slashes are not part of the name. This can only
// happen for the root path.
const char *slash = strchr(name, '/');
- if (slash == name) {
- // The name of "/" (or "//", etc.) is "/"
- name = "/";
- } else if (slash) {
- copy = strdup(name);
+ if (slash && slash > name) {
+ copy = strndup(name, slash - name);
if (!copy) {
eval_error(state);
return false;
}
- copy[slash - name] = '\0';
name = copy;
}
}