From 5286c7ddb8d9744ef3acad7d59dff26130c981d5 Mon Sep 17 00:00:00 2001 From: Brandon Low Date: Mon, 17 Apr 2006 20:32:25 +0000 Subject: Add copy and adjust helper for mp3entry struct as it is 1) not copy safe and 2) nonobvious that its not copy safe git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9709 a1c6a512-1295-4272-9138-f99709370657 --- firmware/export/id3.h | 2 ++ firmware/id3.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/firmware/export/id3.h b/firmware/export/id3.h index 38494044fa..cc0d422e7a 100644 --- a/firmware/export/id3.h +++ b/firmware/export/id3.h @@ -138,5 +138,7 @@ bool mp3info(struct mp3entry *entry, const char *filename, bool v1first); char* id3_get_genre(const struct mp3entry* id3); char* id3_get_codec(const struct mp3entry* id3); int getid3v2len(int fd); +void adjust_mp3entry(struct mp3entry *entry, void *dest, void *orig); +void copy_mp3entry(struct mp3entry *dest, struct mp3entry *orig); #endif diff --git a/firmware/id3.c b/firmware/id3.c index aa370e836e..1188da9fd6 100644 --- a/firmware/id3.c +++ b/firmware/id3.c @@ -1013,6 +1013,40 @@ bool mp3info(struct mp3entry *entry, const char *filename, bool v1first) return false; } +void adjust_mp3entry(struct mp3entry *entry, void *dest, void *orig) +{ + long offset; + if (orig > dest) + offset = - ((size_t)orig - (size_t)dest); + else + offset = (size_t)dest - (size_t)orig; + + if (entry->title) + entry->title += offset; + if (entry->artist) + entry->artist += offset; + if (entry->album) + entry->album += offset; + if (entry->genre_string) + entry->genre_string += offset; + if (entry->track_string) + entry->track_string += offset; + if (entry->year_string) + entry->year_string += offset; + if (entry->composer) + entry->composer += offset; + if (entry->track_gain_string) + entry->track_gain_string += offset; + if (entry->album_gain_string) + entry->album_gain_string += offset; +} + +void copy_mp3entry(struct mp3entry *dest, struct mp3entry *orig) +{ + memcpy(dest, orig, sizeof(struct mp3entry)); + adjust_mp3entry(dest, dest, orig); +} + #ifdef DEBUG_STANDALONE char *secs2str(int ms) -- cgit v1.2.3