path: removed pfx_dir()
Use GLib's g_build_filename() instead of pfx_dir().
This commit is contained in:
parent
1a04e57168
commit
da69382273
17
src/path.c
17
src/path.c
|
@ -107,20 +107,3 @@ void path_global_finish(void)
|
|||
{
|
||||
g_free(fs_charset);
|
||||
}
|
||||
|
||||
char *pfx_dir(char *dst,
|
||||
const char *path, const size_t path_len,
|
||||
const char *pfx, const size_t pfx_len)
|
||||
{
|
||||
if (G_UNLIKELY((pfx_len + path_len + 1) >= MPD_PATH_MAX))
|
||||
g_error("Cannot prefix '%s' to '%s', PATH_MAX: %d",
|
||||
pfx, path, MPD_PATH_MAX);
|
||||
|
||||
/* memmove allows dst == path */
|
||||
memmove(dst + pfx_len + 1, path, path_len + 1);
|
||||
memcpy(dst, pfx, pfx_len);
|
||||
dst[pfx_len] = '/';
|
||||
|
||||
/* this is weird, but directory.c can use it more safely/efficiently */
|
||||
return (dst + pfx_len + 1);
|
||||
}
|
||||
|
|
12
src/path.h
12
src/path.h
|
@ -44,16 +44,4 @@ void path_set_fs_charset(const char *charset);
|
|||
|
||||
const char *path_get_fs_charset(void);
|
||||
|
||||
/*
|
||||
* pfx_dir - sets dst="$pfx/$path" and returns a pointer to path inside * dst
|
||||
* this will unconditionally put a '/' between pfx and path unlike
|
||||
* the static pfx_path() function in path.c
|
||||
* dst is assumed to be MAXPATHLEN in size
|
||||
* dst can point to the same location as path, but not pfx, which makes
|
||||
* this better than sprintf(3) in some cases
|
||||
*/
|
||||
char *pfx_dir(char *dst,
|
||||
const char *path, const size_t path_len,
|
||||
const char *pfx, const size_t pfx_len);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -37,13 +37,12 @@ static struct stored_playlist_info *
|
|||
load_playlist_info(const char *parent_path_fs, const char *name_fs)
|
||||
{
|
||||
size_t name_length = strlen(name_fs);
|
||||
char buffer[MPD_PATH_MAX], *name, *name_utf8;
|
||||
char buffer[MPD_PATH_MAX], *path_fs, *name, *name_utf8;
|
||||
int ret;
|
||||
struct stat st;
|
||||
struct stored_playlist_info *playlist;
|
||||
|
||||
if (name_length < 1 + sizeof(PLAYLIST_FILE_SUFFIX) ||
|
||||
strlen(parent_path_fs) + name_length >= sizeof(buffer) ||
|
||||
memchr(name_fs, '\n', name_length) != NULL)
|
||||
return NULL;
|
||||
|
||||
|
@ -53,10 +52,9 @@ load_playlist_info(const char *parent_path_fs, const char *name_fs)
|
|||
sizeof(PLAYLIST_FILE_SUFFIX) - 1) != 0)
|
||||
return NULL;
|
||||
|
||||
pfx_dir(buffer, name_fs, name_length,
|
||||
parent_path_fs, strlen(parent_path_fs));
|
||||
|
||||
ret = stat(buffer, &st);
|
||||
path_fs = g_build_filename(parent_path_fs, name_fs, NULL);
|
||||
ret = stat(path_fs, &st);
|
||||
g_free(path_fs);
|
||||
if (ret < 0 || !S_ISREG(st.st_mode))
|
||||
return NULL;
|
||||
|
||||
|
|
12
src/update.c
12
src/update.c
|
@ -288,16 +288,16 @@ make_subdir(struct directory *parent, const char *name)
|
|||
|
||||
directory = directory_get_child(parent, name);
|
||||
if (directory == NULL) {
|
||||
char path[MPD_PATH_MAX];
|
||||
char *path;
|
||||
|
||||
if (directory_is_root(parent))
|
||||
strcpy(path, name);
|
||||
path = NULL;
|
||||
else
|
||||
pfx_dir(path, name, strlen(name),
|
||||
directory_get_path(parent),
|
||||
strlen(directory_get_path(parent)));
|
||||
name = path = g_strconcat(directory_get_path(parent),
|
||||
"/", name, NULL);
|
||||
|
||||
directory = directory_new_child(parent, path);
|
||||
directory = directory_new_child(parent, name);
|
||||
g_free(path);
|
||||
}
|
||||
|
||||
return directory;
|
||||
|
|
Loading…
Reference in New Issue