From: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
To: "Willy Tarreau" <w@1wt.eu>, "Thomas Weißschuh" <linux@weissschuh.net>
Cc: linux-kernel@vger.kernel.org,
"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
Subject: [PATCH 03/10] tools/nolibc: move open() and friends to fcntl.h
Date: Wed, 16 Apr 2025 14:06:18 +0200 [thread overview]
Message-ID: <20250416-nolibc-split-sys-v1-3-a069a3f1d145@linutronix.de> (raw)
In-Reply-To: <20250416-nolibc-split-sys-v1-0-a069a3f1d145@linutronix.de>
This is the location regular userspace expects these definitions.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
tools/include/nolibc/Makefile | 1 +
tools/include/nolibc/dirent.h | 1 +
tools/include/nolibc/fcntl.h | 69 +++++++++++++++++++++++++++++++++++++++++++
tools/include/nolibc/nolibc.h | 1 +
tools/include/nolibc/sys.h | 52 --------------------------------
5 files changed, 72 insertions(+), 52 deletions(-)
diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile
index fd76d267d79a8533b7e78375c30324c962b01973..2132e4f4d2165729ec6d10860d0586f1b71ee0fb 100644
--- a/tools/include/nolibc/Makefile
+++ b/tools/include/nolibc/Makefile
@@ -32,6 +32,7 @@ all_files := \
dirent.h \
elf.h \
errno.h \
+ fcntl.h \
limits.h \
nolibc.h \
signal.h \
diff --git a/tools/include/nolibc/dirent.h b/tools/include/nolibc/dirent.h
index c5c30d0dd6806b1bec2fa8120a3df29aaa201393..d3fb9500c60a31bc1b75601d78871df82ca75f7d 100644
--- a/tools/include/nolibc/dirent.h
+++ b/tools/include/nolibc/dirent.h
@@ -9,6 +9,7 @@
#include "stdint.h"
#include "types.h"
+#include "fcntl.h"
#include <linux/limits.h>
diff --git a/tools/include/nolibc/fcntl.h b/tools/include/nolibc/fcntl.h
new file mode 100644
index 0000000000000000000000000000000000000000..5feb08ad54a7d943b8100eac21f4058310efea91
--- /dev/null
+++ b/tools/include/nolibc/fcntl.h
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
+/*
+ * fcntl definition for NOLIBC
+ * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
+ */
+
+#ifndef _NOLIBC_FCNTL_H
+#define _NOLIBC_FCNTL_H
+
+#include "arch.h"
+#include "types.h"
+#include "sys.h"
+
+/*
+ * int openat(int dirfd, const char *path, int flags[, mode_t mode]);
+ */
+
+static __attribute__((unused))
+int sys_openat(int dirfd, const char *path, int flags, mode_t mode)
+{
+ return my_syscall4(__NR_openat, dirfd, path, flags, mode);
+}
+
+static __attribute__((unused))
+int openat(int dirfd, const char *path, int flags, ...)
+{
+ mode_t mode = 0;
+
+ if (flags & O_CREAT) {
+ va_list args;
+
+ va_start(args, flags);
+ mode = va_arg(args, mode_t);
+ va_end(args);
+ }
+
+ return __sysret(sys_openat(dirfd, path, flags, mode));
+}
+
+/*
+ * int open(const char *path, int flags[, mode_t mode]);
+ */
+
+static __attribute__((unused))
+int sys_open(const char *path, int flags, mode_t mode)
+{
+ return my_syscall4(__NR_openat, AT_FDCWD, path, flags, mode);
+}
+
+static __attribute__((unused))
+int open(const char *path, int flags, ...)
+{
+ mode_t mode = 0;
+
+ if (flags & O_CREAT) {
+ va_list args;
+
+ va_start(args, flags);
+ mode = va_arg(args, mode_t);
+ va_end(args);
+ }
+
+ return __sysret(sys_open(path, flags, mode));
+}
+
+/* make sure to include all global symbols */
+#include "nolibc.h"
+
+#endif /* _NOLIBC_FCNTL_H */
diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index 127f0d9068c6508bd45acfe0ebf2ce15acc422b0..bb4183a8fdc41023d9b8b37fe35ec37ca408b4c6 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -106,6 +106,7 @@
#include "time.h"
#include "stackprotector.h"
#include "dirent.h"
+#include "fcntl.h"
/* Used by programs to avoid std includes */
#define NOLIBC
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 08c1c074bec89a27e53e5d461a3ebbf71ec323d1..5fa351e6a3512a3d0c609867244ac91e8563ab2a 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -764,58 +764,6 @@ int mount(const char *src, const char *tgt,
return __sysret(sys_mount(src, tgt, fst, flags, data));
}
-/*
- * int openat(int dirfd, const char *path, int flags[, mode_t mode]);
- */
-
-static __attribute__((unused))
-int sys_openat(int dirfd, const char *path, int flags, mode_t mode)
-{
- return my_syscall4(__NR_openat, dirfd, path, flags, mode);
-}
-
-static __attribute__((unused))
-int openat(int dirfd, const char *path, int flags, ...)
-{
- mode_t mode = 0;
-
- if (flags & O_CREAT) {
- va_list args;
-
- va_start(args, flags);
- mode = va_arg(args, mode_t);
- va_end(args);
- }
-
- return __sysret(sys_openat(dirfd, path, flags, mode));
-}
-
-/*
- * int open(const char *path, int flags[, mode_t mode]);
- */
-
-static __attribute__((unused))
-int sys_open(const char *path, int flags, mode_t mode)
-{
- return my_syscall4(__NR_openat, AT_FDCWD, path, flags, mode);
-}
-
-static __attribute__((unused))
-int open(const char *path, int flags, ...)
-{
- mode_t mode = 0;
-
- if (flags & O_CREAT) {
- va_list args;
-
- va_start(args, flags);
- mode = va_arg(args, mode_t);
- va_end(args);
- }
-
- return __sysret(sys_open(path, flags, mode));
-}
-
/*
* int pipe2(int pipefd[2], int flags);
--
2.49.0
next prev parent reply other threads:[~2025-04-16 12:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-16 12:06 [PATCH 00/10] tools/nolibc: split out functionality into new headers Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 01/10] tools/nolibc: prepare for headers in subdirectories Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 02/10] tools/nolibc: add elf.h Thomas Weißschuh
2025-04-16 12:06 ` Thomas Weißschuh [this message]
2025-04-16 12:06 ` [PATCH 04/10] tools/nolibc: move getauxval() to sys/auxv.h Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 05/10] tools/nolibc: move mmap() and friends to sys/mman.h Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 06/10] tools/nolibc: move stat() and friends to sys/stat.h Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 07/10] tools/nolibc: move syscall() to sys/syscall.h Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 08/10] tools/nolibc: move gettimeofday() to sys/time.h Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 09/10] tools/nolibc: add sys/types.h shim Thomas Weißschuh
2025-04-16 12:06 ` [PATCH 10/10] tools/nolibc: move wait() and friends to sys/wait.h Thomas Weißschuh
2025-04-19 9:02 ` [PATCH 00/10] tools/nolibc: split out functionality into new headers Willy Tarreau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250416-nolibc-split-sys-v1-3-a069a3f1d145@linutronix.de \
--to=thomas.weissschuh@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=w@1wt.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®