2 Copyright © 1995-2012, 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 ******************************************************************************/
55 struct aroscbase
*aroscbase
= __GM_GetBase();
60 if (!aroscbase
->acb_doupath
)
61 return system_no_sh(string
);
63 if (string
== NULL
|| string
[0] == '\0')
65 D(bug("system(cmd=, args=)=1\n"));
69 me
= (struct Process
*) FindTask(NULL
);
70 old_proc_window
= me
->pr_WindowPtr
;
71 me
->pr_WindowPtr
= (APTR
) -1;
72 lock
= Lock((STRPTR
) "bin:sh", SHARED_LOCK
);
73 me
->pr_WindowPtr
= old_proc_window
;
78 return system_sh(string
);
81 return system_no_sh(string
);
85 static int system_sh(const char *string
)
87 struct aroscbase
*aroscbase
= __GM_GetBase();
91 D(bug("system_sh(%s)\n", string
));
95 if(waitpid(pid
, &status
, 0) == -1)
101 execl((aroscbase
->acb_doupath
? "/bin/sh" : "bin:sh"), "sh", "-c", string
, (char *) NULL
);
110 static int system_no_sh(const char *string
)
113 char *args
, *cmd
, *fullcmd
;
114 fdesc
*in
, *out
, *err
;
117 D(bug("system_no_sh(%s)\n", string
));
119 args
= strdup(string
);
120 cmd
= strsep(&args
, " \t\n");
124 D(bug("system(cmd=%s, args=%s)\n", cmd
, args
));
126 apath
= __path_u2a(cmd
);
128 fullcmd
= malloc(strlen(apath
) + strlen(args
) + 2);
129 strcpy(fullcmd
, apath
);
130 strcat(fullcmd
, " ");
131 strcat(fullcmd
, args
);
135 in
= __getfdesc(STDIN_FILENO
);
136 out
= __getfdesc(STDOUT_FILENO
);
137 err
= __getfdesc(STDERR_FILENO
);
139 ret
= (int)SystemTags
142 SYS_Input
, (IPTR
)(in
? in
->fcb
->fh
: BNULL
),
143 SYS_Output
, (IPTR
)(out
? out
->fcb
->fh
: BNULL
),
144 SYS_Error
, (IPTR
)(err
? err
->fcb
->fh
: BNULL
),
151 errno
= IoErr2errno(IoErr());