aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2019-03-27 13:34:59 -0500
committerRob Landley <rob@landley.net>2019-03-27 13:34:59 -0500
commit4eb39e1e3c9454635a8512b51931efe4ba2c14ed (patch)
treecc3693feb3b3a82ae2b29a98cf65925477192e1d /lib
parentbcb06e3244808e2ced0de2a39a348a7ddb7c54f2 (diff)
downloadtoybox-4eb39e1e3c9454635a8512b51931efe4ba2c14ed.tar.gz
Change fileunderdir() to return abspath to file.
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c8
-rw-r--r--lib/lib.h2
2 files changed, 5 insertions, 5 deletions
diff --git a/lib/lib.c b/lib/lib.c
index a6114321..14cedb60 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -1059,16 +1059,16 @@ char *getbasename(char *name)
return name;
}
-// Is this file under this directory?
-int fileunderdir(char *file, char *dir)
+// Return pointer to xabspath(file) if file is under dir, else 0
+char *fileunderdir(char *file, char *dir)
{
char *s1 = xabspath(dir, 1), *s2 = xabspath(file, -1), *ss = s2;
int rc = s1 && s2 && strstart(&ss, s1) && (!s1[1] || s2[strlen(s1)] == '/');
free(s1);
- free(s2);
+ if (!rc) free(s2);
- return rc;
+ return rc ? s2 : 0;
}
// Execute a callback for each PID that matches a process name from a list.
diff --git a/lib/lib.h b/lib/lib.h
index 8e6514a8..e220962c 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -371,7 +371,7 @@ mode_t string_to_mode(char *mode_str, mode_t base);
void mode_to_string(mode_t mode, char *buf);
char *getdirname(char *name);
char *getbasename(char *name);
-int fileunderdir(char *file, char *dir);
+char *fileunderdir(char *file, char *dir);
void names_to_pid(char **names, int (*callback)(pid_t pid, char *name));
pid_t __attribute__((returns_twice)) xvforkwrap(pid_t pid);