Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / iffparse / readchunkbytes.c
blobd05a553fe37fe40c30d067b2c4bf333949c271fb
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "iffparse_intern.h"
8 /*****************************************************************************
10 NAME */
11 #include <proto/iffparse.h>
13 AROS_LH3(LONG, ReadChunkBytes,
15 /* SYNOPSIS */
16 AROS_LHA(struct IFFHandle *, iff, A0),
17 AROS_LHA(APTR , buf, A1),
18 AROS_LHA(LONG , numBytes, D0),
20 /* LOCATION */
21 struct Library *, IFFParseBase, 10, IFFParse)
23 /* FUNCTION
24 Read a number of bytes from the current chunk into a buffer.
25 Attempts to read past the end of the chunk will be truncated.
27 INPUTS
28 iff - pointer to IFFHandle struct.
29 buf - pointer to a buffer into which the data will be placed.
30 numBtes - number of bytes to read.
32 RESULT
33 actual - (positive) the actual number of bytes read.
34 (negative) IFFERR_#? error code if not succesfull.
36 NOTES
38 EXAMPLE
40 BUGS
42 SEE ALSO
43 ReadChunkRecords(), ParseIFF(), WriteChunkBytes()
45 INTERNALS
47 *****************************************************************************/
49 AROS_LIBFUNC_INIT
51 struct ContextNode *cn;
53 LONG lefttoread,
54 bytesread;
56 DEBUG_READCHUNKBYTES(dprintf("ReadChunkBytes: iff %p buf %p bytes %ld\n",
57 iff, buf, numBytes));
59 /* Get pointer to current contextnode */
60 cn = TopChunk(iff);
62 lefttoread = cn->cn_Size - cn->cn_Scan;
64 /* If numBytes > lefttoread then we must truncate the readoperation */
65 if (numBytes > lefttoread)
66 numBytes = lefttoread;
68 DEBUG_READCHUNKBYTES(dprintf("ReadChunkBytes: cn %p cn_Size %ld cn_Scan %ld numBytes %ld\n",
69 cn, cn->cn_Size, cn->cn_Scan, numBytes));
71 bytesread = ReadStream
73 iff,
74 buf,
75 numBytes,
76 IPB(IFFParseBase)
79 /* No error */
80 if (bytesread > 0)
81 cn->cn_Scan += bytesread;
83 DEBUG_READCHUNKBYTES(dprintf("ReadChunkBytes: return %ld\n", bytesread));
85 /* Return number of bytes actually read (or error )*/
86 return (bytesread);
88 AROS_LIBFUNC_EXIT
89 } /* ReadChunkBytes */