2 Copyright © 1995-2007, 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.
44 This function checks that buffers for buffered streams
45 have been freed. This is not very elegant and should have been
46 done at an earlier stadium. It is not a real bug though.
48 *****************************************************************************/
52 struct IFFStreamCmd cmd
;
56 /* clear the IFFF_OPEN bit to mark IFF stream closed */
57 if (!(iff
->iff_Flags
& IFFF_OPEN
) )
62 iff
->iff_Flags
&= ~IFFF_OPEN
;
64 /* Pop of all contextnodes so that only the default one is remaining */
67 for (count = iff->iff_Depth; count; count -- )
69 PopContextNode(iff, IPB(IFFParseBase));
72 while (iff
->iff_Depth
)
77 /* This is for safety:
78 It might be in PopChunk that seeking or writing to streams failed.
79 In that case the memory for eventual buffered setreams
80 were not freed, so we should free it here.
82 (Yes, it is is a kludge !)
84 if ( GetIntIH(iff
)->iff_BufferStartDepth
)
86 FreeBuffer((struct BufferList
*)iff
->iff_Stream
, IPB(IFFParseBase
));
88 GetIntIH(iff
)->iff_BufferStartDepth
= 0;
91 /* Tell the custom stream to cleanup */
92 cmd
.sc_Command
= IFFCMD_CLEANUP
;
95 GetIntIH(iff
)->iff_StreamHandler
,