home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / workbench / libs / iffparse / readchunkbytes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-03  |  1.9 KB  |  90 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: readchunkbytes.c,v 1.1 1997/02/03 16:44:28 digulla Exp $
  4.  
  5.     Desc:
  6.     Lang: english
  7. */
  8. #include "iffparse_intern.h"
  9.  
  10. /*****************************************************************************
  11.  
  12.     NAME */
  13. #include <proto/iffparse.h>
  14.  
  15.     AROS_LH3(LONG, ReadChunkBytes,
  16.  
  17. /*  SYNOPSIS */
  18.     AROS_LHA(struct IFFHandle *, iff, A0),
  19.     AROS_LHA(APTR              , buf, A1),
  20.     AROS_LHA(LONG              , numBytes, D0),
  21.  
  22. /*  LOCATION */
  23.     struct Library *, IFFParseBase, 10, IFFParse)
  24.  
  25. /*  FUNCTION
  26.     Read a number of bytes from the current chunk into a buffer.
  27.     Attempts to read past the end of the chunk will be truncated.
  28.  
  29.     INPUTS
  30.     iff     - pointer to IFFHandle struct.
  31.     buf     -  pointer to a buffer into which the data will be placed.
  32.     numBtes  - number of bytes to read.
  33.  
  34.     RESULT
  35.     actual -   (positive) the actual number of bytes read.
  36.           (negative) IFFERR_#? error code if not succesfull.
  37.  
  38.     NOTES
  39.  
  40.     EXAMPLE
  41.  
  42.     BUGS
  43.  
  44.     SEE ALSO
  45.     ReadChunkRecords(), ParseIFF(), WriteChunkBytes()
  46.  
  47.     INTERNALS
  48.  
  49.     HISTORY
  50.   27-11-96    digulla automatically created from
  51.       iffparse_lib.fd and clib/iffparse_protos.h
  52.  
  53. *****************************************************************************/
  54. {
  55.     AROS_LIBFUNC_INIT
  56.     AROS_LIBBASE_EXT_DECL(struct Library *,IFFParseBase)
  57.  
  58.     struct ContextNode *cn;
  59.  
  60.     LONG   lefttoread,
  61.       bytesread;
  62.  
  63.  
  64.     /* Get pointer to current contextnode */
  65.     cn = TopChunk(iff);
  66.  
  67.     lefttoread = cn->cn_Size - cn->cn_Scan;
  68.  
  69.     /* If numBytes > lefttoread then we must truncate the readoperation */
  70.     if (numBytes > lefttoread)
  71.     numBytes = lefttoread;
  72.  
  73.     bytesread = ReadStream
  74.     (
  75.     iff,
  76.     buf,
  77.     numBytes,
  78.     IPB(IFFParseBase)
  79.     );
  80.  
  81.     if (bytesread < 0)
  82.     /* No error */
  83.     cn->cn_Scan += bytesread;
  84.     /* Return number of bytes actually read  (or error )*/
  85.  
  86.     return (bytesread);
  87.  
  88.     AROS_LIBFUNC_EXIT
  89. } /* ReadChunkBytes */
  90.