1 /* Copyright (C) 1988-1991 Apple Computer, Inc.
5 * Even though Apple has reviewed this software, Apple makes no warranty
6 * or representation, either express or implied, with respect to this
7 * software, its quality, accuracy, merchantability, or fitness for a
8 * particular purpose. As a result, this software is provided "as is,"
9 * and you, its user, are assuming the entire risk as to its quality
12 * This code may be used and freely distributed as long as it includes
13 * this copyright notice and the warranty information.
16 * Motorola processors (Macintosh, Sun, Sparc, MIPS, etc)
17 * pack bytes from high to low (they are big-endian).
18 * Use the HighLow routines to match the native format
21 * Intel-like machines (PCs, Sequent)
22 * pack bytes from low to high (the are little-endian).
23 * Use the LowHigh routines to match the native format
26 * These routines have been tested on the following machines:
27 * Apple Macintosh, MPW 3.1 C compiler
28 * Apple Macintosh, THINK C compiler
29 * Silicon Graphics IRIS, MIPS compiler
31 * Digital Equipment VAX
34 * Implemented by Malcolm Slaney and Ken Turkowski.
36 * Malcolm Slaney contributions during 1988-1990 include big- and little-
37 * endian file I/O, conversion to and from Motorola's extended 80-bit
38 * FLOATing-point format, and conversions to and from IEEE single-
39 * precision FLOATing-point format.
41 * In 1991, Ken Turkowski implemented the conversions to and from
42 * IEEE double-precision format, added more precision to the extended
43 * conversions, and accommodated conversions involving +/- infinity,
44 * NaN's, and denormalized numbers.
46 * $Id: portableio.c,v 1.1 2003/10/04 00:11:19 herman Exp $
48 * $Log: portableio.c,v $
49 * Revision 1.1 2003/10/04 00:11:19 herman
50 * New file from 1.1.7 (not in 1.1.6) added from Rich's automakified src tree.
52 * Revision 1.1 2003/07/29 04:17:52 heroine
53 * *** empty log message ***
55 * Revision 2.6 91/04/30 17:06:02 malcolm
57 * MFC - hacked out everything we don't need for layer II
62 #include "portableio.h"
65 /****************************************************************
66 * Big/little-endian independent I/O routines.
67 ****************************************************************/
68 int Read16BitsHighLow (fp
)
71 int first
, second
, result
;
73 first
= 0xff & getc (fp
);
74 second
= 0xff & getc (fp
);
76 result
= (first
<< 8) + second
;
79 result
= result
- 0x10000;
84 double ReadIeeeExtendedHighLow (fp
)
87 char bits
[kExtendedLength
];
89 ReadBytes (fp
, bits
, kExtendedLength
);
90 return ConvertFromIeeeExtended (bits
);
93 int Read32BitsHighLow (fp
)
96 int first
, second
, result
;
98 first
= 0xffff & Read16BitsHighLow (fp
);
99 second
= 0xffff & Read16BitsHighLow (fp
);
101 result
= (first
<< 16) + second
;
103 if (result
& 0x80000000)
104 result
= result
- 0x100000000;
109 void ReadBytes (fp
, p
, n
)
114 while (!feof (fp
) & (n
-- > 0))