2018-10-22 13:57:25 +02:00
|
|
|
#include "unistd.h"
|
2018-10-23 10:12:50 +02:00
|
|
|
#include "string.h"
|
2018-10-25 12:06:00 +02:00
|
|
|
#include "errno.h"
|
2018-10-22 13:57:25 +02:00
|
|
|
#include <Kernel/Syscall.h>
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
uid_t getuid()
|
|
|
|
{
|
|
|
|
return Syscall::invoke(Syscall::PosixGetuid);
|
|
|
|
}
|
|
|
|
|
2018-10-25 10:00:37 +02:00
|
|
|
gid_t getgid()
|
2018-10-22 13:57:25 +02:00
|
|
|
{
|
|
|
|
return Syscall::invoke(Syscall::PosixGetgid);
|
|
|
|
}
|
|
|
|
|
2018-10-25 10:00:37 +02:00
|
|
|
pid_t getpid()
|
2018-10-22 13:57:25 +02:00
|
|
|
{
|
|
|
|
return Syscall::invoke(Syscall::PosixGetpid);
|
|
|
|
}
|
|
|
|
|
2018-11-02 12:56:51 +01:00
|
|
|
pid_t setsid()
|
|
|
|
{
|
|
|
|
return Syscall::invoke(Syscall::PosixSetsid);
|
|
|
|
}
|
|
|
|
|
|
|
|
pid_t sys$getsid(pid_t pid)
|
|
|
|
{
|
|
|
|
return Syscall::invoke(Syscall::PosixSetsid, (dword)pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
int setpgid(pid_t pid, pid_t pgid)
|
|
|
|
{
|
|
|
|
return Syscall::invoke(Syscall::PosixSetpgid, (dword)pid, (dword)pgid);
|
|
|
|
}
|
|
|
|
|
|
|
|
pid_t getpgid(pid_t pid)
|
|
|
|
{
|
|
|
|
return Syscall::invoke(Syscall::PosixGetpgid, (dword)pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
pid_t getpgrp()
|
|
|
|
{
|
|
|
|
return Syscall::invoke(Syscall::PosixGetpgrp);
|
|
|
|
}
|
|
|
|
|
2018-10-28 14:11:51 +01:00
|
|
|
int open(const char* path, int options)
|
2018-10-23 10:12:50 +02:00
|
|
|
{
|
2018-10-28 14:11:51 +01:00
|
|
|
int rc = Syscall::invoke(Syscall::PosixOpen, (dword)path, (dword)options);
|
2018-10-25 12:06:00 +02:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-10-23 10:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t read(int fd, void* buf, size_t count)
|
|
|
|
{
|
2018-10-25 12:06:00 +02:00
|
|
|
int rc = Syscall::invoke(Syscall::PosixRead, (dword)fd, (dword)buf, (dword)count);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-10-23 10:12:50 +02:00
|
|
|
}
|
|
|
|
|
2018-10-30 15:33:37 +01:00
|
|
|
ssize_t write(int fd, const void* buf, size_t count)
|
|
|
|
{
|
|
|
|
int rc = Syscall::invoke(Syscall::PosixWrite, (dword)fd, (dword)buf, (dword)count);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-10-30 22:03:02 +01:00
|
|
|
int ttyname_r(int fd, char* buffer, size_t size)
|
|
|
|
{
|
|
|
|
int rc = Syscall::invoke(Syscall::PosixTtynameR, (dword)fd, (dword)buffer, (dword)size);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char ttyname_buf[32];
|
|
|
|
char* ttyname(int fd)
|
|
|
|
{
|
|
|
|
if (ttyname_r(fd, ttyname_buf, sizeof(ttyname_buf)) < 0)
|
|
|
|
return nullptr;
|
|
|
|
return ttyname_buf;
|
|
|
|
}
|
|
|
|
|
2018-10-23 10:12:50 +02:00
|
|
|
int close(int fd)
|
|
|
|
{
|
2018-10-25 12:06:00 +02:00
|
|
|
int rc = Syscall::invoke(Syscall::PosixClose, fd);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-10-23 10:12:50 +02:00
|
|
|
}
|
|
|
|
|
2018-10-27 01:24:22 +02:00
|
|
|
pid_t waitpid(pid_t waitee, int* wstatus, int options)
|
2018-10-24 00:20:34 +02:00
|
|
|
{
|
2018-10-27 01:24:22 +02:00
|
|
|
int rc = Syscall::invoke(Syscall::PosixWaitpid, waitee, (dword)wstatus);
|
2018-10-25 12:06:00 +02:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-10-24 00:20:34 +02:00
|
|
|
}
|
|
|
|
|
2018-10-31 10:14:56 +01:00
|
|
|
int lstat(const char* path, struct stat* statbuf)
|
2018-10-24 13:19:36 +02:00
|
|
|
{
|
2018-10-25 12:06:00 +02:00
|
|
|
int rc = Syscall::invoke(Syscall::PosixLstat, (dword)path, (dword)statbuf);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-10-24 13:19:36 +02:00
|
|
|
}
|
|
|
|
|
2018-10-31 10:14:56 +01:00
|
|
|
int stat(const char* path, struct stat* statbuf)
|
|
|
|
{
|
|
|
|
int rc = Syscall::invoke(Syscall::PosixStat, (dword)path, (dword)statbuf);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-10-26 14:24:11 +02:00
|
|
|
int chdir(const char* path)
|
|
|
|
{
|
|
|
|
int rc = Syscall::invoke(Syscall::PosixChdir, (dword)path);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-10-24 14:28:22 +02:00
|
|
|
char* getcwd(char* buffer, size_t size)
|
|
|
|
{
|
|
|
|
int rc = Syscall::invoke(Syscall::PosixGetcwd, (dword)buffer, (dword)size);
|
2018-10-25 12:06:00 +02:00
|
|
|
__RETURN_WITH_ERRNO(rc, buffer, nullptr);
|
2018-10-24 14:28:22 +02:00
|
|
|
}
|
|
|
|
|
2018-10-25 13:53:49 +02:00
|
|
|
int sleep(unsigned seconds)
|
|
|
|
{
|
|
|
|
return Syscall::invoke(Syscall::Sleep, (dword)seconds);
|
|
|
|
}
|
|
|
|
|
2018-10-26 09:54:29 +02:00
|
|
|
int gethostname(char* buffer, size_t size)
|
|
|
|
{
|
|
|
|
int rc = Syscall::invoke(Syscall::PosixGethostname, (dword)buffer, (dword)size);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-10-28 14:11:51 +01:00
|
|
|
ssize_t readlink(const char* path, char* buffer, size_t size)
|
|
|
|
{
|
|
|
|
int rc = Syscall::invoke(Syscall::PosixReadlink, (dword)path, (dword)buffer, (dword)size);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-10-31 17:50:43 +01:00
|
|
|
off_t lseek(int fd, off_t offset, int whence)
|
|
|
|
{
|
|
|
|
int rc = Syscall::invoke(Syscall::PosixLseek, (dword)fd, (dword)offset, (dword)whence);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-10-22 13:57:25 +02:00
|
|
|
}
|
|
|
|
|