2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
6 #include "iffparse_intern.h"
8 /*****************************************************************************
11 #include <proto/iffparse.h>
13 AROS_LH4(LONG
, ReadChunkRecords
,
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
),
22 struct Library
*, IFFParseBase
, 12, IFFParse
)
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.
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.
35 actual - (positive) the actual number of whole records read.
36 (negative) IFFERR_#? error code if not succesfull.
46 ReadChunkBytes(), ParseIFF(), WriteChunkRecords()
50 *****************************************************************************/
54 struct ContextNode
*cn
;
60 DEBUG_READCHUNKRECORDS(dprintf("ReadChunkRecords: iff %p buf %p bytesPerRecord %ld numRecords %ld\n",
61 iff
, buf
, bytesPerRecord
, numRecords
));
63 /* Get pointer to top contextnode */
66 lefttoread
= cn
->cn_Size
- cn
->cn_Scan
;
68 bytestoread
= bytesPerRecord
* numRecords
;
70 /* If bytestoread > lefttoread then we must truncate the readoperation */
71 if (bytestoread
> lefttoread
)
73 bytestoread
= lefttoread
;
76 /* See to it that we only read whole records */
77 bytestoread
-= (lefttoread
% bytesPerRecord
);
80 /* Beware: bytestoread is 0 now if bytesPerRecord > lefttoread */
82 bytesread
= ReadStream
91 /* Return number of records actually read (if no error occured) */
93 /* IFFERR_#? in bytesread */
94 numRecords
= bytesread
;
97 /* calculate the actual number of records written */
98 numRecords
= bytesread
/ bytesPerRecord
;
100 /* Update number of bytes read */
101 cn
->cn_Scan
+= bytesread
;
104 DEBUG_READCHUNKRECORDS(dprintf("ReadChunkRecords: return %ld\n", numRecords
));
108 } /* ReadChunkRecords */