mirror of
https://github.com/mpv-player/mpv
synced 2025-02-23 08:26:56 +00:00
path: make mp_path_join accept normal C strings
Instead of bstr. Most callers of this function do not need bstr. The bstr version of this function is now mp_path_join_bstr().
This commit is contained in:
parent
40997b8ae5
commit
04c02796bd
@ -199,7 +199,7 @@ void playlist_add_base_path(struct playlist *pl, bstr base_path)
|
||||
return;
|
||||
for (struct playlist_entry *e = pl->first; e; e = e->next) {
|
||||
if (!mp_is_url(bstr0(e->filename))) {
|
||||
char *new_file = mp_path_join(e, base_path, bstr0(e->filename));
|
||||
char *new_file = mp_path_join_bstr(e, base_path, bstr0(e->filename));
|
||||
talloc_free(e->filename);
|
||||
e->filename = new_file;
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ static bool open_source(struct timeline *tl, struct bstr filename)
|
||||
if (!base_filename.len) {
|
||||
MP_WARN(tl, "CUE: Invalid audio filename in .cue file!\n");
|
||||
} else {
|
||||
char *fullname = mp_path_join(ctx, dirname, base_filename);
|
||||
char *fullname = mp_path_join_bstr(ctx, dirname, base_filename);
|
||||
if (try_open(tl, fullname)) {
|
||||
res = true;
|
||||
goto out;
|
||||
@ -252,7 +252,7 @@ static bool open_source(struct timeline *tl, struct bstr filename)
|
||||
MP_WARN(tl, "CUE: No useful audio filename "
|
||||
"in .cue file found, trying with '%s' instead!\n",
|
||||
dename0);
|
||||
if (try_open(tl, mp_path_join(ctx, dirname, dename))) {
|
||||
if (try_open(tl, mp_path_join_bstr(ctx, dirname, dename))) {
|
||||
res = true;
|
||||
break;
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ static void fix_filenames(struct tl_parts *parts, char *source_path)
|
||||
for (int n = 0; n < parts->num_parts; n++) {
|
||||
struct tl_part *part = &parts->parts[n];
|
||||
char *filename = mp_basename(part->filename); // plain filename only
|
||||
part->filename = mp_path_join(parts, dirname, bstr0(filename));
|
||||
part->filename = mp_path_join_bstr(parts, dirname, bstr0(filename));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ static char **find_files(const char *original_file)
|
||||
if (!strcmp(ep->d_name, basename))
|
||||
continue;
|
||||
|
||||
char *name = mp_path_join(results, directory, bstr0(ep->d_name));
|
||||
char *name = mp_path_join_bstr(results, directory, bstr0(ep->d_name));
|
||||
char *s1 = ep->d_name;
|
||||
char *s2 = basename;
|
||||
int matchlen = 0;
|
||||
|
@ -245,7 +245,7 @@ static int parse_dir(struct pl_parser *p)
|
||||
qsort(files, num_files, sizeof(files[0]), cmp_filename);
|
||||
|
||||
for (int n = 0; n < num_files; n++)
|
||||
playlist_add_file(p->pl, mp_path_join(p, bstr0(path), bstr0(files[n])));
|
||||
playlist_add_file(p->pl, mp_path_join(p, path, files[n]));
|
||||
|
||||
closedir(dp);
|
||||
|
||||
|
@ -156,13 +156,13 @@ char *mp_get_user_path(void *talloc_ctx, struct mpv_global *global,
|
||||
if (bstr_equals0(prefix, "~")) {
|
||||
res = mp_find_config_file(talloc_ctx, global, rest0);
|
||||
} else if (bstr_equals0(prefix, "")) {
|
||||
res = mp_path_join(talloc_ctx, bstr0(getenv("HOME")), rest);
|
||||
res = mp_path_join_bstr(talloc_ctx, bstr0(getenv("HOME")), rest);
|
||||
} else if (bstr_eatstart0(&prefix, "~")) {
|
||||
void *tmp = talloc_new(NULL);
|
||||
char type[80];
|
||||
snprintf(type, sizeof(type), "%.*s", BSTR_P(prefix));
|
||||
const char *p = mp_get_platform_path(tmp, global, type);
|
||||
res = mp_path_join(talloc_ctx, bstr0(p), rest);
|
||||
res = mp_path_join_bstr(talloc_ctx, bstr0(p), rest);
|
||||
talloc_free(tmp);
|
||||
}
|
||||
}
|
||||
@ -210,7 +210,7 @@ char *mp_splitext(const char *path, bstr *root)
|
||||
return (char *)split + 1;
|
||||
}
|
||||
|
||||
char *mp_path_join(void *talloc_ctx, struct bstr p1, struct bstr p2)
|
||||
char *mp_path_join_bstr(void *talloc_ctx, struct bstr p1, struct bstr p2)
|
||||
{
|
||||
if (p1.len == 0)
|
||||
return bstrdup0(talloc_ctx, p2);
|
||||
@ -238,6 +238,11 @@ char *mp_path_join(void *talloc_ctx, struct bstr p1, struct bstr p2)
|
||||
have_separator ? "" : "/", BSTR_P(p2));
|
||||
}
|
||||
|
||||
char *mp_path_join(void *talloc_ctx, const char *p1, const char *p2)
|
||||
{
|
||||
return mp_path_join_bstr(talloc_ctx, bstr0(p1), bstr0(p2));
|
||||
}
|
||||
|
||||
char *mp_getcwd(void *talloc_ctx)
|
||||
{
|
||||
char *wd = talloc_array(talloc_ctx, char, 20);
|
||||
|
@ -63,7 +63,8 @@ struct bstr mp_dirname(const char *path);
|
||||
* for the result. '/' is inserted between the components if needed.
|
||||
* If p2 is an absolute path then the value of p1 is ignored.
|
||||
*/
|
||||
char *mp_path_join(void *talloc_ctx, struct bstr p1, struct bstr p2);
|
||||
char *mp_path_join(void *talloc_ctx, const char *p1, const char *p2);
|
||||
char *mp_path_join_bstr(void *talloc_ctx, struct bstr p1, struct bstr p2);
|
||||
|
||||
char *mp_getcwd(void *talloc_ctx);
|
||||
|
||||
|
@ -28,7 +28,7 @@ const char *mp_get_platform_path_osx(void *talloc_ctx, const char *type)
|
||||
[pool release];
|
||||
return res;
|
||||
}
|
||||
if (strcmp(type, "desktop") == 0)
|
||||
return mp_path_join(talloc_ctx, bstr0(getenv("HOME")), bstr0("Desktop"));
|
||||
if (strcmp(type, "desktop") == 0 && getenv("HOME"))
|
||||
return mp_path_join(talloc_ctx, getenv("HOME"), "Desktop");
|
||||
return NULL;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ static char *mp_get_win_shell_dir(void *talloc_ctx, int folder)
|
||||
static char *mp_get_win_app_dir(void *talloc_ctx)
|
||||
{
|
||||
char *path = mp_get_win_shell_dir(talloc_ctx, CSIDL_APPDATA);
|
||||
return path ? mp_path_join(talloc_ctx, bstr0(path), bstr0("mpv")) : NULL;
|
||||
return path ? mp_path_join(talloc_ctx, path, "mpv") : NULL;
|
||||
}
|
||||
|
||||
const char *mp_get_platform_path_win(void *talloc_ctx, const char *type)
|
||||
|
@ -117,7 +117,7 @@ static void mp_load_per_file_config(struct MPContext *mpctx)
|
||||
char *name = mp_basename(cfg);
|
||||
|
||||
bstr dir = mp_dirname(cfg);
|
||||
char *dircfg = mp_path_join(NULL, dir, bstr0("mpv.conf"));
|
||||
char *dircfg = mp_path_join_bstr(NULL, dir, bstr0("mpv.conf"));
|
||||
try_load_config(mpctx, dircfg, FILE_LOCAL_FLAGS);
|
||||
talloc_free(dircfg);
|
||||
|
||||
@ -181,7 +181,7 @@ static char *mp_get_playback_resume_config_filename(struct mpv_global *global,
|
||||
char *cwd = mp_getcwd(tmp);
|
||||
if (!cwd)
|
||||
goto exit;
|
||||
realpath = mp_path_join(tmp, bstr0(cwd), bstr0(fname));
|
||||
realpath = mp_path_join(tmp, cwd, fname);
|
||||
}
|
||||
}
|
||||
if (bstr_startswith0(bfname, "dvd://"))
|
||||
|
@ -280,7 +280,7 @@ static void set_path(lua_State *L)
|
||||
char **luadir = mp_find_all_config_files(tmp, get_mpctx(L)->global, "scripts");
|
||||
for (int i = 0; luadir && luadir[i]; i++) {
|
||||
newpath = talloc_asprintf_append(newpath, ";%s",
|
||||
mp_path_join(tmp, bstr0(luadir[i]), bstr0("?.lua")));
|
||||
mp_path_join(tmp, luadir[i], "?.lua"));
|
||||
}
|
||||
|
||||
lua_pushstring(L, newpath); // package path newpath
|
||||
@ -1142,7 +1142,7 @@ static int script_join_path(lua_State *L)
|
||||
{
|
||||
const char *p1 = luaL_checkstring(L, 1);
|
||||
const char *p2 = luaL_checkstring(L, 2);
|
||||
char *r = mp_path_join(NULL, bstr0(p1), bstr0(p2));
|
||||
char *r = mp_path_join(NULL, p1, p2);
|
||||
lua_pushstring(L, r);
|
||||
talloc_free(r);
|
||||
return 1;
|
||||
|
@ -284,7 +284,7 @@ static char *gen_fname(screenshot_ctx *ctx, const char *file_ext)
|
||||
if (dir && dir[0]) {
|
||||
void *t = fname;
|
||||
dir = mp_get_user_path(t, ctx->mpctx->global, dir);
|
||||
fname = mp_path_join(NULL, bstr0(dir), bstr0(fname));
|
||||
fname = mp_path_join(NULL, dir, fname);
|
||||
talloc_free(t);
|
||||
|
||||
mp_mkdirp(dir);
|
||||
|
@ -163,7 +163,7 @@ static char **list_script_files(void *talloc_ctx, char *path)
|
||||
return NULL;
|
||||
struct dirent *ep;
|
||||
while ((ep = readdir(dp))) {
|
||||
char *fname = mp_path_join(talloc_ctx, bstr0(path), bstr0(ep->d_name));
|
||||
char *fname = mp_path_join(talloc_ctx, path, ep->d_name);
|
||||
struct stat s;
|
||||
if (!stat(fname, &s) && S_ISREG(s.st_mode))
|
||||
MP_TARRAY_APPEND(talloc_ctx, files, count, fname);
|
||||
|
@ -891,9 +891,9 @@ static int bdmv_dir_stream_open(stream_t *stream)
|
||||
// directory containing MovieObject.bdmv, or that file itself.
|
||||
if (!check_bdmv(path)) {
|
||||
// On UNIX, just assume the filename has always this case.
|
||||
char *npath = mp_path_join(priv, bstr0(path), bstr0("MovieObject.bdmv"));
|
||||
char *npath = mp_path_join(priv, path, "MovieObject.bdmv");
|
||||
if (!check_bdmv(npath)) {
|
||||
npath = mp_path_join(priv, bstr0(path), bstr0("BDMV/MovieObject.bdmv"));
|
||||
npath = mp_path_join(priv, path, "BDMV/MovieObject.bdmv");
|
||||
if (!check_bdmv(npath))
|
||||
goto unsupported;
|
||||
}
|
||||
|
@ -835,9 +835,9 @@ static int ifo_dvdnav_stream_open(stream_t *stream)
|
||||
// directory containing VIDEO_TS.IFO, or that file itself.
|
||||
if (!check_ifo(path)) {
|
||||
// On UNIX, just assume the filename is always uppercase.
|
||||
char *npath = mp_path_join(priv, bstr0(path), bstr0("VIDEO_TS.IFO"));
|
||||
char *npath = mp_path_join(priv, path, "VIDEO_TS.IFO");
|
||||
if (!check_ifo(npath)) {
|
||||
npath = mp_path_join(priv, bstr0(path), bstr0("VIDEO_TS/VIDEO_TS.IFO"));
|
||||
npath = mp_path_join(priv, path, "VIDEO_TS/VIDEO_TS.IFO");
|
||||
if (!check_ifo(npath))
|
||||
goto unsupported;
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ static void append_dir_subtitles(struct mpv_global *global,
|
||||
|
||||
if (prio) {
|
||||
prio += prio;
|
||||
char *subpath = mp_path_join(*slist, path, dename);
|
||||
char *subpath = mp_path_join_bstr(*slist, path, dename);
|
||||
if (mp_path_exists(subpath)) {
|
||||
MP_GROW_ARRAY(*slist, *nsub);
|
||||
struct subfn *sub = *slist + (*nsub)++;
|
||||
@ -256,8 +256,8 @@ struct subfn *find_external_files(struct mpv_global *global, const char *fname)
|
||||
// Load subtitles in dirs specified by sub-paths option
|
||||
if (opts->sub_paths) {
|
||||
for (int i = 0; opts->sub_paths[i]; i++) {
|
||||
char *path = mp_path_join(slist, mp_dirname(fname),
|
||||
bstr0(opts->sub_paths[i]));
|
||||
char *path = mp_path_join_bstr(slist, mp_dirname(fname),
|
||||
bstr0(opts->sub_paths[i]));
|
||||
append_dir_subtitles(global, &slist, &n, bstr0(path), fname, 0);
|
||||
}
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ bool gl_lcms_get_lut3d(struct gl_lcms *p, struct lut3d **result_lut3d)
|
||||
cache_file = talloc_strdup(tmp, "");
|
||||
for (int i = 0; i < sizeof(hash); i++)
|
||||
cache_file = talloc_asprintf_append(cache_file, "%02X", hash[i]);
|
||||
cache_file = mp_path_join(tmp, bstr0(cache_dir), bstr0(cache_file));
|
||||
cache_file = mp_path_join(tmp, cache_dir, cache_file);
|
||||
|
||||
mp_mkdirp(cache_dir);
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ static void flip_page(struct vo *vo)
|
||||
image_writer_file_ext(p->opts));
|
||||
|
||||
if (p->outdir && strlen(p->outdir))
|
||||
filename = mp_path_join(t, bstr0(p->outdir), bstr0(filename));
|
||||
filename = mp_path_join(t, p->outdir, filename);
|
||||
|
||||
MP_INFO(vo, "Saving %s\n", filename);
|
||||
write_image(p->current, p->opts, filename, vo->log);
|
||||
|
Loading…
Reference in New Issue
Block a user