summaryrefslogtreecommitdiff
path: root/Kernel/API
diff options
context:
space:
mode:
Diffstat (limited to 'Kernel/API')
-rw-r--r--Kernel/API/POSIX/fcntl.h60
-rw-r--r--Kernel/API/POSIX/sys/types.h101
2 files changed, 161 insertions, 0 deletions
diff --git a/Kernel/API/POSIX/fcntl.h b/Kernel/API/POSIX/fcntl.h
new file mode 100644
index 0000000000..b28cefb678
--- /dev/null
+++ b/Kernel/API/POSIX/fcntl.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <Kernel/API/POSIX/sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define F_DUPFD 0
+#define F_GETFD 1
+#define F_SETFD 2
+#define F_GETFL 3
+#define F_SETFL 4
+#define F_ISTTY 5
+#define F_GETLK 6
+#define F_SETLK 7
+#define F_SETLKW 8
+
+#define FD_CLOEXEC 1
+
+#define O_RDONLY (1 << 0)
+#define O_WRONLY (1 << 1)
+#define O_RDWR (O_RDONLY | O_WRONLY)
+#define O_ACCMODE (O_RDONLY | O_WRONLY)
+#define O_EXEC (1 << 2)
+#define O_CREAT (1 << 3)
+#define O_EXCL (1 << 4)
+#define O_NOCTTY (1 << 5)
+#define O_TRUNC (1 << 6)
+#define O_APPEND (1 << 7)
+#define O_NONBLOCK (1 << 8)
+#define O_DIRECTORY (1 << 9)
+#define O_NOFOLLOW (1 << 10)
+#define O_CLOEXEC (1 << 11)
+#define O_DIRECT (1 << 12)
+
+#define F_RDLCK ((short)0)
+#define F_WRLCK ((short)1)
+#define F_UNLCK ((short)2)
+
+#define AT_FDCWD -100
+#define AT_SYMLINK_NOFOLLOW 0x100
+
+struct flock {
+ short l_type;
+ short l_whence;
+ off_t l_start;
+ off_t l_len;
+ pid_t l_pid;
+};
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/Kernel/API/POSIX/sys/types.h b/Kernel/API/POSIX/sys/types.h
new file mode 100644
index 0000000000..3029e0a101
--- /dev/null
+++ b/Kernel/API/POSIX/sys/types.h
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#ifndef KERNEL
+# include <sys/cdefs.h>
+# include <sys/types.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* There is no __SSIZE_TYPE__ but we can trick the preprocessor into defining it for us anyway! */
+#define unsigned signed
+typedef __SIZE_TYPE__ ssize_t;
+#undef unsigned
+
+typedef unsigned char u_char;
+typedef unsigned short u_short;
+typedef unsigned int u_int;
+typedef unsigned long u_long;
+
+typedef uint32_t uid_t;
+typedef uint32_t gid_t;
+
+typedef int __pid_t;
+#define pid_t __pid_t
+
+typedef char* caddr_t;
+
+typedef int id_t;
+
+typedef uint64_t ino_t;
+typedef int64_t off_t;
+
+typedef uint32_t blkcnt_t;
+typedef uint32_t blksize_t;
+typedef uint32_t dev_t;
+typedef uint16_t mode_t;
+typedef uint32_t nlink_t;
+
+typedef int64_t time_t;
+typedef uint32_t useconds_t;
+typedef int32_t suseconds_t;
+typedef uint32_t clock_t;
+
+typedef uint64_t fsblkcnt_t;
+typedef uint64_t fsfilcnt_t;
+
+#define __socklen_t_defined
+#define __socklen_t uint32_t
+typedef __socklen_t socklen_t;
+
+struct utimbuf {
+ time_t actime;
+ time_t modtime;
+};
+
+typedef int pthread_t;
+typedef int pthread_key_t;
+typedef uint32_t pthread_once_t;
+
+typedef struct __pthread_mutex_t {
+ uint32_t lock;
+ pthread_t owner;
+ int level;
+ int type;
+} pthread_mutex_t;
+
+typedef void* pthread_attr_t;
+typedef struct __pthread_mutexattr_t {
+ int type;
+} pthread_mutexattr_t;
+
+typedef struct __pthread_cond_t {
+ pthread_mutex_t* mutex;
+ uint32_t value;
+ int clockid; // clockid_t
+} pthread_cond_t;
+
+typedef uint64_t pthread_rwlock_t;
+typedef void* pthread_rwlockattr_t;
+typedef struct __pthread_spinlock_t {
+ int m_lock;
+} pthread_spinlock_t;
+typedef struct __pthread_condattr_t {
+ int clockid; // clockid_t
+} pthread_condattr_t;
+
+inline dev_t makedev(unsigned major, unsigned minor) { return (minor & 0xffu) | (major << 8u) | ((minor & ~0xffu) << 12u); }
+inline unsigned int major(dev_t dev) { return (dev & 0xfff00u) >> 8u; }
+inline unsigned int minor(dev_t dev) { return (dev & 0xffu) | ((dev >> 12u) & 0xfff00u); }
+
+#ifdef __cplusplus
+}
+#endif