summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Weißschuh <linux@weissschuh.net>2026-05-14 15:05:12 +0300
committerThomas Weißschuh <linux@weissschuh.net>2026-05-14 18:41:09 +0300
commita8856027e29c432b2889aad45580d430ca002c87 (patch)
tree55082d7eebc851eab2515ac55c49f092b73317ee
parentced7994fc87d2d1c162d41ff32be876b09c8ad2b (diff)
downloadlinux-a8856027e29c432b2889aad45580d430ca002c87.tar.xz
tools/nolibc: split open mode handling into a macro
This logic is duplicated and some upcoming extensions would require even more duplicated logic. Move it into a macro to avoid the duplication and allow cleaner changes. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260514-nolibc-open-tmpfile-v2-2-b4c6c5efa266@weissschuh.net
-rw-r--r--tools/include/nolibc/fcntl.h40
1 files changed, 18 insertions, 22 deletions
diff --git a/tools/include/nolibc/fcntl.h b/tools/include/nolibc/fcntl.h
index 46f591cf82fd..d7ea02e1332d 100644
--- a/tools/include/nolibc/fcntl.h
+++ b/tools/include/nolibc/fcntl.h
@@ -16,6 +16,21 @@
#define __nolibc_open_flags(_flags) ((_flags) | O_LARGEFILE)
+#define __nolibc_open_mode(_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); \
+ } \
+ \
+ _mode; \
+})
+
/*
* int openat(int dirfd, const char *path, int flags[, mode_t mode]);
*/
@@ -29,17 +44,8 @@ int _sys_openat(int dirfd, const char *path, int flags, mode_t 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, __nolibc_open_flags(flags), mode));
+ return __sysret(_sys_openat(dirfd, path, __nolibc_open_flags(flags),
+ __nolibc_open_mode(flags)));
}
/*
@@ -55,17 +61,7 @@ int _sys_open(const char *path, int flags, mode_t 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, __nolibc_open_flags(flags), mode));
+ return __sysret(_sys_open(path, __nolibc_open_flags(flags), __nolibc_open_mode(flags)));
}
/*