aboutsummaryrefslogtreecommitdiffstats
path: root/src/stored_playlist.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-01 19:17:44 +0100
committerMax Kellermann <max@duempel.org>2009-01-01 19:17:44 +0100
commit80fa9183e4d30643b1e089d9b96f36a4b266276e (patch)
treeefaa0e4579cb5b7fc6da6610f3485072f384c609 /src/stored_playlist.c
parent886ed1b225d50e5e6c220e11b5800f45d36a5d37 (diff)
downloadmpd-80fa9183e4d30643b1e089d9b96f36a4b266276e.tar.gz
mpd-80fa9183e4d30643b1e089d9b96f36a4b266276e.tar.xz
mpd-80fa9183e4d30643b1e089d9b96f36a4b266276e.zip
mapper: allocate playlist path from heap
Don't pass a static buffer to map_spl_utf8_to_fs().
Diffstat (limited to 'src/stored_playlist.c')
-rw-r--r--src/stored_playlist.c69
1 files changed, 41 insertions, 28 deletions
diff --git a/src/stored_playlist.c b/src/stored_playlist.c
index 545ecc158..534b40d2a 100644
--- a/src/stored_playlist.c
+++ b/src/stored_playlist.c
@@ -115,14 +115,14 @@ static enum playlist_result
spl_save(GPtrArray *list, const char *utf8path)
{
FILE *file;
- char path_max_tmp[MPD_PATH_MAX];
- const char *path_fs;
+ char *path_fs;
assert(utf8path != NULL);
- path_fs = map_spl_utf8_to_fs(utf8path, path_max_tmp);
+ path_fs = map_spl_utf8_to_fs(utf8path);
while (!(file = fopen(path_fs, "w")) && errno == EINTR);
+ g_free(path_fs);
if (file == NULL)
return PLAYLIST_RESULT_ERRNO;
@@ -142,14 +142,15 @@ spl_load(const char *utf8path)
GPtrArray *list;
char buffer[MPD_PATH_MAX];
char path_max_tmp[MPD_PATH_MAX];
- const char *path_fs;
+ char *path_fs;
if (!is_valid_playlist_name(utf8path))
return NULL;
- path_fs = map_spl_utf8_to_fs(utf8path, path_max_tmp);
+ path_fs = map_spl_utf8_to_fs(utf8path);
while (!(file = fopen(path_fs, "r")) && errno == EINTR);
+ g_free(path_fs);
if (file == NULL)
return NULL;
@@ -257,16 +258,16 @@ spl_move_index(const char *utf8path, unsigned src, unsigned dest)
enum playlist_result
spl_clear(const char *utf8path)
{
- char filename[MPD_PATH_MAX];
- const char *path_fs;
+ char *path_fs;
FILE *file;
if (!is_valid_playlist_name(utf8path))
return PLAYLIST_RESULT_BAD_NAME;
- path_fs = map_spl_utf8_to_fs(utf8path, filename);
+ path_fs = map_spl_utf8_to_fs(utf8path);
while (!(file = fopen(path_fs, "w")) && errno == EINTR);
+ g_free(path_fs);
if (file == NULL)
return PLAYLIST_RESULT_ERRNO;
@@ -279,12 +280,13 @@ spl_clear(const char *utf8path)
enum playlist_result
spl_delete(const char *name_utf8)
{
- char filename[MPD_PATH_MAX];
- const char *path_fs;
-
- path_fs = map_spl_utf8_to_fs(name_utf8, filename);
+ char *path_fs;
+ int ret;
- if (unlink(path_fs) < 0)
+ path_fs = map_spl_utf8_to_fs(name_utf8);
+ ret = unlink(path_fs);
+ g_free(path_fs);
+ if (ret < 0)
return errno == ENOENT
? PLAYLIST_RESULT_NO_SUCH_LIST
: PLAYLIST_RESULT_ERRNO;
@@ -323,15 +325,15 @@ spl_append_song(const char *utf8path, struct song *song)
{
FILE *file;
struct stat st;
- char path_max_tmp[MPD_PATH_MAX];
- const char *path_fs;
+ char *path_fs;
if (!is_valid_playlist_name(utf8path))
return PLAYLIST_RESULT_BAD_NAME;
- path_fs = map_spl_utf8_to_fs(utf8path, path_max_tmp);
+ path_fs = map_spl_utf8_to_fs(utf8path);
while (!(file = fopen(path_fs, "a")) && errno == EINTR);
+ g_free(path_fs);
if (file == NULL) {
int save_errno = errno;
while (fclose(file) != 0 && errno == EINTR);
@@ -381,20 +383,10 @@ spl_append_uri(const char *url, const char *utf8file)
return PLAYLIST_RESULT_NO_SUCH_SONG;
}
-enum playlist_result
-spl_rename(const char *utf8from, const char *utf8to)
+static enum playlist_result
+spl_rename_internal(const char *from_path_fs, const char *to_path_fs)
{
struct stat st;
- char from[MPD_PATH_MAX];
- char to[MPD_PATH_MAX];
- const char *from_path_fs, *to_path_fs;
-
- if (!is_valid_playlist_name(utf8from) ||
- !is_valid_playlist_name(utf8to))
- return PLAYLIST_RESULT_BAD_NAME;
-
- from_path_fs = map_spl_utf8_to_fs(utf8from, from);
- to_path_fs = map_spl_utf8_to_fs(utf8to, to);
if (stat(from_path_fs, &st) != 0)
return PLAYLIST_RESULT_NO_SUCH_LIST;
@@ -408,3 +400,24 @@ spl_rename(const char *utf8from, const char *utf8to)
idle_add(IDLE_STORED_PLAYLIST);
return PLAYLIST_RESULT_SUCCESS;
}
+
+enum playlist_result
+spl_rename(const char *utf8from, const char *utf8to)
+{
+ char *from_path_fs, *to_path_fs;
+ static enum playlist_result ret;
+
+ if (!is_valid_playlist_name(utf8from) ||
+ !is_valid_playlist_name(utf8to))
+ return PLAYLIST_RESULT_BAD_NAME;
+
+ from_path_fs = map_spl_utf8_to_fs(utf8from);
+ to_path_fs = map_spl_utf8_to_fs(utf8to);
+
+ ret = spl_rename_internal(from_path_fs, to_path_fs);
+
+ g_free(from_path_fs);
+ g_free(to_path_fs);
+
+ return ret;
+}