diff options
Diffstat (limited to 'options')
-rw-r--r-- | options/path.c | 15 | ||||
-rw-r--r-- | options/path.h | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/options/path.c b/options/path.c index 5072e7312c..adfd2ded3e 100644 --- a/options/path.c +++ b/options/path.c @@ -213,6 +213,21 @@ struct bstr mp_dirname(const char *path) return ret; } + +#if HAVE_DOS_PATHS +static const char mp_path_separators[] = "\\/"; +#else +static const char mp_path_separators[] = "/"; +#endif + +// Mutates path and removes a trailing '/' (or '\' on Windows) +void mp_path_strip_trailing_separator(char *path) +{ + size_t len = strlen(path); + if (len > 0 && strchr(mp_path_separators, path[len - 1])) + path[len - 1] = '\0'; +} + char *mp_splitext(const char *path, bstr *root) { assert(path); diff --git a/options/path.h b/options/path.h index 763a8dda54..203651a931 100644 --- a/options/path.h +++ b/options/path.h @@ -65,6 +65,8 @@ char *mp_splitext(const char *path, bstr *root); */ struct bstr mp_dirname(const char *path); +void mp_path_strip_trailing_separator(char *path); + /* Join two path components and return a newly allocated string * for the result. '/' is inserted between the components if needed. * If p2 is an absolute path then the value of p1 is ignored. |