Skip to content

Commit 893b350

Browse files
committed
misc/path_utils: new mp_stripext shorthand
There are at least two users of this functionality, the filename/no-ext property and the screenshot template %F specifier. The latter uses a buggy private version. So split out what the former does, so it can be reused.
1 parent 0ee2a7b commit 893b350

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

misc/path_utils.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ char *mp_splitext(const char *path, bstr *root)
100100
return (char *)split + 1;
101101
}
102102

103+
char *mp_stripext(void *talloc_ctx, const char *s)
104+
{
105+
bstr root;
106+
return mp_splitext(s, &root) ? bstrto0(talloc_ctx, root) : (char *)s;
107+
}
108+
103109
bool mp_path_is_absolute(struct bstr path)
104110
{
105111
if (path.len && strchr(mp_path_separators, path.start[0]))

misc/path_utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ char *mp_basename(const char *path);
3737
*/
3838
char *mp_splitext(const char *path, bstr *root);
3939

40+
// This is a shorthand to remove the extension
41+
char *mp_stripext(void *talloc_ctx, const char *s);
42+
4043
/* Return struct bstr referencing directory part of path, or if that
4144
* would be empty, ".".
4245
*/

0 commit comments

Comments
 (0)