mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-10 21:55:10 -05:00
metadata/vfx.c cleanup string and character handling
Change-Id: I7550d6db05b0d31a1433d0af9b2233f9dc3f5ee2
This commit is contained in:
parent
60933d98c6
commit
57293f1fd9
1 changed files with 19 additions and 17 deletions
|
|
@ -51,40 +51,42 @@ typedef struct {
|
||||||
#define VTX_STRING_MAX 254
|
#define VTX_STRING_MAX 254
|
||||||
|
|
||||||
static uint Reader_ReadByte(int fd) {
|
static uint Reader_ReadByte(int fd) {
|
||||||
unsigned char c;
|
unsigned char c = 0;
|
||||||
read(fd, &c, sizeof(c));
|
(void)read(fd, &c, sizeof(c));
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint Reader_ReadWord(int fd) {
|
static uint Reader_ReadWord(int fd) {
|
||||||
unsigned short s;
|
unsigned short s = 0;
|
||||||
read(fd, &s, sizeof(s));
|
(void)read(fd, &s, sizeof(s));
|
||||||
return letoh16(s);
|
return letoh16(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint Reader_ReadDWord(int fd) {
|
static uint Reader_ReadDWord(int fd) {
|
||||||
unsigned int i;
|
unsigned int i = 0;
|
||||||
read(fd, &i, sizeof(i));
|
(void)read(fd, &i, sizeof(i));
|
||||||
return letoh32(i);
|
return letoh32(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* Reader_ReadString(int fd, char *str) {
|
static char* Reader_ReadString(int fd, char *str) {
|
||||||
|
/*Note: still advances file buffer even if no string buffer supplied */
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char c = 1;
|
char ch = '\0';
|
||||||
char *p = str;
|
char *p = str;
|
||||||
|
|
||||||
if (str)
|
while (i < VTX_STRING_MAX && (ch || i == 0))
|
||||||
*str = 0;
|
{
|
||||||
|
if (read(fd, &ch, sizeof(ch) == sizeof(ch)))
|
||||||
while (i < VTX_STRING_MAX && c) {
|
{
|
||||||
read(fd, &c, sizeof(c));
|
if (str)
|
||||||
if (str)
|
*str++ = ch;
|
||||||
*str++ = c;
|
}
|
||||||
i++;
|
else
|
||||||
|
break;
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str)
|
if (str)
|
||||||
*str = 0;
|
*str = '\0';
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue