summaryrefslogtreecommitdiffstats
path: root/options/path.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-02-06 14:14:35 +0100
committerwm4 <wm4@nowhere>2020-02-06 14:14:35 +0100
commit1dc3507474aeb82d023d4fc2949d25fc774e2ce0 (patch)
tree669003b20a994fc16fa96bdc84fa1942c15fea0c /options/path.c
parent31acec543819cf56d63dddae59507858b1229b75 (diff)
downloadmpv-1dc3507474aeb82d023d4fc2949d25fc774e2ce0.tar.bz2
mpv-1dc3507474aeb82d023d4fc2949d25fc774e2ce0.tar.xz
path: add mp_path_is_absolute()
Just move it from mp_path_join_bstr() to this new function.
Diffstat (limited to 'options/path.c')
-rw-r--r--options/path.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/options/path.c b/options/path.c
index a17d8b4325..9c996ce664 100644
--- a/options/path.c
+++ b/options/path.c
@@ -254,23 +254,31 @@ char *mp_splitext(const char *path, bstr *root)
return (char *)split + 1;
}
-char *mp_path_join_bstr(void *talloc_ctx, struct bstr p1, struct bstr p2)
+bool mp_path_is_absolute(struct bstr path)
{
- if (p1.len == 0)
- return bstrdup0(talloc_ctx, p2);
- if (p2.len == 0)
- return bstrdup0(talloc_ctx, p1);
+ if (path.len && strchr(mp_path_separators, path.start[0]))
+ return true;
- bool is_absolute = strchr(mp_path_separators, p2.start[0]);
#if HAVE_DOS_PATHS
// Note: "X:filename" is a path relative to the current working directory
// of drive X, and thus is not an absolute path. It needs to be
// followed by \ or /.
- if (p2.len >= 3 && p2.start[1] == ':' &&
- strchr(mp_path_separators, p2.start[2]))
- is_absolute = true;
+ if (path.len >= 3 && path.start[1] == ':' &&
+ strchr(mp_path_separators, path.start[2]))
+ return true;
#endif
- if (is_absolute)
+
+ return false;
+}
+
+char *mp_path_join_bstr(void *talloc_ctx, struct bstr p1, struct bstr p2)
+{
+ if (p1.len == 0)
+ return bstrdup0(talloc_ctx, p2);
+ if (p2.len == 0)
+ return bstrdup0(talloc_ctx, p1);
+
+ if (mp_path_is_absolute(p2))
return bstrdup0(talloc_ctx, p2);
bool have_separator = strchr(mp_path_separators, p1.start[p1.len - 1]);