path: removed pfx_dir()
Use GLib's g_build_filename() instead of pfx_dir().
This commit is contained in:
17
src/path.c
17
src/path.c
@@ -107,20 +107,3 @@ void path_global_finish(void)
|
|||||||
{
|
{
|
||||||
g_free(fs_charset);
|
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);
|
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
|
#endif
|
||||||
|
@@ -37,13 +37,12 @@ static struct stored_playlist_info *
|
|||||||
load_playlist_info(const char *parent_path_fs, const char *name_fs)
|
load_playlist_info(const char *parent_path_fs, const char *name_fs)
|
||||||
{
|
{
|
||||||
size_t name_length = strlen(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;
|
int ret;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
struct stored_playlist_info *playlist;
|
struct stored_playlist_info *playlist;
|
||||||
|
|
||||||
if (name_length < 1 + sizeof(PLAYLIST_FILE_SUFFIX) ||
|
if (name_length < 1 + sizeof(PLAYLIST_FILE_SUFFIX) ||
|
||||||
strlen(parent_path_fs) + name_length >= sizeof(buffer) ||
|
|
||||||
memchr(name_fs, '\n', name_length) != NULL)
|
memchr(name_fs, '\n', name_length) != NULL)
|
||||||
return 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)
|
sizeof(PLAYLIST_FILE_SUFFIX) - 1) != 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
pfx_dir(buffer, name_fs, name_length,
|
path_fs = g_build_filename(parent_path_fs, name_fs, NULL);
|
||||||
parent_path_fs, strlen(parent_path_fs));
|
ret = stat(path_fs, &st);
|
||||||
|
g_free(path_fs);
|
||||||
ret = stat(buffer, &st);
|
|
||||||
if (ret < 0 || !S_ISREG(st.st_mode))
|
if (ret < 0 || !S_ISREG(st.st_mode))
|
||||||
return NULL;
|
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);
|
directory = directory_get_child(parent, name);
|
||||||
if (directory == NULL) {
|
if (directory == NULL) {
|
||||||
char path[MPD_PATH_MAX];
|
char *path;
|
||||||
|
|
||||||
if (directory_is_root(parent))
|
if (directory_is_root(parent))
|
||||||
strcpy(path, name);
|
path = NULL;
|
||||||
else
|
else
|
||||||
pfx_dir(path, name, strlen(name),
|
name = path = g_strconcat(directory_get_path(parent),
|
||||||
directory_get_path(parent),
|
"/", name, NULL);
|
||||||
strlen(directory_get_path(parent)));
|
|
||||||
|
|
||||||
directory = directory_new_child(parent, path);
|
directory = directory_new_child(parent, name);
|
||||||
|
g_free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return directory;
|
return directory;
|
||||||
|
Reference in New Issue
Block a user