2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 ANSI C function system().
8 #include "__arosc_privdata.h"
11 #include <proto/dos.h>
12 //#include <utility/tagitem.h>
14 //#include <sys/types.h>
22 #include <aros/debug.h>
24 static int system_sh(const char *string
);
25 static int system_no_sh(const char *string
);
27 /*****************************************************************************
53 ******************************************************************************/
60 return system_no_sh(string
);
62 if (string
== NULL
|| string
[0] == '\0')
64 D(bug("system(cmd=, args=)=1\n"));
68 me
= (struct Process
*) FindTask(NULL
);
69 old_proc_window
= me
->pr_WindowPtr
;
70 me
->pr_WindowPtr
= (APTR
) -1;
71 lock
= Lock((STRPTR
) "bin:sh", SHARED_LOCK
);
72 me
->pr_WindowPtr
= old_proc_window
;
77 return system_sh(string
);
80 return system_no_sh(string
);
84 static int system_sh(const char *string
)
89 D(bug("system_sh(%s)\n", string
));
93 if(waitpid(pid
, &status
, 0) == -1)
99 execl((__doupath
? "/bin/sh" : "bin:sh"), "sh", "-c", string
, (char *) NULL
);
108 static int system_no_sh(const char *string
)
111 char *args
, *cmd
, *fullcmd
;
112 fdesc
*in
, *out
, *err
;
115 D(bug("system_no_sh(%s)\n", string
));
117 args
= strdup(string
);
118 cmd
= strsep(&args
, " \t\n");
122 D(bug("system(cmd=%s, args=%s)\n", cmd
, args
));
124 apath
= __path_u2a(cmd
);
126 fullcmd
= malloc(strlen(apath
) + strlen(args
) + 2);
127 strcpy(fullcmd
, apath
);
128 strcat(fullcmd
, " ");
129 strcat(fullcmd
, args
);
133 in
= __getfdesc(STDIN_FILENO
);
134 out
= __getfdesc(STDOUT_FILENO
);
135 err
= __getfdesc(STDERR_FILENO
);
137 ret
= (int)SystemTags
140 SYS_Input
, (IPTR
)(in
? in
->fcb
->fh
: BNULL
),
141 SYS_Output
, (IPTR
)(out
? out
->fcb
->fh
: BNULL
),
142 SYS_Error
, (IPTR
)(err
? err
->fcb
->fh
: BNULL
),
149 errno
= IoErr2errno(IoErr());