home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / aros / readdouble.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-28  |  1.6 KB  |  87 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: readdouble.c,v 1.5 1997/01/27 00:16:38 ldp Exp $
  4.  
  5.     Desc: Read a big endian double floating point (64bit) from a file
  6.     Lang: english
  7. */
  8. #include <proto/dos.h>
  9.  
  10. /******************************************************************************
  11.  
  12.     NAME */
  13. #include <stdio.h>
  14. #include <proto/alib.h>
  15.  
  16.     BOOL ReadDouble (
  17.  
  18. /*  SYNOPSIS */
  19.     BPTR     fh,
  20.     DOUBLE * dataptr)
  21.  
  22. /*  FUNCTION
  23.     Reads one big endian 64bit double precision floating point value
  24.     from a file.
  25.  
  26.     INPUTS
  27.     fh - Read from this file
  28.     data - Put the data here
  29.  
  30.     RESULT
  31.     The function returns TRUE on success. On success, the value
  32.     read is written into dataptr. On failure, FALSE is returned and the
  33.     contents of dataptr are not changed.
  34.  
  35.     NOTES
  36.     This function reads big endian values from a file even on little
  37.     endian machines.
  38.  
  39.     EXAMPLE
  40.  
  41.     BUGS
  42.  
  43.     SEE ALSO
  44.     Open(), Close(), ReadByte(), ReadWord(), ReadLong(),
  45.     ReadFloat(), ReadString(), WriteByte(), WriteWord(), WriteLong(),
  46.     WriteFloat(), WriteDouble(), WriteString()
  47.  
  48.     HISTORY
  49.     14.09.93    ada created
  50.  
  51. ******************************************************************************/
  52. {
  53.     DOUBLE  value;
  54.     UBYTE * ptr;
  55.     LONG    c;
  56.  
  57.     ptr = (UBYTE *)&value;
  58.  
  59. #if AROS_BIG_ENDIAN
  60. #   define NEXT ++
  61. #else
  62.     ptr += 7;
  63. #   define NEXT --
  64. #endif
  65.  
  66. #define READ_ONE_BYTE            \
  67.     if ((c = FGetC (fh)) == EOF)    \
  68.     return FALSE;            \
  69.                     \
  70.     *ptr NEXT = c
  71.  
  72.     READ_ONE_BYTE;
  73.     READ_ONE_BYTE;
  74.     READ_ONE_BYTE;
  75.     READ_ONE_BYTE;
  76.  
  77.     READ_ONE_BYTE;
  78.     READ_ONE_BYTE;
  79.     READ_ONE_BYTE;
  80.     READ_ONE_BYTE;
  81.  
  82.     *dataptr = value;
  83.  
  84.     return TRUE;
  85. } /* ReadDouble */
  86.  
  87.