summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Kernel/API/POSIX/fcntl.h60
-rw-r--r--Kernel/API/POSIX/sys/types.h101
-rw-r--r--Kernel/UnixTypes.h34
-rw-r--r--Userland/Libraries/LibC/fcntl.cpp1
-rw-r--r--Userland/Libraries/LibC/fcntl.h45
-rw-r--r--Userland/Libraries/LibC/sys/types.h87
6 files changed, 166 insertions, 162 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
diff --git a/Kernel/UnixTypes.h b/Kernel/UnixTypes.h
index 1edee66b9e..a71b9ec5dc 100644
--- a/Kernel/UnixTypes.h
+++ b/Kernel/UnixTypes.h
@@ -8,22 +8,7 @@
#include <AK/DistinctNumeric.h>
#include <AK/Types.h>
-
-#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)
+#include <Kernel/API/POSIX/fcntl.h>
// Kernel internal options.
#define O_NOFOLLOW_NOERROR (1 << 29)
@@ -426,11 +411,6 @@ struct sigaction {
typedef i64 off_t;
typedef i64 time_t;
-struct utimbuf {
- time_t actime;
- time_t modtime;
-};
-
typedef u32 blksize_t;
typedef u32 blkcnt_t;
@@ -770,15 +750,3 @@ struct statvfs {
unsigned long f_flag;
unsigned long f_namemax;
};
-
-#define F_RDLCK ((short)0)
-#define F_WRLCK ((short)1)
-#define F_UNLCK ((short)2)
-
-struct flock {
- short l_type;
- short l_whence;
- off_t l_start;
- off_t l_len;
- pid_t l_pid;
-};
diff --git a/Userland/Libraries/LibC/fcntl.cpp b/Userland/Libraries/LibC/fcntl.cpp
index 675856fc25..a4e74fc9ea 100644
--- a/Userland/Libraries/LibC/fcntl.cpp
+++ b/Userland/Libraries/LibC/fcntl.cpp
@@ -7,6 +7,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
#include <stdarg.h>
#include <string.h>
#include <syscall.h>
diff --git a/Userland/Libraries/LibC/fcntl.h b/Userland/Libraries/LibC/fcntl.h
index 463e3ba060..7056d874a9 100644
--- a/Userland/Libraries/LibC/fcntl.h
+++ b/Userland/Libraries/LibC/fcntl.h
@@ -7,43 +7,12 @@
#pragma once
-#include <sys/cdefs.h>
-#include <sys/types.h>
+#include <Kernel/API/POSIX/fcntl.h>
__BEGIN_DECLS
-#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)
-
int creat(const char* path, mode_t);
int open(const char* path, int options, ...);
-#define AT_FDCWD -100
-#define AT_SYMLINK_NOFOLLOW 0x100
int openat(int dirfd, const char* path, int options, ...);
int fcntl(int fd, int cmd, ...);
@@ -51,16 +20,4 @@ int create_inode_watcher(unsigned flags);
int inode_watcher_add_watch(int fd, const char* path, size_t path_length, unsigned event_mask);
int inode_watcher_remove_watch(int fd, int wd);
-#define F_RDLCK ((short)0)
-#define F_WRLCK ((short)1)
-#define F_UNLCK ((short)2)
-
-struct flock {
- short l_type;
- short l_whence;
- off_t l_start;
- off_t l_len;
- pid_t l_pid;
-};
-
__END_DECLS
diff --git a/Userland/Libraries/LibC/sys/types.h b/Userland/Libraries/LibC/sys/types.h
index ad21502176..0910186712 100644
--- a/Userland/Libraries/LibC/sys/types.h
+++ b/Userland/Libraries/LibC/sys/types.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -10,87 +10,4 @@
#include <stddef.h>
#include <sys/cdefs.h>
-__BEGIN_DECLS
-
-/* 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;
-
-static inline dev_t makedev(unsigned int major, unsigned int minor) { return (minor & 0xffu) | (major << 8u) | ((minor & ~0xffu) << 12u); }
-static inline unsigned int major(dev_t dev) { return (dev & 0xfff00u) >> 8u; }
-static inline unsigned int minor(dev_t dev) { return (dev & 0xffu) | ((dev >> 12u) & 0xfff00u); }
-
-__END_DECLS
+#include <Kernel/API/POSIX/sys/types.h>