[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

making binary file access byte-order-independent.



I am reading a binary file of 16-bit integers from a SUN on a Symbolics
(:element-type '(unsigned-byte 16). The problem is that the byte order is
reversed, because SUN stores shorts as high-byte-first, and Symbolics expects
them to be low-byte-first.

I can get around the problem by reading 8-bit bytes, packing them as necessary.
But this is inconvenient.

So...

1) Is there a way to make the discrepancy transparent, so that the READ-BYTE
operation automatically swaps the bytes if necessary?

2) If not, can I get from a pathname, information about the host type, like a
keyword (:SUN, :VAX, :SYMBOLICS, etc.)? This way I can read 8-bit bytes and
pack them according to the machine type.

3) Apparently, binary files read from a SUN via TCP must be read all the way to
the end before they are closed, or I get a "Broken Pipe" error. Whose problem
is this? Symbolics? SunOS?

-- David Cogen.