00001 #ifndef PORTABLEIO_H__ 00002 #define PORTABLEIO_H__ 00003 /* Copyright (C) 1988-1991 Apple Computer, Inc. 00004 * All Rights Reserved. 00005 * 00006 * Warranty Information 00007 * Even though Apple has reviewed this software, Apple makes no warranty 00008 * or representation, either express or implied, with respect to this 00009 * software, its quality, accuracy, merchantability, or fitness for a 00010 * particular purpose. As a result, this software is provided "as is," 00011 * and you, its user, are assuming the entire risk as to its quality 00012 * and accuracy. 00013 * 00014 * This code may be used and freely distributed as long as it includes 00015 * this copyright notice and the warranty information. 00016 * 00017 * Machine-independent I/O routines for 8-, 16-, 24-, and 32-bit integers. 00018 * 00019 * Motorola processors (Macintosh, Sun, Sparc, MIPS, etc) 00020 * pack bytes from high to low (they are big-endian). 00021 * Use the HighLow routines to match the native format 00022 * of these machines. 00023 * 00024 * Intel-like machines (PCs, Sequent) 00025 * pack bytes from low to high (the are little-endian). 00026 * Use the LowHigh routines to match the native format 00027 * of these machines. 00028 * 00029 * These routines have been tested on the following machines: 00030 * Apple Macintosh, MPW 3.1 C compiler 00031 * Apple Macintosh, THINK C compiler 00032 * Silicon Graphics IRIS, MIPS compiler 00033 * Cray X/MP and Y/MP 00034 * Digital Equipment VAX 00035 * 00036 * 00037 * Implemented by Malcolm Slaney and Ken Turkowski. 00038 * 00039 * Malcolm Slaney contributions during 1988-1990 include big- and little- 00040 * endian file I/O, conversion to and from Motorola's extended 80-bit 00041 * FLOATing-point format, and conversions to and from IEEE single- 00042 * precision FLOATing-point format. 00043 * 00044 * In 1991, Ken Turkowski implemented the conversions to and from 00045 * IEEE double-precision format, added more precision to the extended 00046 * conversions, and accommodated conversions involving +/- infinity, 00047 * NaN's, and denormalized numbers. 00048 * 00049 * $Id: portableio.h,v 1.1 2003/10/04 00:11:19 herman Exp $ 00050 * 00051 * $Log: portableio.h,v $ 00052 * Revision 1.1 2003/10/04 00:11:19 herman 00053 * New file from 1.1.7 (not in 1.1.6) added from Rich's automakified src tree. 00054 * 00055 * Revision 1.1 2003/07/29 04:17:52 heroine 00056 * *** empty log message *** 00057 * 00058 * Revision 2.6 91/04/30 17:06:02 malcolm 00059 */ 00060 00061 #include <stdio.h> 00062 #include "ieeefloat.h" 00063 00064 int ReadByte (FILE * fp); 00065 int Read16BitsLowHigh (FILE * fp); 00066 int Read16BitsHighLow (FILE * fp); 00067 void Write8Bits (FILE * fp, int i); 00068 void Write16BitsLowHigh (FILE * fp, int i); 00069 void Write16BitsHighLow (FILE * fp, int i); 00070 int Read24BitsHighLow (FILE * fp); 00071 int Read32Bits (FILE * fp); 00072 int Read32BitsHighLow (FILE * fp); 00073 void Write32Bits (FILE * fp, int i); 00074 void Write32BitsLowHigh (FILE * fp, int i); 00075 void Write32BitsHighLow (FILE * fp, int i); 00076 void ReadBytes (FILE * fp, char *p, int n); 00077 void ReadBytesSwapped (FILE * fp, char *p, int n); 00078 void WriteBytes (FILE * fp, char *p, int n); 00079 void WriteBytesSwapped (FILE * fp, char *p, int n); 00080 double ReadIeeeFloatHighLow (FILE * fp); 00081 double ReadIeeeFloatLowHigh (FILE * fp); 00082 double ReadIeeeDoubleHighLow (FILE * fp); 00083 double ReadIeeeDoubleLowHigh (FILE * fp); 00084 double ReadIeeeExtendedHighLow (FILE * fp); 00085 double ReadIeeeExtendedLowHigh (FILE * fp); 00086 void WriteIeeeFloatLowHigh (FILE * fp, double num); 00087 void WriteIeeeFloatHighLow (FILE * fp, double num); 00088 void WriteIeeeDoubleLowHigh (FILE * fp, double num); 00089 void WriteIeeeDoubleHighLow (FILE * fp, double num); 00090 void WriteIeeeExtendedLowHigh (FILE * fp, double num); 00091 void WriteIeeeExtendedHighLow (FILE * fp, double num); 00092 00093 #define Read32BitsLowHigh(f) Read32Bits(f) 00094 #define WriteString(f,s) fwrite(s,strlen(s),sizeof(char),f) 00095 #endif
1.5.5