Detabbed
[AROS.git] / rom / dos / freedosobject.c
blobcce966e028a41748ce922f5f667b70508d95c953
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
45 INTERNALS
47 *****************************************************************************/
49 AROS_LIBFUNC_INIT
51 if (ptr == NULL)
52 return;
54 switch(type)
56 case DOS_FILEHANDLE:
58 struct FileHandle *fh=(struct FileHandle *)ptr;
59 if (fh->fh_Flags & FHF_OWNBUF)
60 FreeMem(BADDR(fh->fh_OrigBuf),fh->fh_BufSize);
61 FreeVec(fh);
62 break;
64 case DOS_FIB:
65 FreeVec(ptr);
66 break;
68 case DOS_STDPKT:
69 freedospacket(ptr);
70 break;
72 case DOS_EXALLCONTROL:
73 if (((struct InternalExAllControl *)ptr)->fib)
74 FreeDosObject(DOS_FIB, ((struct InternalExAllControl *)ptr)->fib);
76 FreeVec(ptr);
77 break;
79 case DOS_CLI:
81 struct CommandLineInterface *cli=(struct CommandLineInterface *)ptr;
82 BPTR *cur, *next;
83 cur=(BPTR *)BADDR(cli->cli_CommandDir);
84 FreeVec(BADDR(cli->cli_SetName));
85 FreeVec(BADDR(cli->cli_CommandName));
86 FreeVec(BADDR(cli->cli_CommandFile));
87 FreeVec(BADDR(cli->cli_Prompt));
88 FreeVec(ptr);
89 while(cur!=NULL)
91 next=(BPTR *)BADDR(cur[0]);
92 UnLock(cur[1]);
93 FreeVec(cur);
94 cur=next;
96 break;
99 FreeArgs() will not free a RDArgs without a RDA_DAList,
100 see that function for more information as to why...
102 case DOS_RDARGS:
103 if(((struct RDArgs *)ptr)->RDA_DAList != 0)
104 FreeArgs(ptr);
105 else
106 FreeVec(ptr);
108 break;
111 AROS_LIBFUNC_EXIT
112 } /* FreeDosObject */
114 #undef offsetof
115 #undef container_of
117 #define offsetof(TYPE, MEMBER) ((IPTR) &((TYPE *)0)->MEMBER)
118 #define container_of(ptr, type, member) ({ \
119 const typeof(((type *)0)->member) *__mptr = (ptr); \
120 (type *)((char *)__mptr - offsetof(type, member)); })
122 void freedospacket(struct DosPacket *dp)
124 FreeVec(container_of(dp, struct StandardPacket, sp_Pkt));