grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / iffparse / writechunkbytes.c
blob4bb77e8515b8547f9956a8724ada7dc77a5a40ec
1 /*
2 Copyright © 1995-2016, 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, WriteChunkBytes,
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, 11, IFFParse)
23 /* FUNCTION
24 Writes given number of bytes in the supplied buffer into the
25 current chunk. Attempts to write past the endo of the chunk will
26 be truncated.
28 INPUTS
29 iff - pointer to IFFHandle struct.
30 buf - buffer with data to write.
31 numBytes - number of bytes to write.
33 RESULT
34 actual - (positive) number of bytes actually written.
35 (negative) IFFERR_#? indicating unsuccessful write.
36 NOTES
38 EXAMPLE
40 BUGS
42 SEE ALSO
43 PushChunk(), PopChunk(), WriteChunkRecords()
45 INTERNALS
47 *****************************************************************************/
49 AROS_LIBFUNC_INIT
51 struct ContextNode *cn;
53 LONG placeleft;
54 LONG byteswritten;
56 DEBUG_WRITECHUNKBYTES(dprintf("WriteChunkBytes: iff 0x%lx buf 0x%lx size %d\n",
57 iff, buf, numBytes));
59 /* Get the top contextnode */
60 cn = TopChunk(iff);
62 /* Is the numBytes known for this chunk ? */
63 if (cn->cn_Size != IFFSIZE_UNKNOWN)
65 /* We must truncate attempts to write larger than the chunksize */
66 placeleft = cn->cn_Size - cn->cn_Scan;
67 if (numBytes > placeleft)
69 numBytes = placeleft;
73 /* Actually write the chunk */
74 byteswritten = WriteStream(iff, buf, numBytes, IPB(IFFParseBase));
76 if (byteswritten > 0)
78 /* No error */
79 cn->cn_Scan += byteswritten;
82 DEBUG_WRITECHUNKBYTES(dprintf("WriteChunkBytes: return %ld\n", byteswritten));
83 return (byteswritten);
85 AROS_LIBFUNC_EXIT
86 } /* WriteChunkBytes */