Luna/libs/libc/src/unistd.cpp

74 lines
1.9 KiB
C++
Raw Normal View History

#include <bits/error.h>
#include <luna.h>
#include <luna/syscall.h>
#include <stdarg.h>
#include <unistd.h>
extern "C"
{
int execv(const char*, char* const[])
{
NOT_IMPLEMENTED("execv");
}
int execve(const char*, char* const[], char* const[])
{
NOT_IMPLEMENTED("execve");
}
int execvp(const char*, char* const[])
{
NOT_IMPLEMENTED("execvp");
}
pid_t fork(void)
{
NOT_IMPLEMENTED("fork");
}
long syscall(long number, ...)
{
typedef unsigned long int arg;
long result;
va_list ap;
va_start(ap, number);
switch (number)
{
case SYS_exit:
case SYS_yield:
case SYS_gettid:
case SYS_rand: result = __luna_syscall0(number); break;
case SYS_sleep: result = __luna_syscall1(number, va_arg(ap, arg)); break;
case SYS_write:
case SYS_munmap:
2022-10-02 15:25:56 +00:00
case SYS_getversion: {
arg arg0 = va_arg(ap, arg);
arg arg1 = va_arg(ap, arg);
result = __luna_syscall2(number, arg0, arg1);
break;
}
case SYS_mmap: {
arg arg0 = va_arg(ap, arg);
arg arg1 = va_arg(ap, arg);
arg arg2 = va_arg(ap, arg);
result = __luna_syscall3(number, arg0, arg1, arg2);
break;
}
case SYS_paint: {
arg arg0 = va_arg(ap, arg);
arg arg1 = va_arg(ap, arg);
arg arg2 = va_arg(ap, arg);
arg arg3 = va_arg(ap, arg);
arg arg4 = va_arg(ap, arg);
result = __luna_syscall5(number, arg0, arg1, arg2, arg3, arg4);
break;
}
default: result = -1; break;
}
va_end(ap);
if (number == SYS_mmap) { _RETURN_WITH_MEMORY_ERRNO(result, long int); }
else { _RETURN_WITH_ERRNO(result, long); }
}
unsigned int sleep(unsigned int seconds)
{
return msleep(seconds * 1000);
}
}