One little endian question

Bill Campbell bill at celestial.com
Sun Mar 2 16:38:32 PST 2008


On Sun, Mar 02, 2008, Jeff Harrison wrote:
>
>--- Bill Campbell <bill at celestial.com> wrote:
>
>> On Sun, Mar 02, 2008, Jeff Harrison wrote:
>> ...
>> >Thanks.  That was very enlightening.  However, I
>> don't
>> >see how that helps me directly.  I need to know
>> from
>> >within a filepro application what the native byte
>> >order is.  How can I tell that?
>> 
>> Given that this isn't something that changes on a
>> system, how
>> about putting it in a file someplace where it's
>> accessible.
>> 
>> On a system with python, this is a one liner that
>> will return the
>> value for the system.  It returns ``little'' or
>> ``big''.
>> 
>> python -c 'import sys; print sys.byteorder'
...
>Well, the problem is that I am designing something
>that hopefully anyone with filepro 5.0 or greater will
>be able to use - I can't depend on them having python,
>and they may have either byte order, so I wouldn't
>know what to put in that file.

Figuring out byte order isn't trivial (look at the configuration code for
tcp_wrappers to get an idea of how much fun it can be).  Since most of what
I'm writing these days is in python, and it provides a simple way to get
the information, that what I've been using for several years.

>As I mentioned, I could assume little endian, and let >the user override
this if necessary - it would just be >a little confusing to the typical end
user.  It is >certainly an option though.

If it's Windows, it will be little endian, as M$ dropped support for the
Alpha and non-Intel/AMD chips years ago.  I think the same can be said for
SCO Unix systems.  FreeBSD and Linux run on non-Intel platforms, and
usually have python these days (Red Hat and CentOS use python for ``yum''
and other administration scripts).

What big endian platforms does FilePro run on?

On Apple OS X, ``uname -a | grep -i PPC -q'' will succeed on the big endian
PowerPC and fail on the Intel Macs.  The ``uname -p'' command returns the
processor name on OS X, FreeBSD, SCO OpenServer, and Linux, but I'm not
sure how portable that is.  This would probably work in /bin/sh or other
non-csh'ish shells where the big endian processors are listed in the first
line, and the default is little

case `uname -p` in
	powerpc|ppc)	byteorder=big;;
	*)	byteorder=little;;
esac
echo $byteorder

Bill
--
INTERNET:   bill at celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

If you make yourselves sheep, the wolves will eat you -- Benjamin Franklin


More information about the Filepro-list mailing list