From 1a09154988d8447afa421adcaa0006f2c3f64652 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Fri, 27 Mar 2026 16:57:24 +0100 Subject: [PATCH] various: replace mp_splitext() with bstr_get_ext() This will allow removing mp_splitext(). --- demux/demux_playlist.c | 6 +++--- player/configfiles.c | 2 +- player/screenshot.c | 3 +-- player/scripting.c | 6 +++--- video/image_writer.c | 4 ++-- video/image_writer.h | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/demux/demux_playlist.c b/demux/demux_playlist.c index c223d4ee19..eec0778618 100644 --- a/demux/demux_playlist.c +++ b/demux/demux_playlist.c @@ -249,14 +249,14 @@ static int parse_m3u(struct pl_parser *p) if (p->probing && !bstr_equals0(line, "#EXTM3U")) { // Last resort: if the file extension is m3u, it might be headerless. if (p->check_level == DEMUX_CHECK_UNSAFE) { - char *ext = mp_splitext(p->real_stream->url, NULL); + bstr ext = bstr_get_ext(bstr0(p->real_stream->url)); char probe[PROBE_SIZE]; int len = stream_read_peek(p->real_stream, probe, sizeof(probe)); bstr data = {probe, len}; - if (ext && data.len >= 2 && maybe_text(data)) { + if (ext.len && data.len >= 2 && maybe_text(data)) { const char *exts[] = {"m3u", "m3u8", "strm", NULL}; for (int n = 0; exts[n]; n++) { - if (strcasecmp(ext, exts[n]) == 0) + if (bstrcasecmp(ext, bstr0(exts[n])) == 0) goto ok; } } diff --git a/player/configfiles.c b/player/configfiles.c index 1e38308cda..bbb1982e72 100644 --- a/player/configfiles.c +++ b/player/configfiles.c @@ -166,7 +166,7 @@ void mp_load_auto_profiles(struct MPContext *mpctx) mp_auto_load_profile(mpctx, "protocol", mp_split_proto(bstr0(mpctx->filename), NULL)); mp_auto_load_profile(mpctx, "extension", - bstr0(mp_splitext(mpctx->filename, NULL))); + bstr_get_ext(bstr0(mpctx->filename))); mp_load_per_file_config(mpctx); } diff --git a/player/screenshot.c b/player/screenshot.c index d16b7d75ab..40b0eb338a 100644 --- a/player/screenshot.c +++ b/player/screenshot.c @@ -489,8 +489,7 @@ void cmd_screenshot_to_file(void *p) int mode = cmd->args[1].v.i; struct image_writer_opts opts = *mpctx->opts->screenshot_image_opts; - char *ext = mp_splitext(filename, NULL); - int format = image_writer_format_from_ext(ext); + int format = image_writer_format_from_ext(bstr_get_ext(bstr0(filename))); if (format) opts.format = format; bool high_depth = image_writer_high_depth(&opts); diff --git a/player/scripting.c b/player/scripting.c index 6ed582f142..3b2337f1c2 100644 --- a/player/scripting.c +++ b/player/scripting.c @@ -104,8 +104,8 @@ static MP_THREAD_VOID script_thread(void *p) static int64_t mp_load_script(struct MPContext *mpctx, const char *fname) { - char *ext = mp_splitext(fname, NULL); - if (ext && strcasecmp(ext, "disable") == 0) + bstr ext = bstr_get_ext(bstr0(fname)); + if (bstrcasecmp0(ext, "disable") == 0) return 0; void *tmp = talloc_new(NULL); @@ -144,7 +144,7 @@ static int64_t mp_load_script(struct MPContext *mpctx, const char *fname) } else { for (int n = 0; scripting_backends[n]; n++) { const struct mp_scripting *b = scripting_backends[n]; - if (ext && strcasecmp(ext, b->file_ext) == 0) { + if (bstrcasecmp0(ext, b->file_ext) == 0) { backend = b; break; } diff --git a/video/image_writer.c b/video/image_writer.c index f3c9777026..0da61af17b 100644 --- a/video/image_writer.c +++ b/video/image_writer.c @@ -584,10 +584,10 @@ bool image_writer_flexible_csp(const struct image_writer_opts *opts) || opts->format == AV_CODEC_ID_PNG; } -int image_writer_format_from_ext(const char *ext) +int image_writer_format_from_ext(bstr ext) { for (int n = 0; mp_image_writer_formats[n].name; n++) { - if (ext && strcmp(mp_image_writer_formats[n].name, ext) == 0) + if (bstrcmp0(ext, mp_image_writer_formats[n].name) == 0) return mp_image_writer_formats[n].value; } return 0; diff --git a/video/image_writer.h b/video/image_writer.h index c22606ed65..78130cdc90 100644 --- a/video/image_writer.h +++ b/video/image_writer.h @@ -52,7 +52,7 @@ bool image_writer_high_depth(const struct image_writer_opts *opts); bool image_writer_flexible_csp(const struct image_writer_opts *opts); // Map file extension to format ID - return 0 (which is invalid) if unknown. -int image_writer_format_from_ext(const char *ext); +int image_writer_format_from_ext(bstr ext); /* * Save the given image under the given filename. The parameters csp and opts