forked from johnothwolo/noah
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoah.h
73 lines (61 loc) · 1.39 KB
/
noah.h
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
typedef unsigned long uint64_t;
typedef unsigned long size_t;
typedef long ssize_t;
uint64_t syscall(uint64_t num, uint64_t rdi, uint64_t rsi, uint64_t rdx)
{
uint64_t ret;
asm("syscall"
: "=rax" (ret)
: "0" (num), "D" (rdi), "S" (rsi), "d" (rdx)
: "cc", "memory", "r11", "rcx"
);
return ret;
}
#define SYS_read 0
#define SYS_write 1
#define SYS_open 2
#define SYS_close 3
#define SYS_exit 60
#define SYS_rename 82
#define O_RDONLY 0
ssize_t read(int fd, void *buf, size_t count)
{
return syscall(SYS_read, fd, (uint64_t)buf, count);
}
ssize_t write(int fd, const void *buf, size_t count)
{
return syscall(SYS_write, fd, (uint64_t)buf, count);
}
int open(const char *path, int flags)
{
return syscall(SYS_open, (uint64_t)path, flags, 0);
}
int rename(const char *oldpath, const char *newpath)
{
return syscall(SYS_rename, (uint64_t)oldpath, (uint64_t)newpath, 0);
}
int close(unsigned int fd)
{
return syscall(SYS_close, fd, 0, 0);
}
void _exit(int status)
{
syscall(SYS_exit, status, 0, 0);
__builtin_unreachable();
}
int _main(int argc, char **argv)
{
typedef int (*main_t)(int, char **, char **);
int main();
_exit(((main_t)main)(argc, argv, argv + argc + 1));
}
size_t strlen(const char *str)
{
const char *s;
for (s = str; *s; s++);
return s - str;
}
int strcmp(const char *s, const char *t) {
while (*s && *s == *t) s++, t++;
return *s - *t;
}