2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
5 ANSI C function system().
8 #include "__arosc_privdata.h"
11 //#include <dos/filesystem.h>
12 #include <proto/dos.h>
13 //#include <utility/tagitem.h>
15 //#include <sys/types.h>
23 #include <aros/debug.h>
25 static int system_sh(const char *string
);
26 static int system_no_sh(const char *string
);
28 /*****************************************************************************
54 ******************************************************************************/
60 if (string
== NULL
|| string
[0] == '\0')
62 D(bug("system(cmd=, args=)=1\n"));
66 me
= (struct Process
*) FindTask(NULL
);
67 old_proc_window
= me
->pr_WindowPtr
;
68 me
->pr_WindowPtr
= (APTR
) -1;
69 lock
= Lock((STRPTR
) "bin:sh", SHARED_LOCK
);
70 me
->pr_WindowPtr
= old_proc_window
;
75 return system_sh(string
);
79 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
)
110 struct arosc_privdata
*pdata
= __get_arosc_privdata();
112 char *args
, *cmd
, *fullcmd
;
113 fdesc
*in
, *out
, *err
;
116 D(bug("system_no_sh(%s)\n", string
));
118 args
= strdup(string
);
119 cmd
= strsep(&args
, " \t\n");
123 D(bug("system(cmd=%s, args=%s)\n", cmd
, args
));
125 apath
= __path_u2a(cmd
);
127 fullcmd
= malloc(strlen(apath
) + strlen(args
) + 2);
128 strcpy(fullcmd
, apath
);
129 strcat(fullcmd
, " ");
130 strcat(fullcmd
, args
);
134 in
= pdata
->acpd_fd_array
[STDIN_FILENO
];
135 out
= pdata
->acpd_fd_array
[STDOUT_FILENO
];
136 err
= pdata
->acpd_fd_array
[STDERR_FILENO
];
138 ret
= (int)SystemTags
141 SYS_Input
, (IPTR
)(in
? in
->fcb
->fh
: NULL
),
142 SYS_Output
, (IPTR
)(out
? out
->fcb
->fh
: NULL
),
143 SYS_Error
, (IPTR
)(err
? err
->fcb
->fh
: NULL
),
150 errno
= IoErr2errno(IoErr());