summaryrefslogtreecommitdiffstats
path: root/options
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-12-22 23:04:19 +0100
committerwm4 <wm4@nowhere>2013-12-22 23:25:08 +0100
commit3782fa20edcd3e4bdbbfa5ffbd430449b97c009a (patch)
treef9021405d4f140a5405041027d04a06746339d32 /options
parentc31ce789c5058e076b3219d19a0441171add9c08 (diff)
downloadmpv-3782fa20edcd3e4bdbbfa5ffbd430449b97c009a.tar.bz2
mpv-3782fa20edcd3e4bdbbfa5ffbd430449b97c009a.tar.xz
path: change mp_splitext() semantics
Including the "." in the returned extension was too inconvenient. I think originally, the semantics were supposed to work like in Python, but screw this. Also, return NULL instead of "" on failure (which is what its only user actually seems to expect).
Diffstat (limited to 'options')
-rw-r--r--options/path.c8
-rw-r--r--options/path.h6
2 files changed, 7 insertions, 7 deletions
diff --git a/options/path.c b/options/path.c
index 17d6245582..304f009167 100644
--- a/options/path.c
+++ b/options/path.c
@@ -155,11 +155,11 @@ char *mp_splitext(const char *path, bstr *root)
{
assert(path);
const char *split = strrchr(path, '.');
- if (!split)
- split = path + strlen(path);
+ if (!split || !split[1] || strchr(split, '/'))
+ return NULL;
if (root)
- *root = (bstr){.start = (char *)path, .len = path - split};
- return (char *)split;
+ *root = (bstr){(char *)path, split - path};
+ return (char *)split + 1;
}
char *mp_path_join(void *talloc_ctx, struct bstr p1, struct bstr p2)
diff --git a/options/path.h b/options/path.h
index 0e1744bbd0..4756379fa2 100644
--- a/options/path.h
+++ b/options/path.h
@@ -50,10 +50,10 @@ char *mp_get_user_path(void *talloc_ctx, struct mpv_global *global,
char *mp_basename(const char *path);
-/* Return file extension, including the '.'. If root is not NULL, set it to the
- * part of the path without extension. So: path == root + returnvalue
+/* Return file extension, excluding the '.'. If root is not NULL, set it to the
+ * part of the path without extension. So: path == root + "." + extension
* Don't consider it a file extension if the only '.' is the first character.
- * Return "" if no extension.
+ * Return NULL if no extension and don't set *root in this case.
*/
char *mp_splitext(const char *path, bstr *root);