[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220419004225.3952530-24-paulmck@kernel.org>
Date: Mon, 18 Apr 2022 17:41:48 -0700
From: "Paul E. McKenney" <paulmck@...nel.org>
To: linux-kernel@...r.kernel.org
Cc: gwml@...r.gnuweeb.org, kernel-team@...com, w@....eu,
Willy Tarreau <w@....eu>,
"Paul E . McKenney" <paulmck@...nel.org>
Subject: [PATCH nolibc 24/61] tools/nolibc/sys: make open() take a vararg on the 3rd argument
From: Willy Tarreau <w@....eu>
Let's pass a vararg to open() so that it remains compatible with existing
code. The arg is only dereferenced when flags contain O_CREAT. The function
is generally not inlined anymore, causing an extra call (total 16 extra
bytes) but it's still optimized for constant propagation, limiting the
excess to no more than 16 bytes in practice when open() is called without
O_CREAT, and ~40 with O_CREAT, which remains reasonable.
Signed-off-by: Willy Tarreau <w@....eu>
Signed-off-by: Paul E. McKenney <paulmck@...nel.org>
---
tools/include/nolibc/sys.h | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 98689f668ed3..539af457a91b 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -7,6 +7,7 @@
#ifndef _NOLIBC_SYS_H
#define _NOLIBC_SYS_H
+#include <stdarg.h>
#include "std.h"
/* system includes */
@@ -719,7 +720,7 @@ int mount(const char *src, const char *tgt,
/*
- * int open(const char *path, int flags, mode_t mode);
+ * int open(const char *path, int flags[, mode_t mode]);
*/
static __attribute__((unused))
@@ -735,9 +736,20 @@ int sys_open(const char *path, int flags, mode_t mode)
}
static __attribute__((unused))
-int open(const char *path, int flags, mode_t mode)
+int open(const char *path, int flags, ...)
{
- int ret = sys_open(path, flags, mode);
+ mode_t mode = 0;
+ int ret;
+
+ if (flags & O_CREAT) {
+ va_list args;
+
+ va_start(args, flags);
+ mode = va_arg(args, mode_t);
+ va_end(args);
+ }
+
+ ret = sys_open(path, flags, mode);
if (ret < 0) {
SET_ERRNO(-ret);
--
2.31.1.189.g2e36527f23
Powered by blists - more mailing lists