2 Copyright © 1995-2016, The AROS Development Team. All rights reserved.
6 #include "iffparse_intern.h"
8 /*****************************************************************************
11 #include <proto/iffparse.h>
13 AROS_LH4(LONG
, WriteChunkRecords
,
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
, 13, IFFParse
)
25 Write numRecods records of bytesPerRecord bytes to the current chunk.
26 Attempts to write past the end of the chunk will be truncated.
29 iff - pointer to IFFHandle struct.
30 buf - pointer to a buffer containig the data to be written.
31 bytesPerRecord - number of bytes per record.
32 numRecords - number of records to write.
35 actual - (positive) the actual number of whole records written.
36 (negative) IFFERR_#? error code if not successful.
49 *****************************************************************************/
53 struct ContextNode
*cn
;
55 /* Number of bytes possible to write in the chunk */
57 /* Number of bytes actually written */
59 /* Number of bytes to write into the chunk */
62 DEBUG_WRITECHUNKRECORDS(dprintf("WriteChunkRecords: iff %p buf %p bytesPerRecord %ld numRecords %ld\n",
63 iff
, buf
, bytesPerRecord
, numRecords
));
65 /* Calculate number of bytes to write */
66 bytestowrite
= bytesPerRecord
* numRecords
;
68 /* Get the top contextnode */
71 /* Is the numBytes known for this chunk ? */
72 if (cn
->cn_Size
!= IFFSIZE_UNKNOWN
)
74 /* We must truncate attempts to write larger than the chunksize */
75 lefttowrite
= cn
->cn_Size
- cn
->cn_Scan
;
76 if (bytestowrite
> lefttowrite
)
78 bytestowrite
= lefttowrite
;
80 /* See to it that we only write whole records */
81 bytestowrite
-= (lefttowrite
% bytesPerRecord
);
86 /* Actually write the chunk */
87 byteswritten
= WriteStream(iff
, buf
, bytestowrite
, IPB(IFFParseBase
));
90 /* IFFERR_#? returned by WriteStream() */
91 numRecords
= byteswritten
;
95 cn
->cn_Scan
+= byteswritten
;
97 numRecords
= (byteswritten
/ bytesPerRecord
);
100 DEBUG_WRITECHUNKRECORDS(dprintf("WriteChunkRecords: return %ld\n", numRecords
));
104 } /* WriteChunkRecords */