aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/path.c10
-rw-r--r--src/path.h13
2 files changed, 20 insertions, 3 deletions
diff --git a/src/path.c b/src/path.c
index 8c7b61cdf..a99f8bd2c 100644
--- a/src/path.c
+++ b/src/path.c
@@ -225,13 +225,23 @@ void pathcpy_trunc(char *dest, const char *src)
char *parent_path(char *path_max_tmp, const char *path)
{
char *c;
+ static const int handle_trailing_slashes = 0;
pathcpy_trunc(path_max_tmp, path);
+
+ if (handle_trailing_slashes) {
+ size_t last_char = strlen(path_max_tmp) - 1;
+
+ while (last_char > 0 && path_max_tmp[last_char] == '/')
+ path_max_tmp[last_char--] = '\0';
+ }
+
c = strrchr(path_max_tmp,'/');
if (c == NULL)
path_max_tmp[0] = '\0';
else {
+ /* strip redundant slashes: */
while ((path_max_tmp <= c) && *(--c) == '/') /* nothing */
;
c[1] = '\0';
diff --git a/src/path.h b/src/path.h
index 5a452ca7c..fef935400 100644
--- a/src/path.h
+++ b/src/path.h
@@ -60,13 +60,20 @@ char *pfx_dir(char *dst,
const char *path, const size_t path_len,
const char *pfx, const size_t pfx_len);
-/* relative music path to absolute music path
- * char * passed is a static variable, so don't free it
- */
+/* relative music path to absolute music path */
char *rmp2amp_r(char *dst, const char *rel_path);
+/* relative playlist path to absolute playlist path */
char *rpp2app_r(char *dst, const char *rel_path);
+/*
+ * parent_path - saner version of dirname(3) with slightly different semantics
+ * - we will return "" instead of "." or "/" if we have no parent
+ * this is because we only deal with internal paths
+ * - we always skip over redundant slashes in the middle, if there are any
+ * - we will never get meaningful paths with trailing slashes in our callers
+ * (set handle_trailing_slashes to true if we do)
+ */
char *parent_path(char *path_max_tmp, const char *path);
/* strips extra "///" and leading "/" and trailing "/" */