2 Copyright © 1995-2013 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
= AllocVec(sizeof(struct FileHandle
), MEMF_CLEAR
);
65 struct FileHandle
*fh
= (struct FileHandle
*)mem
;
70 fh
->fh_Func2
= DOS_FH_MAGIC
;
75 return AllocVec(sizeof(struct FileInfoBlock
), MEMF_CLEAR
);
78 return allocdospacket();
80 case DOS_EXALLCONTROL
:
81 return AllocVec(sizeof(struct InternalExAllControl
), MEMF_CLEAR
);
85 struct CommandLineInterface
*cli
= NULL
;
86 struct TagItem defaults
[] =
88 /* 0 */ { ADO_DirLen
, 255 },
89 /* 1 */ { ADO_CommNameLen
, 255 },
90 /* 2 */ { ADO_CommFileLen
, 255 },
91 /* 3 */ { ADO_PromptLen
, 255 },
96 STRPTR command
= NULL
;
100 /* C has no exceptions. This is a simple replacement. */
101 #define ENOMEM_IF(a) if(a) goto enomem /* Throw out of memory. */
103 cli
= AllocVec(sizeof(struct CommandLineInterface
), MEMF_CLEAR
);
104 ENOMEM_IF(cli
== NULL
);
106 cli
->cli_FailLevel
= RETURN_ERROR
;
107 cli
->cli_Background
= DOSTRUE
;
108 ApplyTagChanges(defaults
, (struct TagItem
*)tags
);
110 dir
= AllocVec(defaults
[0].ti_Data
+ 1, MEMF_PUBLIC
| MEMF_CLEAR
);
111 ENOMEM_IF(dir
== NULL
);
113 AROS_BSTR_setstrlen(MKBADDR(dir
), 0);
114 cli
->cli_SetName
= MKBADDR(dir
);
116 command
= AllocVec(defaults
[1].ti_Data
+ 1,
117 MEMF_PUBLIC
| MEMF_CLEAR
);
118 ENOMEM_IF(command
== NULL
);
120 AROS_BSTR_setstrlen(MKBADDR(command
), 0);
121 cli
->cli_CommandName
= MKBADDR(command
);
123 file
= AllocVec(defaults
[2].ti_Data
+ 1, MEMF_PUBLIC
| MEMF_CLEAR
);
124 ENOMEM_IF(file
== NULL
);
126 AROS_BSTR_setstrlen(MKBADDR(file
), 0);
127 cli
->cli_CommandFile
= MKBADDR(file
);
129 prompt
= AllocVec(defaults
[3].ti_Data
+ 1,
130 MEMF_PUBLIC
| MEMF_CLEAR
);
131 ENOMEM_IF(prompt
== NULL
);
133 AROS_BSTR_setstrlen(MKBADDR(prompt
), 0);
134 cli
->cli_Prompt
= MKBADDR(prompt
);
146 SetIoErr(ERROR_NO_FREE_STORE
);
152 return AllocVec(sizeof(struct RDArgs
), MEMF_CLEAR
);
155 SetIoErr(ERROR_BAD_NUMBER
);
160 } /* AllocDosObject */
162 /* Internal routines for packet allocation. Does not require DOSBase. */
163 struct DosPacket
*allocdospacket(void)
165 struct StandardPacket
*sp
= AllocVec(sizeof(struct StandardPacket
), MEMF_CLEAR
);
170 sp
->sp_Pkt
.dp_Link
= &sp
->sp_Msg
;
171 sp
->sp_Msg
.mn_Node
.ln_Name
= (char *)&sp
->sp_Pkt
;