166 lines
3.3 KiB
C++
166 lines
3.3 KiB
C++
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <luna.h>
|
|
#include <luna/syscall.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/syscall.h>
|
|
#include <unistd.h>
|
|
|
|
extern "C"
|
|
{
|
|
int execv(const char* program, char* const argv[])
|
|
{
|
|
return (int)__lc_fast_syscall2(SYS_execv, program, argv);
|
|
}
|
|
|
|
int execve(const char*, char* const[], char* const[])
|
|
{
|
|
NOT_IMPLEMENTED("execve");
|
|
}
|
|
int execvp(const char*, char* const[])
|
|
{
|
|
NOT_IMPLEMENTED("execvp");
|
|
}
|
|
|
|
pid_t fork(void)
|
|
{
|
|
return __lc_fast_syscall0(SYS_fork);
|
|
}
|
|
|
|
pid_t getpid(void)
|
|
{
|
|
return getprocid(ID_PID);
|
|
}
|
|
|
|
pid_t getppid(void)
|
|
{
|
|
return getprocid(ID_PPID);
|
|
}
|
|
|
|
uid_t getuid(void)
|
|
{
|
|
return (uid_t)getprocid(ID_UID);
|
|
}
|
|
|
|
uid_t geteuid(void)
|
|
{
|
|
return (uid_t)getprocid(ID_EUID);
|
|
}
|
|
|
|
gid_t getgid(void)
|
|
{
|
|
return (gid_t)getprocid(ID_GID);
|
|
}
|
|
|
|
gid_t getegid(void)
|
|
{
|
|
return (gid_t)getprocid(ID_EGID);
|
|
}
|
|
|
|
int setuid(uid_t uid)
|
|
{
|
|
return (int)__lc_fast_syscall2(SYS_setuid, uid, uid);
|
|
}
|
|
|
|
int seteuid(uid_t uid)
|
|
{
|
|
return (int)__lc_fast_syscall2(SYS_setuid, getprocid(ID_UID), uid);
|
|
}
|
|
|
|
int setgid(gid_t gid)
|
|
{
|
|
return (int)__lc_fast_syscall2(SYS_setgid, gid, gid);
|
|
}
|
|
|
|
int setegid(gid_t gid)
|
|
{
|
|
return (int)__lc_fast_syscall2(SYS_setgid, getprocid(ID_GID), gid);
|
|
}
|
|
|
|
unsigned int sleep(unsigned int seconds)
|
|
{
|
|
return msleep(seconds * 1000);
|
|
}
|
|
|
|
ssize_t read(int fd, void* buf, size_t count)
|
|
{
|
|
return __lc_fast_syscall3(SYS_read, fd, count, buf); // yes, our read() syscall is in the wrong order.
|
|
}
|
|
|
|
ssize_t write(int fd, const void* buf, size_t count)
|
|
{
|
|
return __lc_fast_syscall3(SYS_write, fd, count, buf); // yes, our write() syscall is in the wrong order.
|
|
}
|
|
|
|
int close(int fd)
|
|
{
|
|
return (int)__lc_fast_syscall1(SYS_close, fd);
|
|
}
|
|
|
|
off_t lseek(int fd, off_t offset, int whence)
|
|
{
|
|
return __lc_fast_syscall3(SYS_seek, fd, offset, whence);
|
|
}
|
|
|
|
__lc_noreturn void _exit(int status)
|
|
{
|
|
__lc_fast_syscall1(SYS_exit, status);
|
|
__lc_unreachable();
|
|
}
|
|
|
|
int dup(int fd)
|
|
{
|
|
return fcntl(fd, F_DUPFD, 0);
|
|
}
|
|
|
|
int dup2(int fd, int fd2)
|
|
{
|
|
return (int)__lc_fast_syscall2(SYS_dup2, fd, fd2);
|
|
}
|
|
|
|
int access(const char* path, int amode)
|
|
{
|
|
return (int)__lc_fast_syscall2(SYS_access, path, amode);
|
|
}
|
|
|
|
int isatty(int fd)
|
|
{
|
|
int result = fcntl(fd, F_ISTTY);
|
|
if (result < 0) return 0;
|
|
return 1;
|
|
}
|
|
|
|
char* getcwd(char* buf, size_t size)
|
|
{
|
|
const char* dummy_cwd = "/"; // FIXME: Actually retrieve the current working directory from the kernel.
|
|
if (size < 2)
|
|
{
|
|
errno = ERANGE;
|
|
return NULL;
|
|
}
|
|
if (!buf) { buf = (char*)malloc(size); }
|
|
strlcpy(buf, dummy_cwd, 2);
|
|
return buf;
|
|
}
|
|
|
|
int unlink(const char*)
|
|
{
|
|
NOT_IMPLEMENTED("unlink");
|
|
}
|
|
|
|
int rmdir(const char*)
|
|
{
|
|
NOT_IMPLEMENTED("rmdir");
|
|
}
|
|
|
|
int chdir(const char*)
|
|
{
|
|
NOT_IMPLEMENTED("chdir");
|
|
}
|
|
|
|
int pipe(int[2])
|
|
{
|
|
NOT_IMPLEMENTED("pipe");
|
|
}
|
|
} |