Fix for the (stupid) case of app (always) passing
[tangerine.git] / rom / dos / runcommand.c
blob4094bfc62ed59f4b452d71377d55fdb748351e0d
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Execute a loaded command synchonously
6 Lang: english
7 */
8 #include <exec/memory.h>
9 #include <proto/exec.h>
10 #include <utility/tagitem.h>
11 #include <dos/filesystem.h>
12 #include <proto/dos.h>
13 #include "dos_intern.h"
15 LONG AROS_SLIB_ENTRY(RunProcess,Dos)
17 struct Process * proc,
18 struct StackSwapStruct * sss,
19 STRPTR argptr,
20 ULONG argsize,
21 LONG_FUNC entry,
22 struct DosLibrary * DOSBase
25 /*****************************************************************************
27 NAME */
28 #include <proto/dos.h>
30 AROS_LH4(LONG, RunCommand,
32 /* SYNOPSIS */
33 AROS_LHA(BPTR, segList, D1),
34 AROS_LHA(ULONG, stacksize, D2),
35 AROS_LHA(STRPTR, argptr, D3),
36 AROS_LHA(ULONG, argsize, D4),
38 /* LOCATION */
39 struct DosLibrary *, DOSBase, 84, Dos)
41 /* FUNCTION
42 RunCommand() will run the command loaded in the |segList| with the
43 arguments specified with a new stack of |stacksize| bytes. Note
44 that the stacksize may be extended if this is required.
46 The return code of the command run will be returned.
48 AROS ONLY: RunCommand() automatically computes argsize
49 automatically if you pass -1.
51 This call will not return until the command has completed.
53 INPUTS
54 segList - segment of program to run.
55 stacksize - size of the stack to use.
56 argptr - pointer to NULL-terminated arguments.
57 argsize - size of the arguments string.
59 RESULT
60 The return code from the program. See also IoErr().
62 NOTES
63 Programs expect the arugment string to end with a newline ('\n')
64 character (ReadArgs() requires it to work properly).
66 EXAMPLE
68 BUGS
70 SEE ALSO
71 SystemTagList()
73 INTERNALS
75 *****************************************************************************/
77 AROS_LIBFUNC_INIT
78 AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
80 STRPTR oldargs;
81 LONG oldresult;
83 /* Get pointer to process structure */
84 struct Process *me=(struct Process *)FindTask(NULL);
86 UBYTE *stack;
87 LONG ret;
88 struct StackSwapStruct sss;
90 if(stacksize < AROS_STACKSIZE)
91 stacksize = AROS_STACKSIZE;
93 stack=(UBYTE *)AllocMem(stacksize,MEMF_ANY);
94 if(stack==NULL)
95 return -1;
97 sss.stk_Lower=stack;
98 sss.stk_Upper=stack+stacksize;
100 oldresult=me->pr_Result2;
102 me->pr_Result2=oldresult;
104 oldargs=me->pr_Arguments;
105 me->pr_Arguments=argptr;
107 ret=AROS_SLIB_ENTRY(RunProcess,Dos)(me,&sss,argptr,argsize,
108 (LONG_FUNC)((BPTR *)BADDR(segList)+1),DOSBase);
109 me->pr_Arguments=oldargs;
111 oldresult=me->pr_Result2;
113 me->pr_Result2=oldresult;
115 FreeMem(stack,stacksize);
117 return ret;
119 AROS_LIBFUNC_EXIT
121 } /* RunCommand */