Better hex/oct width handling.
[AROS.git] / compiler / loadseg / unloadsegment.c
blob70895dd1ffb72db55e7c84763b84a91b392556c6
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
9 #include <aros/libcall.h>
10 #include <aros/asmcall.h>
11 #include <exec/libraries.h>
12 #include <proto/debug.h>
13 #include <proto/exec.h>
14 #include <proto/dos.h>
16 #include "loadseg_intern.h"
18 /*****************************************************************************
20 NAME */
21 #include <loadseg/loadseg.h>
23 BOOL UnLoadSegment(
25 /* SYNOPSIS */
26 BPTR seglist ,
27 VOID_FUNC freefunc,
28 struct DosLibrary *DOSBase)
30 /* LOCATION
32 loadseg.lib
34 FUNCTION
35 Unloads a seglist loaded with LoadSegment().
37 INPUTS
38 seglist - Seglist
39 freefunc - Function to be called to free memory
40 DOSBase - Required for AOS HUNK overlays only, otherwise NULL
42 RESULT
43 DOSTRUE if everything wents O.K.
45 NOTES
47 EXAMPLE
49 BUGS
51 SEE ALSO
53 INTERNALS
55 *****************************************************************************/
57 BPTR next;
58 SIPTR funcarray[] = { (SIPTR)NULL, (SIPTR)NULL, (SIPTR)freefunc };
60 if (seglist)
62 APTR DebugBase;
64 if ((DebugBase = OpenLibrary("debug.library", 0))) {
65 UnregisterModule(seglist);
66 CloseLibrary(DebugBase);
69 #if (AROS_FLAVOUR & AROS_FLAVOUR_BINCOMPAT)
70 if (DOSBase != NULL) {
71 /* free overlay structures */
72 ULONG *seg = BADDR(seglist);
73 if (seg[2] == 0x0000abcd && seg[6] == (ULONG)DOSBase->dl_GV) {
74 Close((BPTR)seg[3]); /* file handle */
75 ilsFreeVec((void*)seg[4]); /* overlay table, APTR */
76 ilsFreeVec(BADDR(seg[5])); /* hunk table, BPTR */
79 #endif
81 while (seglist)
83 next = *(BPTR *)BADDR(seglist);
84 ilsFreeVec(BADDR(seglist));
85 seglist = next;
88 return DOSTRUE;
90 else
91 return DOSFALSE;
93 } /* UnLoadSegment */