diff --git a/Kernel/include/interface/fcntl.h b/Kernel/include/interface/fcntl.h
new file mode 100644
index 00000000..587c4fda
--- /dev/null
+++ b/Kernel/include/interface/fcntl.h
@@ -0,0 +1,109 @@
+/*
+ This file is part of Fennix Kernel.
+
+ Fennix Kernel is free software: you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation, either version 3 of
+ the License, or (at your option) any later version.
+
+ Fennix Kernel is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Fennix Kernel. If not, see .
+*/
+
+#ifndef __FENNIX_API_FCNTL_H__
+#define __FENNIX_API_FCNTL_H__
+
+#ifdef __kernel__
+#include
+#endif
+
+/* cmd */
+#define F_DUPFD 0x1
+#define F_DUPFD_CLOEXEC 0x101
+#define F_DUPFD_CLOFORK 0x201
+#define F_GETFD 0x2
+#define F_SETFD 0x3
+#define F_GETFL 0x4
+#define F_SETFL 0x5
+#define F_GETLK 0x6
+#define F_SETLK 0x7
+#define F_SETLKW 0x8
+#define F_OFD_GETLK 0x9
+#define F_OFD_SETLK 0xA
+#define F_OFD_SETLKW 0xB
+#define F_GETOWN 0xC
+#define F_GETOWN_EX 0xD
+#define F_SETOWN 0xE
+#define F_SETOWN_EX 0xF
+
+#define FD_CLOEXEC 0x1
+#define FD_CLOFORK 0x2
+
+/* l_type */
+#define F_RDLCK 0x1
+#define F_UNLCK 0x2
+#define F_WRLCK 0x3
+
+/* type */
+#define F_OWNER_PID 0
+#define F_OWNER_PGRP 1
+
+/* oflag */
+#define O_CLOEXEC 02000000
+#define O_CLOFORK 04000000
+#define O_CREAT 0x8
+#define O_DIRECTORY 0200000
+#define O_EXCL 0x20
+#define O_NOCTTY 0x40
+#define O_NOFOLLOW 0400000
+#define O_TRUNC 0x400
+#define O_TTY_INIT 0x800
+
+#define O_APPEND 0x4
+#define O_DSYNC 0x10
+#define O_NONBLOCK 0x80
+#define O_RSYNC 0x100
+#define O_SYNC 0x200
+
+#define O_ACCMODE 0x3
+
+#define O_EXEC 0x4
+#define O_RDONLY 0x1
+#define O_RDWR 0x3
+#define O_SEARCH 0x10
+#define O_WRONLY 0x2
+
+#define AT_FDCWD
+#define AT_EACCESS
+#define AT_SYMLINK_NOFOLLOW
+#define AT_SYMLINK_FOLLOW
+#define AT_REMOVEDIR
+
+#define POSIX_FADV_DONTNEED
+#define POSIX_FADV_NOREUSE
+#define POSIX_FADV_NORMAL
+#define POSIX_FADV_RANDOM
+#define POSIX_FADV_SEQUENTIAL
+#define POSIX_FADV_WILLNEED
+
+typedef struct f_owner_ex
+{
+ int type; /* Discriminator for pid. */
+ pid_t pid; /* Process ID or process group ID. */
+} f_owner_ex;
+
+typedef struct flock
+{
+ short l_type; /* Type of lock; F_RDLCK, F_WRLCK, F_UNLCK. */
+ short l_whence; /* Flag for starting offset. */
+ off_t l_start; /* Relative offset in bytes. */
+ off_t l_len; /* Size; if 0 then until EOF. */
+ pid_t l_pid; /* For a process-owned file lock, ignored on input or the process ID of the owning process on output; for an OFD-owned file lock, zero on input or (pid_t)-1 on output. */
+} flock;
+
+#endif // !__FENNIX_API_FCNTL_H__
diff --git a/Kernel/include/interface/syscalls.h b/Kernel/include/interface/syscalls.h
index df4dcd43..3c0fbcc4 100644
--- a/Kernel/include/interface/syscalls.h
+++ b/Kernel/include/interface/syscalls.h
@@ -18,6 +18,16 @@
#ifndef __FENNIX_API_SYSTEM_CALLS_LIST_H__
#define __FENNIX_API_SYSTEM_CALLS_LIST_H__
+#if __has_include()
+#include
+#else
+#include
+#endif
+
+#ifndef __fennix__
+#error "__fennix__ not defined"
+#endif
+
#pragma region Syscall Wrappers
#define scarg __UINTPTR_TYPE__
@@ -393,18 +403,18 @@ typedef enum
typedef enum
{
- __SYS_O_RDONLY = 0x1,
- __SYS_O_WRONLY = 0x2,
- __SYS_O_RDWR = 0x3,
- __SYS_O_APPEND = 0x4,
- __SYS_O_CREAT = 0x8,
- __SYS_O_DSYNC = 0x10,
- __SYS_O_EXCL = 0x20,
- __SYS_O_NOCTTY = 0x40,
- __SYS_O_NONBLOCK = 0x80,
- __SYS_O_RSYNC = 0x100,
- __SYS_O_SYNC = 0x200,
- __SYS_O_TRUNC = 0x400
+ __SYS_O_RDONLY = O_RDONLY,
+ __SYS_O_WRONLY = O_WRONLY,
+ __SYS_O_RDWR = O_RDWR,
+ __SYS_O_APPEND = O_APPEND,
+ __SYS_O_CREAT = O_CREAT,
+ __SYS_O_DSYNC = O_DSYNC,
+ __SYS_O_EXCL = O_EXCL,
+ __SYS_O_NOCTTY = O_NOCTTY,
+ __SYS_O_NONBLOCK = O_NONBLOCK,
+ __SYS_O_RSYNC = O_RSYNC,
+ __SYS_O_SYNC = O_SYNC,
+ __SYS_O_TRUNC = O_TRUNC
} syscall_open_flags_t;
typedef enum
diff --git a/Userspace/Makefile b/Userspace/Makefile
index 68d0b17c..9fd1e563 100644
--- a/Userspace/Makefile
+++ b/Userspace/Makefile
@@ -49,9 +49,14 @@ build_coreutils:
make -j$(shell nproc) && \
make install
+define copy_generic_header
+ cp -f $(WORKSPACE_DIR)/../Kernel/include/interface/$(1) $(WORKSPACE_DIR)/libc/abis/fennix/generic/bits/$(1)
+endef
+
build_libc:
- cp -f $(WORKSPACE_DIR)/../Kernel/include/interface/errno.h $(WORKSPACE_DIR)/libc/abis/fennix/generic/bits/errno.h
- cp -f $(WORKSPACE_DIR)/../Kernel/include/interface/syscalls.h $(WORKSPACE_DIR)/libc/abis/fennix/generic/bits/syscalls.h
+ $(call copy_generic_header,errno.h)
+ $(call copy_generic_header,syscalls.h)
+ $(call copy_generic_header,fcntl.h)
mkdir -p cache/libc
cd cache/libc && \
cmake $(WORKSPACE_DIR)/libc \
diff --git a/Userspace/libc/abis/fennix/generic/bits/fcntl.h b/Userspace/libc/abis/fennix/generic/bits/fcntl.h
new file mode 100644
index 00000000..587c4fda
--- /dev/null
+++ b/Userspace/libc/abis/fennix/generic/bits/fcntl.h
@@ -0,0 +1,109 @@
+/*
+ This file is part of Fennix Kernel.
+
+ Fennix Kernel is free software: you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation, either version 3 of
+ the License, or (at your option) any later version.
+
+ Fennix Kernel is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Fennix Kernel. If not, see .
+*/
+
+#ifndef __FENNIX_API_FCNTL_H__
+#define __FENNIX_API_FCNTL_H__
+
+#ifdef __kernel__
+#include
+#endif
+
+/* cmd */
+#define F_DUPFD 0x1
+#define F_DUPFD_CLOEXEC 0x101
+#define F_DUPFD_CLOFORK 0x201
+#define F_GETFD 0x2
+#define F_SETFD 0x3
+#define F_GETFL 0x4
+#define F_SETFL 0x5
+#define F_GETLK 0x6
+#define F_SETLK 0x7
+#define F_SETLKW 0x8
+#define F_OFD_GETLK 0x9
+#define F_OFD_SETLK 0xA
+#define F_OFD_SETLKW 0xB
+#define F_GETOWN 0xC
+#define F_GETOWN_EX 0xD
+#define F_SETOWN 0xE
+#define F_SETOWN_EX 0xF
+
+#define FD_CLOEXEC 0x1
+#define FD_CLOFORK 0x2
+
+/* l_type */
+#define F_RDLCK 0x1
+#define F_UNLCK 0x2
+#define F_WRLCK 0x3
+
+/* type */
+#define F_OWNER_PID 0
+#define F_OWNER_PGRP 1
+
+/* oflag */
+#define O_CLOEXEC 02000000
+#define O_CLOFORK 04000000
+#define O_CREAT 0x8
+#define O_DIRECTORY 0200000
+#define O_EXCL 0x20
+#define O_NOCTTY 0x40
+#define O_NOFOLLOW 0400000
+#define O_TRUNC 0x400
+#define O_TTY_INIT 0x800
+
+#define O_APPEND 0x4
+#define O_DSYNC 0x10
+#define O_NONBLOCK 0x80
+#define O_RSYNC 0x100
+#define O_SYNC 0x200
+
+#define O_ACCMODE 0x3
+
+#define O_EXEC 0x4
+#define O_RDONLY 0x1
+#define O_RDWR 0x3
+#define O_SEARCH 0x10
+#define O_WRONLY 0x2
+
+#define AT_FDCWD
+#define AT_EACCESS
+#define AT_SYMLINK_NOFOLLOW
+#define AT_SYMLINK_FOLLOW
+#define AT_REMOVEDIR
+
+#define POSIX_FADV_DONTNEED
+#define POSIX_FADV_NOREUSE
+#define POSIX_FADV_NORMAL
+#define POSIX_FADV_RANDOM
+#define POSIX_FADV_SEQUENTIAL
+#define POSIX_FADV_WILLNEED
+
+typedef struct f_owner_ex
+{
+ int type; /* Discriminator for pid. */
+ pid_t pid; /* Process ID or process group ID. */
+} f_owner_ex;
+
+typedef struct flock
+{
+ short l_type; /* Type of lock; F_RDLCK, F_WRLCK, F_UNLCK. */
+ short l_whence; /* Flag for starting offset. */
+ off_t l_start; /* Relative offset in bytes. */
+ off_t l_len; /* Size; if 0 then until EOF. */
+ pid_t l_pid; /* For a process-owned file lock, ignored on input or the process ID of the owning process on output; for an OFD-owned file lock, zero on input or (pid_t)-1 on output. */
+} flock;
+
+#endif // !__FENNIX_API_FCNTL_H__
diff --git a/Userspace/libc/abis/fennix/generic/bits/syscalls.h b/Userspace/libc/abis/fennix/generic/bits/syscalls.h
index df4dcd43..3c0fbcc4 100644
--- a/Userspace/libc/abis/fennix/generic/bits/syscalls.h
+++ b/Userspace/libc/abis/fennix/generic/bits/syscalls.h
@@ -18,6 +18,16 @@
#ifndef __FENNIX_API_SYSTEM_CALLS_LIST_H__
#define __FENNIX_API_SYSTEM_CALLS_LIST_H__
+#if __has_include()
+#include
+#else
+#include
+#endif
+
+#ifndef __fennix__
+#error "__fennix__ not defined"
+#endif
+
#pragma region Syscall Wrappers
#define scarg __UINTPTR_TYPE__
@@ -393,18 +403,18 @@ typedef enum
typedef enum
{
- __SYS_O_RDONLY = 0x1,
- __SYS_O_WRONLY = 0x2,
- __SYS_O_RDWR = 0x3,
- __SYS_O_APPEND = 0x4,
- __SYS_O_CREAT = 0x8,
- __SYS_O_DSYNC = 0x10,
- __SYS_O_EXCL = 0x20,
- __SYS_O_NOCTTY = 0x40,
- __SYS_O_NONBLOCK = 0x80,
- __SYS_O_RSYNC = 0x100,
- __SYS_O_SYNC = 0x200,
- __SYS_O_TRUNC = 0x400
+ __SYS_O_RDONLY = O_RDONLY,
+ __SYS_O_WRONLY = O_WRONLY,
+ __SYS_O_RDWR = O_RDWR,
+ __SYS_O_APPEND = O_APPEND,
+ __SYS_O_CREAT = O_CREAT,
+ __SYS_O_DSYNC = O_DSYNC,
+ __SYS_O_EXCL = O_EXCL,
+ __SYS_O_NOCTTY = O_NOCTTY,
+ __SYS_O_NONBLOCK = O_NONBLOCK,
+ __SYS_O_RSYNC = O_RSYNC,
+ __SYS_O_SYNC = O_SYNC,
+ __SYS_O_TRUNC = O_TRUNC
} syscall_open_flags_t;
typedef enum
diff --git a/Userspace/libc/include/fcntl.h b/Userspace/libc/include/fcntl.h
index e76907d1..f77ad800 100644
--- a/Userspace/libc/include/fcntl.h
+++ b/Userspace/libc/include/fcntl.h
@@ -24,77 +24,7 @@ extern "C"
#endif // __cplusplus
#include
-
- typedef struct f_owner_ex
- {
- int type; /* Discriminator for pid. */
- pid_t pid; /* Process ID or process group ID. */
- } f_owner_ex;
-
- typedef struct flock
- {
- short l_type; /* Type of lock; F_RDLCK, F_WRLCK, F_UNLCK. */
- short l_whence; /* Flag for starting offset. */
- off_t l_start; /* Relative offset in bytes. */
- off_t l_len; /* Size; if 0 then until EOF. */
- pid_t l_pid; /* For a process-owned file lock, ignored on input or the process ID of the owning process on output; for an OFD-owned file lock, zero on input or (pid_t)-1 on output. */
- } flock;
-
-#define F_DUPFD
-#define F_DUPFD_CLOEXEC
-#define F_DUPFD_CLOFORK
-#define F_GETFD
-#define F_SETFD
-#define F_GETFL
-#define F_SETFL
-#define F_GETLK
-#define F_SETLK
-#define F_SETLKW
-#define F_OFD_GETLK
-#define F_OFD_SETLK
-#define F_OFD_SETLKW
-#define F_GETOWN
-#define F_GETOWN_EX
-#define F_SETOWN
-#define F_SETOWN_EX
-#define FD_CLOEXEC
-#define FD_CLOFORK
-#define F_RDLCK
-#define F_UNLCK
-#define F_WRLCK
-#define F_OWNER_PID
-#define F_OWNER_PGRP
-#define O_CLOEXEC 02000000
-#define O_CLOFORK
-#define O_CREAT 0100
-#define O_DIRECTORY
-#define O_EXCL 0200
-#define O_NOCTTY
-#define O_NOFOLLOW 0400000
-#define O_TRUNC 01000
-#define O_TTY_INIT
-#define O_APPEND 02000
-#define O_DSYNC
-#define O_NONBLOCK
-#define O_RSYNC
-#define O_SYNC
-#define O_ACCMODE
-#define O_EXEC
-#define O_RDONLY 00
-#define O_RDWR 02
-#define O_SEARCH
-#define O_WRONLY 01
-#define AT_FDCWD
-#define AT_EACCESS
-#define AT_SYMLINK_NOFOLLOW
-#define AT_SYMLINK_FOLLOW
-#define AT_REMOVEDIR
-#define POSIX_FADV_DONTNEED
-#define POSIX_FADV_NOREUSE
-#define POSIX_FADV_NORMAL
-#define POSIX_FADV_RANDOM
-#define POSIX_FADV_SEQUENTIAL
-#define POSIX_FADV_WILLNEED
+#include
int creat(const char *path, mode_t mode);
int fcntl(int fildes, int cmd, ...);