summaryrefslogtreecommitdiff
path: root/nonstd/stubs
diff options
context:
space:
mode:
Diffstat (limited to 'nonstd/stubs')
-rw-r--r--nonstd/stubs/fcntl.h48
-rw-r--r--nonstd/stubs/inttypes.h6
-rw-r--r--nonstd/stubs/sys/mman.h13
-rw-r--r--nonstd/stubs/sys/stat.h0
-rw-r--r--nonstd/stubs/sys/types.h1
-rw-r--r--nonstd/stubs/unistd.h15
-rw-r--r--nonstd/stubs/wchar.h9
7 files changed, 92 insertions, 0 deletions
diff --git a/nonstd/stubs/fcntl.h b/nonstd/stubs/fcntl.h
new file mode 100644
index 00000000..2c737603
--- /dev/null
+++ b/nonstd/stubs/fcntl.h
@@ -0,0 +1,48 @@
+#ifndef __FCNTL_H__
+#define __FCNTL_H__
+#include "nonstd/types.h"
+
+#define F_DUPFD 1
+#define F_DUPFD_CLOEXEC 2
+#define F_GETFD 3
+#define F_SETFD 4
+#define F_GETFL 5
+#define F_SETFL 6
+#define F_GETLK 7
+#define F_SETLK 8
+#define F_SETLKW 9
+#define F_GETOWN 10
+#define F_SETOWN 11
+
+#define FD_CLOEXEC 1
+
+#define F_RDLCK 1
+#define F_UNLCK 2
+#define F_WRLCK 3
+
+#define O_CLOEXEC 02000000
+#define O_CREAT (1 << 1)
+#define O_DIRECTORY (1 << 2)
+#define O_EXCL (1 << 3)
+#define O_NCTTY (1 << 4)
+#define O_NOFOLLOW (1 << 5)
+#define O_TRUNC (1 << 6)
+#define O_TTY_INIT (1 << 7)
+
+#define O_APPEND (1 << 8)
+#define O_DSYNC (1 << 9)
+#define O_NONBLOCK (1 << 10)
+#define O_RSYNC (1 << 11)
+#define O_SYNC (1 << 12)
+
+#define O_EXEC (1 << 13)
+#define O_RDONLY (1 << 14)
+#define O_RDWR 02
+#define O_SEARCH (1 << 16)
+#define O_WRONLY (1 << 17)
+
+#define O_ACCMODE (O_EXEC|O_RDONLY|O_RDWR|O_SEARCH|O_WRONLY)
+
+#define open(path, mode, flags) __libc.syscall(__libc.syscall_lookup("open"), path, mode, flags)
+
+#endif
diff --git a/nonstd/stubs/inttypes.h b/nonstd/stubs/inttypes.h
new file mode 100644
index 00000000..acaa97af
--- /dev/null
+++ b/nonstd/stubs/inttypes.h
@@ -0,0 +1,6 @@
+#define SIZE_MAX 0xffffffff
+typedef long long int intmax_t;
+typedef unsigned long long int uintmax_t;
+typedef unsigned long int intptr_t;
+intmax_t strtoimax(const char *, char **, int);
+uintmax_t strtoumax(const char *, char **, int);
diff --git a/nonstd/stubs/sys/mman.h b/nonstd/stubs/sys/mman.h
new file mode 100644
index 00000000..01a201eb
--- /dev/null
+++ b/nonstd/stubs/sys/mman.h
@@ -0,0 +1,13 @@
+#include "nonstd/types.h"
+
+#ifndef PROT_READ
+# define PROT_READ 0x1
+#endif
+#ifndef PROT_WRITE
+# define PROT_WRITE 0x2
+#endif
+#ifndef MAP_PRIVATE
+# define MAP_PRIVATE 0x02
+#endif
+
+#define mmap(_a, _l, _p, _f, _d, _o) __libc.syscall(__libc.syscall_lookup("mmap"), _a, _l, _p, _f, _d, _o)
diff --git a/nonstd/stubs/sys/stat.h b/nonstd/stubs/sys/stat.h
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/nonstd/stubs/sys/stat.h
diff --git a/nonstd/stubs/sys/types.h b/nonstd/stubs/sys/types.h
new file mode 100644
index 00000000..5fe25895
--- /dev/null
+++ b/nonstd/stubs/sys/types.h
@@ -0,0 +1 @@
+typedef int pid_t;
diff --git a/nonstd/stubs/unistd.h b/nonstd/stubs/unistd.h
new file mode 100644
index 00000000..8e16c2e8
--- /dev/null
+++ b/nonstd/stubs/unistd.h
@@ -0,0 +1,15 @@
+#ifndef __UNISTD_H__
+#define __UNISTD_H__
+
+#include <stddef.h>
+#include "nonstd/syscall.h"
+
+#define open(path, mode, flags) __libc.syscall(__libc.syscall_lookup("open"), path, mode, flags)
+#define close(fd) __libc.syscall(__libc.syscall_lookup("close"), fd)
+#define write(fd, buf, nbyte) __libc.syscall(__libc.syscall_lookup("write"), fd, buf, nbyte)
+#define read(fd, buf, nbyte) __libc.syscall(__libc.syscall_lookup("read"), fd, buf, nbyte)
+#define kill(pid, sig) __libc.syscall(__libc.syscall_lookup("kill"), pid, sig)
+#define getpid() __libc.syscall(__libc.syscall_lookup("getpid"))
+#define _exit(status) __libc.syscall(__libc.syscall_lookup("exit"), status)
+
+#endif
diff --git a/nonstd/stubs/wchar.h b/nonstd/stubs/wchar.h
new file mode 100644
index 00000000..0bdc95cb
--- /dev/null
+++ b/nonstd/stubs/wchar.h
@@ -0,0 +1,9 @@
+#include <stddef.h>
+#define WEOF (-1L)
+typedef int mbstate_t;
+typedef int wint_t;
+size_t mbrlen(const char * restrict, size_t, mbstate_t * restrict);
+size_t mbsrtowcs(wchar_t * restrict, const char * restrict, size_t, mbstate_t * restrict);
+size_t mbrtowc(wchar_t * restrict, const char * restrict, size_t, mbstate_t * restrict);
+size_t wcrtomb(char * restrict, wchar_t, mbstate_t * restrict);
+wint_t btowc(int);