user1660675
user1660675

Reputation: 149

Writing bytes to file gets swapped on certain platforms

The following code gives me different outputs on different systems:

int fd = open(filename, O_RDWR | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
byte_t data[] = { 0x00, 0x01, 0x02, 0x03, 0x0a, 0x0b 0x0c, 0x0d };

write(fd, data, sizeof(data));

On the mac a 'hexdump' of the filename gives what I would expect

00 01 02 03 0a 0b 0c 0d

On Ubuntu and on Windows ( the code is different but the effect is the same ) you get

01 00 03 02 0b 0a 0d 0c

I would like platforms to print

00 01 02 03 0a 0b 0c 0d

So how should I proceed?

Upvotes: 0

Views: 103

Answers (1)

jaeheung
jaeheung

Reputation: 1208

It looks like the hexdump utility swaps the bytes. Please show the hexdump command you used in each platform.

To confirm it, test with

byte_t data[] = { 'a', 'b', 'c', 'd', 'e' }

and compare the hexdump and cat(or type) outputs.

Upvotes: 1

Related Questions