Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Sep 1999 22:32:33 -0500
From:      Dan Nelson <dnelson@emsphone.com>
To:        cjclark@home.com
Cc:        FreeBSD Questions <freebsd-questions@FreeBSD.ORG>
Subject:   Re: Reading 'Foreign' Binaries
Message-ID:  <19990915223233.B5312@dan.emsphone.com>
In-Reply-To: <199909152148.RAA28463@cc942873-a.ewndsr1.nj.home.com>
References:  <199909152148.RAA28463@cc942873-a.ewndsr1.nj.home.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Sep 15), Crist J. Clark said:
> I have large (100s MB) files that are written in binary formats. That
> is, structures from C programs are just dumped to files using
> write(2). All of them are produced on SGIs (MIPS processor), which,
> like most computers, have the opposite endian convention than i386s.
> 
> I have never had to deal with this issue before and have not been
> able to get this help from my usual C resources. I found the htonl,
> htons, ntohl, and ntohs family of functions, but they only seem to
> want to help with int's. The structures I want to read are full of
> int's, float's, double's, and char's. Looking over what happens when
> I write(2) float's from both platforms has not been particularly
> enlightening yet.
> 
> I probably could figure this out given the time, but I would have to
> guess this has been dealt with many times before. Why re-invent the
> wheel? Can anyone point me in the right direction or offer direct
> help?

It's been dealt with by not writing out machine-depentant data :)

If you're lucky, the MIPS use IEEE floating-point values, in which case
you should be able to read them directly.  Otherwise you'll have to
find out the internal representation of the floating-point format and
convert it manually.

Chars convert directly, of course.

For shorts, longs, and long longs, write functions that swap the
appropriate bytes.

Keep in mind that you'll see lots of garbage characters (padding
between the fields to align them on CPU-friendly word boundries) if the
files are true C structs written to disk.

-- 
	Dan Nelson
	dnelson@emsphone.com


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990915223233.B5312>