tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / rom / dos / freedosobject.c
blob42e4379fadec5b09992644109224fad4b00cb0f8
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
8 #include <exec/memory.h>
9 #include <proto/exec.h>
10 #include <dos/exall.h>
11 #include <dos/rdargs.h>
12 #include "dos_intern.h"
14 /*****************************************************************************
16 NAME */
17 #include <proto/dos.h>
19 AROS_LH2(void, FreeDosObject,
21 /* SYNOPSIS */
22 AROS_LHA(ULONG, type, D1),
23 AROS_LHA(APTR, ptr, D2),
25 /* LOCATION */
26 struct DosLibrary *, DOSBase, 39, Dos)
28 /* FUNCTION
29 Frees an object allocated with AllocDosObject.
31 INPUTS
32 type - object type. The same parameter as given to AllocDosObject().
33 ptr - Pointer to object.
35 RESULT
37 NOTES
39 EXAMPLE
41 BUGS
43 SEE ALSO
44 AllocDosObject()
46 INTERNALS
48 *****************************************************************************/
50 AROS_LIBFUNC_INIT
52 if (ptr == NULL)
53 return;
55 switch(type)
57 case DOS_FILEHANDLE:
59 struct FileHandle *fh=(struct FileHandle *)ptr;
60 if (fh->fh_Flags & FHF_OWNBUF)
61 FreeMem(BADDR(fh->fh_OrigBuf),fh->fh_BufSize);
62 FreeVec(fh);
63 break;
65 case DOS_FIB:
66 FreeVec(ptr);
67 break;
69 case DOS_STDPKT:
70 freedospacket(ptr);
71 break;
73 case DOS_EXALLCONTROL:
74 if (((struct InternalExAllControl *)ptr)->fib)
75 FreeDosObject(DOS_FIB, ((struct InternalExAllControl *)ptr)->fib);
77 FreeVec(ptr);
78 break;
80 case DOS_CLI:
82 struct CommandLineInterface *cli=(struct CommandLineInterface *)ptr;
83 BPTR *cur, *next;
84 cur=(BPTR *)BADDR(cli->cli_CommandDir);
85 FreeVec(BADDR(cli->cli_SetName));
86 FreeVec(BADDR(cli->cli_CommandName));
87 FreeVec(BADDR(cli->cli_CommandFile));
88 FreeVec(BADDR(cli->cli_Prompt));
89 FreeVec(ptr);
90 while(cur!=NULL)
92 next=(BPTR *)BADDR(cur[0]);
93 UnLock(cur[1]);
94 FreeVec(cur);
95 cur=next;
97 break;
100 FreeArgs() will not free a RDArgs without a RDA_DAList,
101 see that function for more information as to why...
103 case DOS_RDARGS:
104 if(((struct RDArgs *)ptr)->RDA_DAList != 0)
105 FreeArgs(ptr);
106 else
107 FreeVec(ptr);
109 break;
112 AROS_LIBFUNC_EXIT
113 } /* FreeDosObject */
115 #undef offsetof
116 #undef container_of
118 #define offsetof(TYPE, MEMBER) ((IPTR) &((TYPE *)0)->MEMBER)
119 #define container_of(ptr, type, member) ({ \
120 const typeof(((type *)0)->member) *__mptr = (ptr); \
121 (type *)((char *)__mptr - offsetof(type, member)); })
123 void freedospacket(struct DosPacket *dp)
125 FreeVec(container_of(dp, struct StandardPacket, sp_Pkt));