summaryrefslogtreecommitdiff
path: root/LibC/unistd.cpp
blob: da7e5591032c0e1f8d6d67214f982e274cdd960c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "unistd.h"
#include "string.h"
#include "errno.h"
#include <Kernel/Syscall.h>

extern "C" {

uid_t getuid()
{
    return Syscall::invoke(Syscall::PosixGetuid);
}

gid_t getgid()
{
    return Syscall::invoke(Syscall::PosixGetgid);
}

pid_t getpid()
{
    return Syscall::invoke(Syscall::PosixGetpid);
}

int open(const char* path)
{
    size_t length = strlen(path);
    int rc = Syscall::invoke(Syscall::PosixOpen, (dword)path, (dword)length);
    __RETURN_WITH_ERRNO(rc, rc, -1);
}

ssize_t read(int fd, void* buf, size_t count)
{
    int rc = Syscall::invoke(Syscall::PosixRead, (dword)fd, (dword)buf, (dword)count);
    __RETURN_WITH_ERRNO(rc, rc, -1);
}

int close(int fd)
{
    int rc = Syscall::invoke(Syscall::PosixClose, fd);
    __RETURN_WITH_ERRNO(rc, rc, -1);
}

pid_t waitpid(pid_t waitee)
{
    int rc = Syscall::invoke(Syscall::PosixWaitpid, waitee);
    __RETURN_WITH_ERRNO(rc, rc, -1);
}

int lstat(const char* path, stat* statbuf)
{
    int rc = Syscall::invoke(Syscall::PosixLstat, (dword)path, (dword)statbuf);
    __RETURN_WITH_ERRNO(rc, rc, -1);
}

int chdir(const char* path)
{
    int rc = Syscall::invoke(Syscall::PosixChdir, (dword)path);
    __RETURN_WITH_ERRNO(rc, rc, -1);
}

char* getcwd(char* buffer, size_t size)
{
    int rc = Syscall::invoke(Syscall::PosixGetcwd, (dword)buffer, (dword)size);
    __RETURN_WITH_ERRNO(rc, buffer, nullptr);
}

int sleep(unsigned seconds)
{
    return Syscall::invoke(Syscall::Sleep, (dword)seconds);
}

int gethostname(char* buffer, size_t size)
{
    int rc = Syscall::invoke(Syscall::PosixGethostname, (dword)buffer, (dword)size);
    __RETURN_WITH_ERRNO(rc, rc, -1);
}

}