Nonsense removed: upper case and lower case the same time.
[AROS.git] / workbench / libs / iffparse / writechunkrecords.c
blob9eb1ea90d63157d3a16f4d2aa53009b902d7e2aa
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_LH4(LONG, WriteChunkRecords,
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, 13, IFFParse)
24 /* FUNCTION
25 Write numRecods records of bytesPerRecord bytes to the current chunk.
26 Attempts to write past the end of the chunk will be truncated.
28 INPUTS
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.
34 RESULT
35 actual - (positive) the actual number of whole records written.
36 (negative) IFFERR_#? error code if not succesfull.
38 NOTES
40 EXAMPLE
42 BUGS
44 SEE ALSO
45 WriteChunkBytes()
47 INTERNALS
49 *****************************************************************************/
51 AROS_LIBFUNC_INIT
53 struct ContextNode *cn;
55 /* Number of bytes possible to write in the chunk */
56 LONG lefttowrite;
57 /* Number of bytes actually written */
58 LONG byteswritten;
59 /* Number of bytes to write into the chunk */
60 LONG bytestowrite;
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 */
69 cn = TopChunk(iff);
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));
89 if (byteswritten < 0)
90 /* IFFERR_#? returned by WriteStream() */
91 numRecords = byteswritten;
92 else
94 /* No error */
95 cn->cn_Scan += byteswritten;
97 numRecords = (byteswritten / bytesPerRecord);
100 DEBUG_WRITECHUNKRECORDS(dprintf("WriteChunkRecords: return %ld\n", numRecords));
101 return (numRecords);
103 AROS_LIBFUNC_EXIT
104 } /* WriteChunkRecords */