Gaius
---------------------------
#include <sys/syscall.h>
#include <stdarg.h>
#include <errno.h>
#if !defined(TRUE)
# define TRUE (1==1)
#endif
#if !defined(FALSE)
# define FALSE (1==0)
#endif
extern int read (int, void *, int);
extern int write (int, void *, int);
static int (*syscalls[200])();
static int initialized = 0;
int mywrite (int fd, void *buf, int len)
{
return write (fd, buf, len);
}
int
SYSTEM_UNIXCALL (int syscall, int *r0, int *r1, ...)
{
va_list ap;
int p1, p2, p3;
if (! initialized)
_M2_SYSTEM_init();
va_start (ap, r1);
p1 = va_arg (ap, int);
p2 = va_arg (ap, int);
p3 = va_arg (ap, int);
*r0 = (*syscalls[syscall]) (p1, p2, p3);
va_end (ap);
return (*r0) >= 0;
}
/*
* UNIXFORK - returns TRUE if successful and pid is set to the son pid
* if the parent is returning. If the child is returning pid=0.
* UNIXFORK returns FALSE if an error occurs and errno is held in
pid.
*/
int
SYSTEM_UNIXFORK (unsigned int *pid)
{
int p = fork();
if (p == -1) {
*pid = errno;
return FALSE;
}
*pid = p;
return TRUE;
}
_M2_SYSTEM_init ()
{
syscalls[__NR_write] = (void *)mywrite;
syscalls[__NR_read] = (void *)read;
initialized = 1;
}
_______________________________________________
gm2 mailing list
address@hidden
http://floppsie.comp.glam.ac.uk/mailman/listinfo/gm2