2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
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 /*****************************************************************************
20 #include <proto/dos.h>
22 AROS_LH2(APTR
, AllocDosObject
,
25 AROS_LHA(ULONG
, type
, D1
),
26 AROS_LHA(const struct TagItem
*, tags
, D2
),
29 struct DosLibrary
*, DOSBase
, 38, Dos
)
32 Creates a new dos object of a given type. This memory has to be
33 freed with FreeDosObject().
37 tags - Pointer to taglist array with additional information. See
38 <dos/dostags.h> for a list of all supported tags.
41 Pointer to new object or NULL, to indicate an error.
53 *****************************************************************************/
61 mem
= AllocMem(sizeof(struct FileHandle
), MEMF_CLEAR
);
65 struct FileHandle
*fh
= (struct FileHandle
*)mem
;
73 return AllocMem(sizeof(struct FileInfoBlock
), MEMF_CLEAR
);
76 return allocdospacket();
78 case DOS_EXALLCONTROL
:
79 return AllocMem(sizeof(struct InternalExAllControl
), MEMF_CLEAR
);
83 struct CommandLineInterface
*cli
= NULL
;
84 struct TagItem defaults
[] =
86 /* 0 */ { ADO_DirLen
, 255 },
87 /* 1 */ { ADO_CommNameLen
, 255 },
88 /* 2 */ { ADO_CommFileLen
, 255 },
89 /* 3 */ { ADO_PromptLen
, 255 },
94 STRPTR command
= NULL
;
98 /* C has no exceptions. This is a simple replacement. */
99 #define ENOMEM_IF(a) if(a) goto enomem /* Throw out of memory. */
101 cli
= AllocMem(sizeof(struct CommandLineInterface
), MEMF_CLEAR
);
102 ENOMEM_IF(cli
== NULL
);
104 cli
->cli_FailLevel
= RETURN_ERROR
;
105 cli
->cli_Background
= DOSTRUE
;
106 ApplyTagChanges(defaults
, (struct TagItem
*)tags
);
108 dir
= AllocVec(defaults
[0].ti_Data
+ 1, MEMF_PUBLIC
| MEMF_CLEAR
);
109 ENOMEM_IF(dir
== NULL
);
111 AROS_BSTR_setstrlen(MKBADDR(dir
), 0);
112 cli
->cli_SetName
= MKBADDR(dir
);
114 command
= AllocVec(defaults
[1].ti_Data
+ 1,
115 MEMF_PUBLIC
| MEMF_CLEAR
);
116 ENOMEM_IF(command
== NULL
);
118 AROS_BSTR_setstrlen(MKBADDR(command
), 0);
119 cli
->cli_CommandName
= MKBADDR(command
);
121 file
= AllocVec(defaults
[2].ti_Data
+ 1, MEMF_PUBLIC
| MEMF_CLEAR
);
122 ENOMEM_IF(file
== NULL
);
124 AROS_BSTR_setstrlen(MKBADDR(file
), 0);
125 cli
->cli_CommandFile
= MKBADDR(file
);
127 prompt
= AllocVec(defaults
[3].ti_Data
+ 1,
128 MEMF_PUBLIC
| MEMF_CLEAR
);
129 ENOMEM_IF(prompt
== NULL
);
131 AROS_BSTR_setstrlen(MKBADDR(prompt
), 0);
132 cli
->cli_Prompt
= MKBADDR(prompt
);
138 FreeMem(cli
, sizeof(struct CommandLineInterface
));
145 SetIoErr(ERROR_NO_FREE_STORE
);
151 return AllocVec(sizeof(struct RDArgs
), MEMF_CLEAR
);
154 SetIoErr(ERROR_BAD_NUMBER
);
159 } /* AllocDosObject */
161 /* Internal routines for packet allocation. Does not require DOSBase. */
162 struct DosPacket
*allocdospacket(void)
164 struct StandardPacket
*sp
= AllocMem(sizeof(struct StandardPacket
), MEMF_CLEAR
);
169 sp
->sp_Pkt
.dp_Link
= &sp
->sp_Msg
;
170 sp
->sp_Msg
.mn_Node
.ln_Name
= (char *)&sp
->sp_Pkt
;