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

making binary file access byte-order-independent.



    Date: Fri, 26 Jan 90 13:50:11 EDT
    From: cogen@XN.LL.MIT.EDU (David Cogen)

    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?

No, there is no standard for binary data files.  You might want to look
into using XDR (eXternal Data Representation), which is part of RPC,
which is part of NFS.  This is RPC's standard representation for binary
streams.

    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.

We put this information in the Machine Type field of our namespace
entries.  If your site does this as well, then you can do

	(let ((host (pathname-host pathname)))
	  (setq host (or (send-if-handles host :host) host)) ; for FEP file hosts
	  (send host :machine-type))

Note, however, that there's no standard specification for what this
should return.  At our site, the machine type for our Lispms is the
model number as a keyword symbol, e.g. :|3640|, and for the Suns it is
:SUN-3 or :SUN-4 (or :SUN for older entries).

Another possibility would be for the program that writes the file to
write a header that indicates the byte order it used.

    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?

I can't duplicate this using either TCP-FTP or NFS.  What type of access
path are you using (go into Peek File System and look at the entry for
the host).

                                                barmar