metadata/metadata_common.c WS changes

Change-Id: Ieef86e94676c603a21cbb5af55e63ba628a09cdf
This commit is contained in:
William Wilgus 2021-08-11 22:16:19 -04:00
parent 7aa0e0a898
commit f05a7a10a6

View file

@ -30,7 +30,7 @@
#include "metadata_parsers.h" #include "metadata_parsers.h"
#include "replaygain.h" #include "replaygain.h"
/* Read a string from the file. Read up to size bytes, or, if eos != -1, /* Read a string from the file. Read up to size bytes, or, if eos != -1,
* until the eos character is found (eos is not stored in buf, unless it is * until the eos character is found (eos is not stored in buf, unless it is
* nil). Writes up to buf_size chars to buf, always terminating with a nil. * nil). Writes up to buf_size chars to buf, always terminating with a nil.
* Returns number of chars read or -1 on read error. * Returns number of chars read or -1 on read error.
@ -39,7 +39,7 @@ long read_string(int fd, char* buf, long buf_size, int eos, long size)
{ {
long read_bytes = 0; long read_bytes = 0;
char c; char c;
while (size != 0) while (size != 0)
{ {
if (read(fd, &c, 1) != 1) if (read(fd, &c, 1) != 1)
@ -47,22 +47,22 @@ long read_string(int fd, char* buf, long buf_size, int eos, long size)
read_bytes = -1; read_bytes = -1;
break; break;
} }
read_bytes++; read_bytes++;
size--; size--;
if ((eos != -1) && (eos == (unsigned char) c)) if ((eos != -1) && (eos == (unsigned char) c))
{ {
break; break;
} }
if (buf_size > 1) if (buf_size > 1)
{ {
*buf++ = c; *buf++ = c;
buf_size--; buf_size--;
} }
} }
*buf = 0; *buf = 0;
return read_bytes; return read_bytes;
} }
@ -198,31 +198,31 @@ uint32_t get_itunes_int32(char* value, int count)
static const char hexdigits[] = "0123456789ABCDEF"; static const char hexdigits[] = "0123456789ABCDEF";
const char* c; const char* c;
int r = 0; int r = 0;
while (count-- > 0) while (count-- > 0)
{ {
while (isspace(*value)) while (isspace(*value))
{ {
value++; value++;
} }
while (*value && !isspace(*value)) while (*value && !isspace(*value))
{ {
value++; value++;
} }
} }
while (isspace(*value)) while (isspace(*value))
{ {
value++; value++;
} }
while (*value && ((c = strchr(hexdigits, toupper(*value))) != NULL)) while (*value && ((c = strchr(hexdigits, toupper(*value))) != NULL))
{ {
r = (r << 4) | (c - hexdigits); r = (r << 4) | (c - hexdigits);
value++; value++;
} }
return r; return r;
} }
@ -243,9 +243,9 @@ bool skip_id3v2(int fd, struct mp3entry *id3)
if ((id3->first_frame_offset = getid3v2len(fd)) == 0) if ((id3->first_frame_offset = getid3v2len(fd)) == 0)
return false; return false;
if ((lseek(fd, id3->first_frame_offset, SEEK_SET) < 0)) if ((lseek(fd, id3->first_frame_offset, SEEK_SET) < 0))
return false; return false;
return true; return true;
} else { } else {
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
@ -278,7 +278,7 @@ long parse_tag(const char* name, char* value, struct mp3entry* id3,
else if (((strcasecmp(name, "year") == 0) && (type == TAGTYPE_APE)) else if (((strcasecmp(name, "year") == 0) && (type == TAGTYPE_APE))
|| ((strcasecmp(name, "date") == 0) && (type == TAGTYPE_VORBIS))) || ((strcasecmp(name, "date") == 0) && (type == TAGTYPE_VORBIS)))
{ {
/* Date's can be in any format in Vorbis. However most of them /* Date's can be in any format in Vorbis. However most of them
* are in ISO8601 format so if we try and parse the first part * are in ISO8601 format so if we try and parse the first part
* of the tag as a number, we should get the year. If we get crap, * of the tag as a number, we should get the year. If we get crap,
* then act like we never parsed it. * then act like we never parsed it.
@ -334,7 +334,7 @@ long parse_tag(const char* name, char* value, struct mp3entry* id3,
{ {
p = &(id3->grouping); p = &(id3->grouping);
} }
else if (strcasecmp(name, "contentgroup") == 0) else if (strcasecmp(name, "contentgroup") == 0)
{ {
p = &(id3->grouping); p = &(id3->grouping);
} }
@ -348,9 +348,9 @@ long parse_tag(const char* name, char* value, struct mp3entry* id3,
parse_replaygain(name, value, id3); parse_replaygain(name, value, id3);
p = NULL; p = NULL;
} }
/* Do not overwrite already available metadata. Especially when reading /* Do not overwrite already available metadata. Especially when reading
* tags with e.g. multiple genres / artists. This way only the first * tags with e.g. multiple genres / artists. This way only the first
* of multiple entries is used, all following are dropped. */ * of multiple entries is used, all following are dropped. */
if (p!=NULL && *p==NULL) if (p!=NULL && *p==NULL)
{ {
@ -369,6 +369,6 @@ long parse_tag(const char* name, char* value, struct mp3entry* id3,
len = 0; len = 0;
} }
} }
return len; return len;
} }