Skip to content

Commit f4b253a

Browse files
committed
openbsd build: renaming byte order routines
1 parent 7a4054f commit f4b253a

File tree

5 files changed

+94
-94
lines changed

5 files changed

+94
-94
lines changed

noson/src/filepicreader.cpp

+24-24
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ FilePicReader::Picture * FilePicReader::ExtractFLACPicture(const std::string& fi
240240
// get last block flag. if true next loop will stop
241241
isLast = ((*buf & 0x80) != 0);
242242
// get the current block size
243-
unsigned v = (read32be(buf) & 0xffffff) - 4;
243+
unsigned v = (read_b32be(buf) & 0xffffff) - 4;
244244
if (v > MAX_PICTURE_SIZE)
245245
break;
246246

@@ -250,17 +250,17 @@ FilePicReader::Picture * FilePicReader::ExtractFLACPicture(const std::string& fi
250250
{
251251
DBG(DBG_PROTO, "%s: picture type (%.2x)\n", __FUNCTION__, buf[7]);
252252
// check picture type matches with requirement
253-
if (read32be(buf + 4) == pictureType || pictureType == -1)
253+
if (read_b32be(buf + 4) == pictureType || pictureType == -1)
254254
{
255255
unsigned mime_type_len;
256256
unsigned desc_len;
257257
unsigned data_len;
258258
char * picbuf = new char [v];
259259
// read data block and check for sanity
260260
if (fread(picbuf, 1, v, file) != v ||
261-
(mime_type_len = read32be(picbuf)) > v - 4 ||
262-
(desc_len = read32be(picbuf + 4 + mime_type_len)) > v - 8 - mime_type_len ||
263-
(data_len = read32be(picbuf + mime_type_len + desc_len + 24)) > v - 28 - desc_len - mime_type_len)
261+
(mime_type_len = read_b32be(picbuf)) > v - 4 ||
262+
(desc_len = read_b32be(picbuf + 4 + mime_type_len)) > v - 8 - mime_type_len ||
263+
(data_len = read_b32be(picbuf + mime_type_len + desc_len + 24)) > v - 28 - desc_len - mime_type_len)
264264
{
265265
delete [] picbuf;
266266
break;
@@ -384,20 +384,20 @@ static inline void _parse_id3v2_frame_header(char * data, unsigned int version,
384384
case 2:
385385
memcpy(fh->frame_id, data, 3);
386386
fh->frame_id[3] = 0;
387-
fh->frame_size = (unsigned)read24be(data + 3);
387+
fh->frame_size = (unsigned)read_b24be(data + 3);
388388
fh->compression = 0;
389389
fh->data_length_indicator = 0;
390390
break;
391391
case 3:
392392
memcpy(fh->frame_id, data, 4);
393-
fh->frame_size = (unsigned)read32be(data + 4);
393+
fh->frame_size = (unsigned)read_b32be(data + 4);
394394
fh->compression = data[9] & 0x40;
395395
fh->data_length_indicator = 0;
396396
break;
397397
case 4:
398398
default:
399399
memcpy(fh->frame_id, data, 4);
400-
fh->frame_size = (unsigned)read32be(data + 4);
400+
fh->frame_size = (unsigned)read_b32be(data + 4);
401401
fh->compression = data[9] & 0x4;
402402
fh->data_length_indicator = data[9] & 0x1;
403403
break;
@@ -671,7 +671,7 @@ int FilePicReader::parse_id3v2(FILE * file, long id3v2_offset, Picture ** pic, o
671671
if (fread(extended_header_data, 1, 6, file) != 6)
672672
return -1;
673673

674-
extended_header_size = (unsigned)read32be(extended_header_data);
674+
extended_header_size = (unsigned)read_b32be(extended_header_data);
675675

676676
fseek(file, extended_header_size - 6, SEEK_CUR);
677677
frame_data_pos += extended_header_size;
@@ -766,8 +766,8 @@ FilePicReader::Picture * FilePicReader::ExtractOGGSPicture(const std::string& fi
766766
break;
767767
}
768768
//char stream_structure_version = read8(buf + 4);
769-
unsigned char header_type_flag = (unsigned char)read8(buf + 5);
770-
unsigned char number_page_segments = (unsigned char)read8(buf + 26);
769+
unsigned char header_type_flag = (unsigned char)read_b8(buf + 5);
770+
unsigned char number_page_segments = (unsigned char)read_b8(buf + 26);
771771

772772
uint32_t segment_table = 0;
773773
if (fread(lacing, 1, number_page_segments, file) != number_page_segments)
@@ -777,7 +777,7 @@ FilePicReader::Picture * FilePicReader::ExtractOGGSPicture(const std::string& fi
777777
}
778778

779779
for (int i = 0; i < number_page_segments; ++i)
780-
segment_table += (unsigned char)read8(lacing + i);
780+
segment_table += (unsigned char)read_b8(lacing + i);
781781

782782
// bit 0x04: this is the last page of a logical bitstream (eos)
783783
if ((header_type_flag & 0x04) == 0x04)
@@ -828,7 +828,7 @@ FilePicReader::Picture * FilePicReader::ExtractOGGSPicture(const std::string& fi
828828
}
829829

830830
// check for vorbis comment header
831-
unsigned char block = (unsigned char)read8(packet.data);
831+
unsigned char block = (unsigned char)read_b8(packet.data);
832832
if (block == 0x03 && packet.datalen > 7 &&
833833
memcmp(packet.data + 1, "vorbis", 6) == 0)
834834
{
@@ -895,12 +895,12 @@ bool FilePicReader::parse_comment(packet_t * packet, Picture ** pic, PictureType
895895
bool gotoLast = false;
896896
unsigned char * ve = packet->data + packet->datalen;
897897
unsigned char * vp = packet->data + 7; // pass magic string
898-
vp += read32le(vp) + 4; // pass vendor string
899-
int count = read32le(vp); // comment list length;
898+
vp += read_b32le(vp) + 4; // pass vendor string
899+
int count = read_b32le(vp); // comment list length;
900900
vp += 4;
901901
while (count > 0)
902902
{
903-
int len = read32le(vp);
903+
int len = read_b32le(vp);
904904
vp += 4;
905905
if ((vp + len) > ve)
906906
break; // buffer overflow
@@ -911,15 +911,15 @@ bool FilePicReader::parse_comment(packet_t * packet, Picture ** pic, PictureType
911911
char * picbuf = nullptr;
912912
size_t lenbuf = Base64::b64decode(vp + 23, len - 23, &picbuf);
913913
// check picture type matches with requirement
914-
if (lenbuf > 8 && (read32be(picbuf) == pictureType || pictureType == -1))
914+
if (lenbuf > 8 && (read_b32be(picbuf) == pictureType || pictureType == -1))
915915
{
916916
unsigned mime_type_len;
917917
unsigned desc_len;
918918
unsigned data_len;
919919
// check for sanity
920-
if ((mime_type_len = read32be(picbuf + 4)) > lenbuf - 8 ||
921-
(desc_len = read32be(picbuf + 8 + mime_type_len)) > lenbuf - 12 - mime_type_len ||
922-
(data_len = read32be(picbuf + mime_type_len + desc_len + 28)) > lenbuf - 32 - desc_len - mime_type_len)
920+
if ((mime_type_len = read_b32be(picbuf + 4)) > lenbuf - 8 ||
921+
(desc_len = read_b32be(picbuf + 8 + mime_type_len)) > lenbuf - 12 - mime_type_len ||
922+
(data_len = read_b32be(picbuf + mime_type_len + desc_len + 28)) > lenbuf - 32 - desc_len - mime_type_len)
923923
{
924924
delete [] picbuf;
925925
break;
@@ -1015,15 +1015,15 @@ int FilePicReader::nextChild(unsigned char * buf, uint64_t * remaining, FILE * f
10151015
if (fread(buf, 1, M4A_HEADER_SIZE, fp) == M4A_HEADER_SIZE)
10161016
{
10171017
*remaining -= M4A_HEADER_SIZE;
1018-
*child = (unsigned)read32be(buf + 4);
1019-
*childSize = (uint32_t)read32be(buf);
1018+
*child = (unsigned)read_b32be(buf + 4);
1019+
*childSize = (uint32_t)read_b32be(buf);
10201020
if (*childSize == 1)
10211021
{
10221022
// size of 1 means the real size follows the header in next 8 bytes (64bits)
10231023
if (*remaining < 8 || fread(buf, 1, 8, fp) != 8)
10241024
return -1; // error
10251025
*remaining -= 8;
1026-
*childSize = (((uint64_t)read32be(buf) << 32) | (uint32_t)read32be(buf + 4)) - M4A_HEADER_SIZE - 8;
1026+
*childSize = (((uint64_t)read_b32be(buf) << 32) | (uint32_t)read_b32be(buf + 4)) - M4A_HEADER_SIZE - 8;
10271027
}
10281028
else
10291029
{
@@ -1054,7 +1054,7 @@ int FilePicReader::loadDataValue(uint64_t * remaining, FILE * fp, char ** alloc,
10541054
*remaining -= size;
10551055
*allocSize = size;
10561056
*alloc = _alloc;
1057-
return (read32be(_alloc) & 0x00ffffff); // return datatype
1057+
return (read_b32be(_alloc) & 0x00ffffff); // return datatype
10581058
}
10591059
return r;
10601060
}

noson/src/flacencoder.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,14 @@ int FLACEncoder::encode(const char * data, int len)
180180
m_pcm[i] = (unsigned char)(*data) - 128;
181181
break;
182182
case 16:
183-
m_pcm[i] = read16le(data);
183+
m_pcm[i] = read_b16le(data);
184184
break;
185185
case 24:
186-
m_pcm[i] = read24le(data);
186+
m_pcm[i] = read_b24le(data);
187187
break;
188188
case 32:
189189
// remove lower LSB
190-
m_pcm[i] = (read32le(data) >> 8);
190+
m_pcm[i] = (read_b32le(data) >> 8);
191191
break;
192192
default:
193193
m_pcm[i] = 0;

noson/src/private/byteorder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ static int test_endianess() {
2323
return (*((char*)(&test))) ? LITTLE_ENDIAN : BIG_ENDIAN;
2424
}
2525

26-
int __endianess__ = test_endianess();
26+
int machine_bom = test_endianess();

noson/src/private/byteorder.h

+24-24
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
#ifndef BYTE_ORDER
2626
#define LITTLE_ENDIAN 1234
2727
#define BIG_ENDIAN 4321
28-
extern int __endianess__;
29-
#define BYTE_ORDER __endianess__
28+
extern int machine_bom;
29+
#define BYTE_ORDER machine_bom
3030
#endif
3131
#define is_big_endian (BYTE_ORDER == BIG_ENDIAN)
3232
#define is_little_endian (BYTE_ORDER == LITTLE_ENDIAN)
@@ -44,24 +44,24 @@ template <typename T> inline void toUnaligned(void * data, T val)
4444
memcpy(data, &val, sizeof(T));
4545
}
4646

47-
static inline int8_t read8(const void * data)
47+
static inline int8_t read_b8(const void * data)
4848
{
4949
return fromUnaligned<int8_t>(data);
5050
}
5151

52-
static inline void write8(void * data, int8_t val)
52+
static inline void write_b8(void * data, int8_t val)
5353
{
5454
toUnaligned(data, val);
5555
}
5656

57-
static inline int16_t swap16(int16_t val)
57+
static inline int16_t swap_b16(int16_t val)
5858
{
5959
return (int16_t)(0 |
6060
(((uint32_t)val & 0x00ff) << 8) |
6161
(((uint32_t)val & 0xff00) >> 8));
6262
}
6363

64-
static inline int32_t swap32(int32_t val)
64+
static inline int32_t swap_b32(int32_t val)
6565
{
6666
return (int32_t)(0 |
6767
(((uint32_t)val & 0x000000ff) << 24) |
@@ -71,39 +71,39 @@ static inline int32_t swap32(int32_t val)
7171
);
7272
}
7373

74-
static inline int16_t read16le(const void * data)
74+
static inline int16_t read_b16le(const void * data)
7575
{
7676
int16_t val = fromUnaligned<int16_t>(data);
7777
if (is_little_endian)
7878
return val;
79-
return swap16(val);
79+
return swap_b16(val);
8080
}
8181

82-
static inline void write16le(void * data, int16_t val)
82+
static inline void write_b16le(void * data, int16_t val)
8383
{
8484
if (is_little_endian)
8585
toUnaligned(data, val);
8686
else
87-
toUnaligned(data, swap16(val));
87+
toUnaligned(data, swap_b16(val));
8888
}
8989

90-
static inline int16_t read16be(const void * data)
90+
static inline int16_t read_b16be(const void * data)
9191
{
9292
int16_t val = fromUnaligned<int16_t>(data);
9393
if (is_big_endian)
9494
return val;
95-
return swap16(val);
95+
return swap_b16(val);
9696
}
9797

98-
static inline void write16be(void * data, int16_t val)
98+
static inline void write_b16be(void * data, int16_t val)
9999
{
100100
if (is_big_endian)
101101
toUnaligned(data, val);
102102
else
103-
toUnaligned(data, swap16(val));
103+
toUnaligned(data, swap_b16(val));
104104
}
105105

106-
static inline int32_t read24le(const void * data)
106+
static inline int32_t read_b24le(const void * data)
107107
{
108108
const char * p = (const char*)data;
109109
int32_t val = fromUnaligned<uint8_t>(&p[2]) << 16;
@@ -114,7 +114,7 @@ static inline int32_t read24le(const void * data)
114114
return val;
115115
}
116116

117-
static inline int32_t read24be(const void * data)
117+
static inline int32_t read_b24be(const void * data)
118118
{
119119
const char * p = (const char*)data;
120120
int32_t val = fromUnaligned<uint8_t>(&p[0]) << 16;
@@ -125,36 +125,36 @@ static inline int32_t read24be(const void * data)
125125
return val;
126126
}
127127

128-
static inline int32_t read32le(const void * data)
128+
static inline int32_t read_b32le(const void * data)
129129
{
130130
int32_t val = fromUnaligned<int32_t>(data);
131131
if (is_little_endian)
132132
return val;
133-
return swap32(val);
133+
return swap_b32(val);
134134
}
135135

136-
static inline void write32le(void * data, int32_t val)
136+
static inline void write_b32le(void * data, int32_t val)
137137
{
138138
if (is_little_endian)
139139
toUnaligned(data, val);
140140
else
141-
toUnaligned(data, swap32(val));
141+
toUnaligned(data, swap_b32(val));
142142
}
143143

144-
static inline int32_t read32be(const void * data)
144+
static inline int32_t read_b32be(const void * data)
145145
{
146146
int32_t val = fromUnaligned<int32_t>(data);
147147
if (is_big_endian)
148148
return val;
149-
return swap32(val);
149+
return swap_b32(val);
150150
}
151151

152-
static inline void write32be(void * data, int32_t val)
152+
static inline void write_b32be(void * data, int32_t val)
153153
{
154154
if (is_big_endian)
155155
toUnaligned(data, val);
156156
else
157-
toUnaligned(data, swap32(val));
157+
toUnaligned(data, swap_b32(val));
158158
}
159159

160160
#endif /* BYTEORDER_H */

0 commit comments

Comments
 (0)