Commit d59090a4 authored by Diederik van Arkel's avatar Diederik van Arkel
Browse files

get return code and log from 'system' call;

parent 7c65f197
#ifndef __MACH__
#include <Carbon.h>
# include <Carbon.h>
#else
#include <Carbon/Carbon.h>
# include <Carbon/Carbon.h>
# include <fcntl.h>
#endif
CFBundleRef systemBundle=NULL;
#ifndef __MACH__
typedef int pid_t;
typedef int mode_t;
#define O_WRONLY 0x0001
#define O_CREAT 0x0200
#define O_TRUNC 0x0400
pid_t (*fork_p)(void) = NULL;
int (*execv_p)(const char *path,char *const argv[])=NULL;
pid_t (*waitpid_p)(pid_t wpid,int *status,int options)=NULL;
int (*open_p)(const char *path,int flags,mode_t mode)=NULL;
int (*dup2_p) (int oldd,int newd)=NULL;
int (*close_p) (int d)=NULL;
#endif
#ifndef __MACH__
......@@ -150,9 +159,66 @@ pid_t waitpid (pid_t wpid,int *status,int options)
return r;
}
int open (const char *path,int flags,mode_t mode)
{
int r,t;
if (open_p==NULL){
if (systemBundle==NULL)
initSystemBundle ();
open_p = (int (*)(const char *path,int flags,mode_t mode)) CFBundleGetFunctionPointerForName (systemBundle,CFSTR ("open"));
if (open_p==NULL)
return -1;
}
t=get_toc();
r=(*open_p) (path,flags,mode);
set_toc (t);
return r;
}
int dup2 (int oldd,int newd)
{
int r,t;
if (dup2_p==NULL){
if (systemBundle==NULL)
initSystemBundle ();
dup2_p = (int (*)(int oldd,int newd)) CFBundleGetFunctionPointerForName (systemBundle,CFSTR ("dup2"));
if (dup2_p==NULL)
return -1;
}
t=get_toc();
r=(*dup2_p) (oldd,newd);
set_toc (t);
return r;
}
int close (int d)
{
int r,t;
if (close_p==NULL){
if (systemBundle==NULL)
initSystemBundle ();
close_p = (int (*)(int d)) CFBundleGetFunctionPointerForName (systemBundle,CFSTR ("close"));
if (close_p==NULL)
return -1;
}
t=get_toc();
r=(*close_p) (d);
set_toc (t);
return r;
}
#endif
int fork_execv_waitpid (char *command)
int fork_execv_waitpid (char *command,char *stderr_file_name,int *status_p)
{
char *p,*(argv[2049]);
int argc,result;
......@@ -209,14 +275,25 @@ int fork_execv_waitpid (char *command)
}
argv[argc]=NULL;
if (argc>0){
int pid,status;
int pid;
pid=fork();
if (pid==0)
if (pid==0){
if (stderr_file_name!=NULL && *stderr_file_name!='\0'){
int fd;
fd=open (stderr_file_name,O_CREAT | O_TRUNC | O_WRONLY,0777);
if (fd!=-1){
dup2 (fd,1);
close (fd);
}
}
result=execv (argv[0],argv);
else if (pid!=-1)
waitpid (pid,&status,0);
}
} else if (pid!=-1)
result=waitpid (pid,status_p,0);
} else
result=-1;
return result;
}
......
Supports Markdown
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