aboutsummaryrefslogtreecommitdiffstats
path: root/src/song_save.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-14 13:43:57 +0100
committerMax Kellermann <max@duempel.org>2009-01-14 13:43:57 +0100
commit3c6a85d8f7f68b5f85eca0c7f8363ae520154bd0 (patch)
tree3b14ddae69327f0c27b9c5c635dcd19d90d9c163 /src/song_save.c
parent7cc9ba45a9d9137f1bed26e427fea17910cd5eb6 (diff)
downloadmpd-3c6a85d8f7f68b5f85eca0c7f8363ae520154bd0.tar.gz
mpd-3c6a85d8f7f68b5f85eca0c7f8363ae520154bd0.tar.xz
mpd-3c6a85d8f7f68b5f85eca0c7f8363ae520154bd0.zip
song_save: return value pointer from matchesAnMpdTagItemKey()
The matchesAnMpdTagItemKey() API becomes more powerful and flexible if the return value is the value pointer instead of a boolean. It also removes (invalid and dangerous) assumptions about the string from its caller.
Diffstat (limited to 'src/song_save.c')
-rw-r--r--src/song_save.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/song_save.c b/src/song_save.c
index 30a095dfe..eecdd7634 100644
--- a/src/song_save.c
+++ b/src/song_save.c
@@ -86,7 +86,8 @@ insertSongIntoList(struct songvec *sv, struct song *newsong)
}
}
-static int matchesAnMpdTagItemKey(char *buffer, enum tag_type *itemType)
+static char *
+matchesAnMpdTagItemKey(char *buffer, enum tag_type *itemType)
{
int i;
@@ -96,11 +97,11 @@ static int matchesAnMpdTagItemKey(char *buffer, enum tag_type *itemType)
if (0 == strncmp(mpdTagItemKeys[i], buffer, len) &&
buffer[len] == ':' && buffer[len + 1] == ' ') {
*itemType = i;
- return 1;
+ return buffer + len + 2;
}
}
- return 0;
+ return NULL;
}
void readSongInfoIntoList(FILE *fp, struct songvec *sv,
@@ -109,6 +110,7 @@ void readSongInfoIntoList(FILE *fp, struct songvec *sv,
char buffer[MPD_PATH_MAX + 1024];
struct song *song = NULL;
enum tag_type itemType;
+ const char *value;
while (fgets(buffer, sizeof(buffer), fp) &&
!g_str_has_prefix(buffer, SONG_END)) {
@@ -126,16 +128,14 @@ void readSongInfoIntoList(FILE *fp, struct songvec *sv,
FATAL("Problems reading song info\n");
} else if (0 == strncmp(SONG_FILE, buffer, strlen(SONG_FILE))) {
/* we don't need this info anymore */
- } else if (matchesAnMpdTagItemKey(buffer, &itemType)) {
+ } else if ((value = matchesAnMpdTagItemKey(buffer,
+ &itemType)) != NULL) {
if (!song->tag) {
song->tag = tag_new();
tag_begin_add(song->tag);
}
- tag_add_item(song->tag, itemType,
- &(buffer
- [strlen(mpdTagItemKeys[itemType]) +
- 2]));
+ tag_add_item(song->tag, itemType, value);
} else if (0 == strncmp(SONG_TIME, buffer, strlen(SONG_TIME))) {
if (!song->tag) {
song->tag = tag_new();