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/06/16 20:00:50 herman Exp $
48 * $Log: portableio.c,v $
49 * Revision 1.1 2003/06/16 20:00:50 herman
52 * Revision 1.1.1.1 2002/06/21 12:35:26 myrina
55 * Revision 1.1.1.1 2001/10/01 03:14:55 heroine
58 * Revision 1.1.1.1 2001/10/01 02:51:42 root
61 * Revision 1.5 2001/07/15 12:16:31 mikecheng
62 * Removed a whooooole heap of unused functions
64 * Revision 1.4 2001/07/14 06:17:20 mikecheng
65 * More cleanup. psy.c init and cleanup functions added.
66 * Removed 'II_' from in front of all function names.
67 * absthr table files now in exe.
68 * Started renaming some variables in some sort of scheme (heaps more to come)
70 * Revision 1.3 2001/07/04 09:51:36 uid43892
71 * everything passed through 'indent *.c *.h'
73 * Revision 1.2 2001/07/02 10:35:28 mikecheng
74 * Function args changed from K&R -> ansi.
75 * Cleaned up the header files.
76 * Made compilation pretty strict (-Wall -ansi -pedantic)
78 * Revision 1.1.1.1 2001/07/01 06:54:47 mikecheng
79 * This is v0.30 of toolame. A fresh start consisting of the dist10 code with
80 * all layerI and layerIII removed.
82 * Revision 2.6 91/04/30 17:06:02 malcolm
87 #include "portableio.h"
90 /****************************************************************
91 * Big/little-endian independent I/O routines.
92 ****************************************************************/
94 Read16BitsHighLow (fp
)
97 int first
, second
, result
;
99 first
= 0xff & getc (fp
);
100 second
= 0xff & getc (fp
);
102 result
= (first
<< 8) + second
;
105 result
= result
- 0x10000;
111 Read32BitsHighLow (fp
)
114 int first
, second
, result
;
116 first
= 0xffff & Read16BitsHighLow (fp
);
117 second
= 0xffff & Read16BitsHighLow (fp
);
119 result
= (first
<< 16) + second
;
121 if (result
& 0x80000000)
122 result
= result
- 0x100000000;
128 ReadIeeeExtendedHighLow (fp
)
131 char bits
[kExtendedLength
];
133 ReadBytes (fp
, bits
, kExtendedLength
);
134 return ConvertFromIeeeExtended (bits
);
143 while ((!feof (fp
) & (n
--)) > 0)