return 0;
}
-#define LE_4BYTE(a) ((a)[0] | ((a)[1] << 8) | ((a)[2] << 16) | ((a)[3] << 24))
-#define BE_4BYTE(a) (((a)[0] << 24) | ((a)[1] << 16) | ((a)[2] << 8) | (a)[3])
-
-#define LE_2BYTE(a) ((a)[0] | ((a)[1] << 8))
-#define BE_2BYTE(a) (((a)[0] << 8) | (a)[1])
-
-#define E_2BTYE(little_endian, a) ((little_endian) ? LE_2BYTE(a) : BE_2BYTE(a))
-#define E_4BTYE(little_endian, a) ((little_endian) ? LE_4BYTE(a) : BE_4BYTE(a))
+#define E_2BTYE(little_endian, a) ((little_endian) ? get_le16(a) : get_be16(a))
+#define E_4BTYE(little_endian, a) ((little_endian) ? get_le32(a) : get_be32(a))
enum {
EXIF_TYPE_BYTE = 1, /* 8 bit unsigned */
}
if (little_endian) {
- ifd->tag = LE_2BYTE(buf);
- ifd->type = LE_2BYTE(buf + 2);
- ifd->count = LE_4BYTE(buf + 4);
- ifd->offset = LE_4BYTE(buf + 8);
+ ifd->tag = get_le16(buf);
+ ifd->type = get_le16(buf + 2);
+ ifd->count = get_le32(buf + 4);
+ ifd->offset = get_le32(buf + 8);
} else {
- ifd->tag = BE_2BYTE(buf);
- ifd->type = BE_2BYTE(buf + 2);
- ifd->count = BE_4BYTE(buf + 4);
- ifd->offset = BE_4BYTE(buf + 8);
+ ifd->tag = get_be16(buf);
+ ifd->type = get_be16(buf + 2);
+ ifd->count = get_be32(buf + 4);
+ ifd->offset = get_be32(buf + 8);
}
return 0;
}
if (buf[0] == 'I' && buf[1] == 'I') {
little_endian = 1;
- offset = LE_4BYTE(buf + 4);
+ offset = get_le32(buf + 4);
} else if (buf[0] == 'M' && buf[1] == 'M') {
little_endian = 0;
- offset = BE_4BYTE(buf + 4);
+ offset = get_be32(buf + 4);
} else {
fprintf(stderr, "ERROR: undefined byte sex \"%2.2s\".\n", buf);
return -5;
#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,
return -1;
}
- /* convert to host byte order */
- file_header->size = BE_4BYTE(&file_header->size);
+ file_header->size = be32toh(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 = BE_4BYTE(size);
+ *size = be32toh(*size);
#if 0
fprintf(stderr, "header type=%.*s\n", 4, type);
if (read(fd, &len, 2) == -1)
return -1;
- len = BE_2BYTE(&len);
+ len = be16toh(len);
if (out) {
if (len > 0) {