Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions misc/path_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ char *mp_basename(const char *path)
{
char *s;

/* otherwise the check below finds the wrong index */
mp_path_strip_trailing_separator((char *)path);

#if HAVE_DOS_PATHS
if (!mp_is_url(bstr0(path))) {
s = strrchr(path, '\\');
Expand All @@ -54,7 +57,7 @@ char *mp_basename(const char *path)
}
#endif
s = strrchr(path, '/');
return s ? s + 1 : (char *)path;
return s && strlen(s) > 1 ? s + 1 : (char *)path;
}

struct bstr mp_dirname(const char *path)
Expand All @@ -77,8 +80,8 @@ static const char mp_path_separators[] = "/";
// 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]))
size_t len;
while ((len=strlen(path)) > 0 && strchr(mp_path_separators, path[len - 1]))
path[len - 1] = '\0';
}

Expand Down
Loading