2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
6 #include "iffparse_intern.h"
8 /*****************************************************************************
11 #include <proto/iffparse.h>
13 AROS_LH1(void, CloseIFF
,
16 AROS_LHA(struct IFFHandle
*, iff
, A0
),
19 struct Library
*, IFFParseBase
, 8, IFFParse
)
22 Completes a read or write session by closing the IFF handle.
23 The IFFHandle struct is ready for reuse in another session,
24 it's just to open it again with OpenIFF(). This function
25 also automatically cleans up if a read or write fails halfway through.
28 iff - Pointer to an IFFhandle struct previously opened with OpenIFF()
33 This function tells the custom stream handler to clean up
34 by sending it a IFFCMD_CLEANUP IFFStreamCmd.
39 Errors during writing of any of the remaining chunks are just
40 ignored and both the faulty and all following chunks are not written.
46 This function checks that buffers for buffered streams
47 have been freed. This is not very elegant and should have been
48 done at an earlier stadium. It is not a real bug though.
50 *****************************************************************************/
54 struct IFFStreamCmd cmd
;
59 /* clear the IFFF_OPEN bit to mark IFF stream closed */
60 if (!(iff
->iff_Flags
& IFFF_OPEN
) )
65 iff
->iff_Flags
&= ~IFFF_OPEN
;
67 /* Pop of all contextnodes so that only the default one is remaining */
70 for (count = iff->iff_Depth; count; count -- )
72 PopContextNode(iff, IPB(IFFParseBase));
75 while (iff
->iff_Depth
&& !error
)
77 error
= PopChunk(iff
);
81 /* FIXME: handle error */
82 bug("[CloseIFF] unhandled error code: %d\n", error
);
85 /* This is for safety:
86 It might be in PopChunk that seeking or writing to streams failed.
87 In that case the memory for eventual buffered setreams
88 were not freed, so we should free it here.
90 (Yes, it is is a kludge !)
92 if ( GetIntIH(iff
)->iff_BufferStartDepth
)
94 FreeBuffer((struct BufferList
*)iff
->iff_Stream
, IPB(IFFParseBase
));
96 GetIntIH(iff
)->iff_BufferStartDepth
= 0;
99 /* Tell the custom stream to cleanup */
100 cmd
.sc_Command
= IFFCMD_CLEANUP
;
103 GetIntIH(iff
)->iff_StreamHandler
,