New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / workbench / libs / iffparse / readchunkbytes.c
blob1273df8c09f95f39de37038dd2e86b3968432b31
1 /*
2 Copyright © 1995-2004, 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
50 AROS_LIBBASE_EXT_DECL(struct Library *,IFFParseBase)
52 struct ContextNode *cn;
54 LONG lefttoread,
55 bytesread;
57 DEBUG_READCHUNKBYTES(dprintf("ReadChunkBytes: iff %p buf %p bytes %ld\n",
58 iff, buf, numBytes));
60 /* Get pointer to current contextnode */
61 cn = TopChunk(iff);
63 lefttoread = cn->cn_Size - cn->cn_Scan;
65 /* If numBytes > lefttoread then we must truncate the readoperation */
66 if (numBytes > lefttoread)
67 numBytes = lefttoread;
69 DEBUG_READCHUNKBYTES(dprintf("ReadChunkBytes: cn %p cn_Size %ld cn_Scan %ld numBytes %ld\n",
70 cn, cn->cn_Size, cn->cn_Scan, numBytes));
72 bytesread = ReadStream
74 iff,
75 buf,
76 numBytes,
77 IPB(IFFParseBase)
80 /* No error */
81 if (bytesread > 0)
82 cn->cn_Scan += bytesread;
84 DEBUG_READCHUNKBYTES(dprintf("ReadChunkBytes: return %ld\n", bytesread));
86 /* Return number of bytes actually read (or error )*/
87 return (bytesread);
89 AROS_LIBFUNC_EXIT
90 } /* ReadChunkBytes */