added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / rom / dos / allocdosobject.c
blob4289dfcd186d322d7ce734e31840803acc3a5e8e
1 /*
2 Copyright © 1995-2007, 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 <utility/tagitem.h>
12 #include <proto/utility.h>
13 #include <dos/rdargs.h>
14 #include <dos/dostags.h>
15 #include "dos_intern.h"
17 /*****************************************************************************
19 NAME */
20 #include <proto/dos.h>
22 AROS_LH2(APTR, AllocDosObject,
24 /* SYNOPSIS */
25 AROS_LHA(ULONG , type, D1),
26 AROS_LHA(struct TagItem *, tags, D2),
28 /* LOCATION */
29 struct DosLibrary *, DOSBase, 38, Dos)
31 /* FUNCTION
32 Creates a new dos object of a given type. This memory has to be
33 freed with FreeDosObject().
35 INPUTS
36 type - Object type.
37 tags - Pointer to taglist array with additional information. See
38 <dos/dostags.h> for a list of all supported tags.
40 RESULT
41 Pointer to new object or NULL, to indicate an error.
43 NOTES
45 EXAMPLE
47 BUGS
49 SEE ALSO
51 INTERNALS
53 *****************************************************************************/
55 AROS_LIBFUNC_INIT
56 APTR mem;
58 switch(type)
60 case DOS_FILEHANDLE:
61 mem = AllocMem(sizeof(struct FileHandle), MEMF_CLEAR);
63 if (mem != NULL)
65 struct FileHandle *fh = (struct FileHandle *)mem;
67 /* We set fh->fh_Arg1 to point back to 'fh' to make packet
68 emulation possible */
69 fh->fh_CompatibilityHack = fh;
71 else
73 SetIoErr(ERROR_NO_FREE_STORE);
76 return mem;
78 case DOS_FIB:
79 mem = AllocMem(sizeof(struct FileInfoBlock), MEMF_CLEAR);
81 if(mem == NULL)
82 SetIoErr(ERROR_NO_FREE_STORE);
84 return mem;
86 case DOS_STDPKT:
88 struct StandardPacket *sp = AllocMem(sizeof(struct StandardPacket), MEMF_CLEAR);
90 if (sp == NULL) {
91 SetIoErr(ERROR_NO_FREE_STORE);
92 return NULL;
95 sp->sp_Pkt.dp_Link = &(sp->sp_Msg);
96 sp->sp_Msg.mn_Node.ln_Name = (char *) &(sp->sp_Pkt);
98 return (APTR) &(sp->sp_Pkt);
101 case DOS_EXALLCONTROL:
102 mem = AllocMem(sizeof(struct InternalExAllControl), MEMF_CLEAR);
104 if(mem == NULL)
105 SetIoErr(ERROR_NO_FREE_STORE);
107 return mem;
109 case DOS_CLI:
111 struct CommandLineInterface *cli = NULL;
112 struct TagItem defaults[] =
114 /* 0 */ { ADO_DirLen, 255 },
115 /* 1 */ { ADO_CommNameLen, 255 },
116 /* 2 */ { ADO_CommFileLen, 255 },
117 /* 3 */ { ADO_PromptLen, 255 },
118 { TAG_END, 0 }
121 STRPTR dir = NULL;
122 STRPTR command = NULL;
123 STRPTR file = NULL;
124 STRPTR prompt = NULL;
126 /* C has no exceptions. This is a simple replacement. */
127 #define ENOMEM_IF(a) if(a) goto enomem /* Throw out of memory. */
129 cli = AllocMem(sizeof(struct CommandLineInterface), MEMF_CLEAR);
130 ENOMEM_IF(cli == NULL);
132 cli->cli_FailLevel = RETURN_ERROR;
133 cli->cli_Background = DOSTRUE;
134 ApplyTagChanges(defaults, tags);
136 dir = AllocVec(defaults[0].ti_Data + 1, MEMF_PUBLIC | MEMF_CLEAR);
137 ENOMEM_IF(dir == NULL);
139 AROS_BSTR_setstrlen(MKBADDR(dir), 0);
140 cli->cli_SetName = MKBADDR(dir);
142 command = AllocVec(defaults[1].ti_Data + 1,
143 MEMF_PUBLIC | MEMF_CLEAR);
144 ENOMEM_IF(command == NULL);
146 AROS_BSTR_setstrlen(MKBADDR(command), 0);
147 cli->cli_CommandName = MKBADDR(command);
149 file = AllocVec(defaults[2].ti_Data + 1, MEMF_PUBLIC | MEMF_CLEAR);
150 ENOMEM_IF(file == NULL);
152 AROS_BSTR_setstrlen(MKBADDR(file), 0);
153 cli->cli_CommandFile = MKBADDR(file);
155 prompt = AllocVec(defaults[3].ti_Data + 1,
156 MEMF_PUBLIC | MEMF_CLEAR);
157 ENOMEM_IF(prompt == NULL);
159 AROS_BSTR_setstrlen(MKBADDR(prompt), 0);
160 cli->cli_Prompt = MKBADDR(prompt);
162 return cli;
164 enomem:
165 if(cli != NULL)
166 FreeMem(cli, sizeof(struct CommandLineInterface));
168 FreeVec(dir);
169 FreeVec(command);
170 FreeVec(file);
171 FreeVec(prompt);
173 SetIoErr(ERROR_NO_FREE_STORE);
175 return NULL;
178 case DOS_RDARGS:
179 return AllocVec(sizeof(struct RDArgs), MEMF_CLEAR);
182 SetIoErr(ERROR_BAD_NUMBER);
184 return NULL;
186 AROS_LIBFUNC_EXIT
187 } /* AllocDosObject */