mirror of
https://github.com/mpv-player/mpv
synced 2025-01-22 23:53:29 +00:00
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).
This commit is contained in:
parent
c31ce789c5
commit
3782fa20ed
@ -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)
|
||||
|
@ -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);
|
||||
|
||||
|
@ -347,7 +347,7 @@ void screenshot_to_file(struct MPContext *mpctx, const char *filename, int mode,
|
||||
}
|
||||
char *ext = mp_splitext(filename, NULL);
|
||||
if (ext)
|
||||
opts.format = ext + 1; // omit '.'
|
||||
opts.format = ext;
|
||||
struct mp_image *image = screenshot_get(mpctx, mode);
|
||||
if (!image) {
|
||||
screenshot_msg(ctx, SMSG_ERR, "Taking screenshot failed.");
|
||||
|
Loading…
Reference in New Issue
Block a user