Commit 7e4600b7 authored by John van Groningen's avatar John van Groningen

add function fork_execv_pid

parent 5d39d781
......@@ -218,17 +218,10 @@ int close (int d)
}
#endif
int fork_execv_waitpid (char *command,char *stderr_file_name,int *status_p)
static int parse_arguments (char *command,char **argv)
{
char *p,*(argv[2049]);
int argc,result;
#ifndef __MACH__
if (!initSystemBundle())
return -1;
#endif
result=0;
char *p;
int argc;
argc=0;
p=command;
......@@ -274,6 +267,24 @@ int fork_execv_waitpid (char *command,char *stderr_file_name,int *status_p)
++p;
}
argv[argc]=NULL;
return argc;
}
int fork_execv_waitpid (char *command,char *stderr_file_name,int *status_p)
{
char *(argv[2049]);
int argc,result;
#ifndef __MACH__
if (!initSystemBundle())
return -1;
#endif
result=0;
argc=parse_arguments (command,argv);
if (argc>0){
int pid;
......@@ -300,7 +311,6 @@ int fork_execv_waitpid (char *command,char *stderr_file_name,int *status_p)
int fork_execv (char *p_command)
{
char *p;
char *(argv[2049]);
int argc,result;
char *command;
......@@ -325,63 +335,70 @@ int fork_execv (char *p_command)
}
result=0;
argc=parse_arguments (command,argv);
argc=0;
p=command;
if (argc>0){
int pid;
pid=fork();
if (pid==0)
result=execv (argv[0],argv);
else if (pid!=-1)
result=0;
else
result=1;
}
while (*p==' ' || *p=='\t')
++p;
DisposePtr (command);
while (*p!='\0' && argc<2048){
if (*p=='\''){
char c,*d_p;
++p;
argv[argc]=p;
return result;
}
d_p=p;
c=*p;
while (!(c=='\'' && p[1]!='\'') && c!='\0'){
*d_p++=c;
if (c=='\'')
++p;
c=*++p;
}
if (*p=='\0'){
*d_p='\0';
break;
}
++argc;
*d_p='\0';
++p;
} else {
argv[argc++]=p;
while (*p!=' ' && *p!='\t' && *p!='\0')
++p;
int fork_execv_pid (char *p_command,int *pid_p)
{
char *(argv[2049]);
int argc,result;
char *command;
#ifndef __MACH__
if (!initSystemBundle())
return -1;
#endif
{
char *p,*d_p;
for (p=p_command; *p!='\0'; ++p)
;
if (*p!='\0')
*p++='\0';
}
while (*p==' ' || *p=='\t')
++p;
command=NewPtr (p+1-p_command);
d_p=command;
for (p=p_command; *p!='\0'; ++p)
*d_p++=*p;
*d_p='\0';
}
argv[argc]=NULL;
result=0;
argc=parse_arguments (command,argv);
if (argc>0){
int pid;
pid=fork();
*pid_p=pid;
if (pid==0)
result=execv (argv[0],argv);
else if (pid!=-1)
result=0;
else
result=1;
}
} else
*pid_p=0;
DisposePtr (command);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment