#include <string.h>
#include <unistd.h>
+#define BE_4BYTE(a) ((((unsigned char*)a)[0] << 24) | \
+ (((unsigned char*)a)[1] << 16) | \
+ (((unsigned char*)a)[2] << 8) | \
+ ((unsigned char*)a)[3])
+#define BE_2BYTE(a) ((((unsigned char*)a)[0] << 8) | ((unsigned char*)a)[1])
+
enum StreamTypes {
STREAM_TYPE_UNKNOWN = 0,
STREAM_TYPE_AUDIO,
}
/* convert to host byte order */
- file_header->size = ntohl(file_header->size);
+ file_header->size = BE_4BYTE(&file_header->size);
#if 0
fprintf(stderr, "file_header type=%.*s\n", 4, file_header->type);
if (read(fd, size, 4) != 4)
return -1;
- *size = ntohl(*size);
+ *size = BE_4BYTE(size);
#if 0
fprintf(stderr, "header type=%.*s\n", 4, type);
}
static int
-_read_string(int fd, char **out, int *out_len)
+_read_string(int fd, char **out, unsigned int *out_len)
{
char *s;
uint16_t len;
if (read(fd, &len, 2) == -1)
return -1;
- len = ntohs(len);
+ len = BE_2BYTE(&len);
if (out) {
if (len > 0) {
- s = malloc(sizeof(char) * len + 1);
+ s = malloc(sizeof(char) * (len + 1));
if (read(fd, s, len) == -1) {
free(s);
return -1;
}
s[len] = '\0';
*out = s;
- }
- else {
+ } else
*out = NULL;
- }
*out_len = len;
- }
- else {
+ } else
lseek(fd, len, SEEK_CUR);
- }
+
+ return 0;
}
/*
* word Comment string length
* byte[] Comment string
*/
-static int
+static void
_parse_cont_header(int fd, struct rm_info *info)
{
- uint16_t version;
- uint16_t title_len;
- char *title;
-
/* Ps.: type and size were already read */
/* ignore version */