Is substr() offset always in bytes?
Note that the "I" format can result in more than 4 bytes on some platforms.
Yeah, I suppose you could use 'L' then.
I suppose you could figure out the size of integers with code like:
@b = unpack('C*', pack('I', 0));
return scalar(@b);
Then you could make the endian code more generic with:
@b = unpack('C*', pack('I', 0));
$sizeof_long = scalar(@b);
@c = (1..$sizeof_long);
$i = pack('I', hex('0x0'.join('0',reverse @c)));
$big = pack('C'.$sizeof_long, reverse @c);
$lit = pack('C'.$sizeof_long, @);
if ( substr($i, 0, $sizeof_long) eq $big ) {
return 'big';
}
elsif ( substr($i, 0, $sizeof_long) eq $lit ) {
return 'little';
}
else {
return "strange";
}
|