New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / workbench / libs / iffparse / readchunkrecords.c
blob938ab620d65acea6b474b31a1c279eecd5b556c1
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_LH4(LONG, ReadChunkRecords,
15 /* SYNOPSIS */
16 AROS_LHA(struct IFFHandle *, iff, A0),
17 AROS_LHA(APTR , buf, A1),
18 AROS_LHA(LONG , bytesPerRecord, D0),
19 AROS_LHA(LONG , numRecords, D1),
21 /* LOCATION */
22 struct Library *, IFFParseBase, 12, IFFParse)
24 /* FUNCTION
25 Read a number of records with the given size from the current chunk
26 into a buffer. Attempts to read past the end of the chunk will be truncated.
28 INPUTS
29 iff - pointer to IFFHandle struct.
30 buf - pointer to a buffer into which the data will be placed.
31 bytesPerRecord - number of bytes per record.
32 numRecords - number of records to read.
34 RESULT
35 actual - (positive) the actual number of whole records read.
36 (negative) IFFERR_#? error code if not succesfull.
39 NOTES
41 EXAMPLE
43 BUGS
45 SEE ALSO
46 ReadChunkBytes(), ParseIFF(), WriteChunkRecords()
48 INTERNALS
50 *****************************************************************************/
52 AROS_LIBFUNC_INIT
53 AROS_LIBBASE_EXT_DECL(struct Library *,IFFParseBase)
55 struct ContextNode *cn;
57 LONG bytestoread,
58 lefttoread,
59 bytesread;
61 DEBUG_READCHUNKRECORDS(dprintf("ReadChunkRecords: iff %p buf %p bytesPerRecord %ld numRecords %ld\n",
62 iff, buf, bytesPerRecord, numRecords));
64 /* Get pointer to top contextnode */
65 cn = TopChunk(iff);
67 lefttoread = cn->cn_Size - cn->cn_Scan;
69 bytestoread = bytesPerRecord * numRecords;
71 /* If bytestoread > lefttoread then we must truncate the readoperation */
72 if (bytestoread > lefttoread)
74 bytestoread = lefttoread;
77 /* See to it that we only read whole records */
78 bytestoread -= (lefttoread % bytesPerRecord);
81 /* Beware: bytestoread is 0 now if bytesPerRecord > lefttoread */
83 bytesread = ReadStream
85 iff,
86 buf,
87 bytestoread,
88 IPB(IFFParseBase)
92 /* Return number of records actually read (if no error occured) */
93 if (bytesread < 0)
94 /* IFFERR_#? in bytesread */
95 numRecords = bytesread;
96 else
98 /* calculate the actual number of records written */
99 numRecords = bytesread / bytesPerRecord;
101 /* Update number of bytes read */
102 cn->cn_Scan += bytesread;
105 DEBUG_READCHUNKRECORDS(dprintf("ReadChunkRecords: return %ld\n", numRecords));
106 return (numRecords);
108 AROS_LIBFUNC_EXIT
109 } /* ReadChunkRecords */