Nonsense removed: upper case and lower case the same time.
[AROS.git] / workbench / libs / iffparse / closeiff.c
blob0d5b2391c5aee577cc86c5a732fc6817cd00e91b
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_LH1(void, CloseIFF,
15 /* SYNOPSIS */
16 AROS_LHA(struct IFFHandle *, iff, A0),
18 /* LOCATION */
19 struct Library *, IFFParseBase, 8, IFFParse)
21 /* FUNCTION
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.
27 INPUTS
28 iff - Pointer to an IFFhandle struct previously opened with OpenIFF()
30 RESULT
32 NOTES
33 This function tells the custom stream handler to clean up
34 by sending it a IFFCMD_CLEANUP IFFStreamCmd.
36 EXAMPLE
38 BUGS
40 SEE ALSO
41 OpenIFF(), InitIFF()
43 INTERNALS
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 *****************************************************************************/
50 AROS_LIBFUNC_INIT
52 struct IFFStreamCmd cmd;
54 if (iff != NULL)
56 /* clear the IFFF_OPEN bit to mark IFF stream closed */
57 if (!(iff->iff_Flags & IFFF_OPEN) )
59 return;
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)
74 PopChunk(iff);
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;
93 CallHookPkt
95 GetIntIH(iff)->iff_StreamHandler,
96 iff,
97 &cmd
101 AROS_LIBFUNC_EXIT
102 } /* CloseIFF */