Use id3v2buf to read the title of MOD files. Avoids additional declaration of a 1KB buffer and saves a bit codesize as well.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30105 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Andree Buschmann 2011-06-30 18:39:13 +00:00
parent 617d1e9f6b
commit 1a1ac92f45

View file

@ -35,17 +35,20 @@
bool get_mod_metadata(int fd, struct mp3entry* id3)
{
/* Use the trackname part of the id3 structure as a temporary buffer */
unsigned char buf[MODULEHEADERSIZE];
unsigned char *buf = id3->id3v2buf;
unsigned char id[4];
bool is_mod_file = false;
char *p;
if ((lseek(fd, 0, SEEK_SET) < 0)
|| (read(fd, buf, sizeof(buf)) < MODULEHEADERSIZE))
{
/* Seek to file begin */
if (lseek(fd, 0, SEEK_SET) < 0)
return false;
}
/* Use id3v2buf as buffer for the track name */
if (read(fd, buf, sizeof(id3->id3v2buf)) < (ssize_t)sizeof(id3->id3v2buf))
return false;
/* Seek to MOD ID position */
if (lseek(fd, MODULEHEADERSIZE, SEEK_SET) < 0)
return false;
/* Read MOD ID */
if (read(fd, id, sizeof(id)) < (ssize_t)sizeof(id))
return false;
@ -88,14 +91,7 @@ bool get_mod_metadata(int fd, struct mp3entry* id3)
if (!is_mod_file)
return false;
p = id3->id3v2buf;
/* Copy Title */
if (strlcpy(p, buf, sizeof(id3->id3v2buf)) >= sizeof(id3->id3v2buf))
return false;
id3->title = p;
id3->title = id3->id3v2buf; /* Point title to previous read ID3 buffer. */
id3->bitrate = filesize(fd)/1024; /* size in kb */
id3->frequency = 44100;
id3->length = 120*1000;