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

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: writechunkbytes.c,v 1.1 1997/02/03 16:44:29 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, WriteChunkBytes,
  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, 11, IFFParse)
  24.  
  25. /*  FUNCTION
  26.     Writes given number of bytes in the supplied buffer into the
  27.     current chunk. Attempts to write past the endo of the chunk will
  28.     be truncated.
  29.  
  30.     INPUTS
  31.     iff       - pointer to IFFHandle struct.
  32.     buf       -  buffer with data to write.
  33.     numBytes  - number of bytes to write.
  34.  
  35.     RESULT
  36.     actual      -  (positive) number of bytes actually written.
  37.             (negative) IFFERR_#? indicating unsuccesfull write.
  38.     NOTES
  39.  
  40.     EXAMPLE
  41.  
  42.     BUGS
  43.  
  44.     SEE ALSO
  45.     PushChunk(), PopChunk(), WriteChunkRecords()
  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 placeleft;
  61.     LONG byteswritten;
  62.  
  63.  
  64.     /* Get the top contextnode */
  65.     cn = TopChunk(iff);
  66.  
  67.     /* Is the numBytes known for this chunk ? */
  68.     if (cn->cn_Size != IFFSIZE_UNKNOWN)
  69.     {
  70.     /* We must truncate attempts to write larger than the chunksize */
  71.     placeleft = cn->cn_Size - cn->cn_Scan;
  72.     if  (numBytes > placeleft)
  73.  
  74.     numBytes = placeleft;
  75.     }
  76.  
  77.  
  78.     /* Actually write the chunk */
  79.     byteswritten = WriteStream(iff, buf, numBytes, IPB(IFFParseBase));
  80.  
  81.     if (byteswritten > 0)
  82.     /* No error */
  83.     cn->cn_Scan += byteswritten;
  84.  
  85.     return (byteswritten);
  86.  
  87.     AROS_LIBFUNC_EXIT
  88. } /* WriteChunkBytes */
  89.