From: Willy Tarreau <w@1wt.eu>
To: paulmck@kernel.org
Cc: chenhuacai@loongson.cn, chenfeiyang@loongson.cn,
linux-kernel@vger.kernel.org, Willy Tarreau <w@1wt.eu>
Subject: [PATCH 3/5] tools/nolibc: check for S_I* macros before defining them
Date: Sat, 4 Mar 2023 15:28:42 +0100 [thread overview]
Message-ID: <20230304142844.6522-4-w@1wt.eu> (raw)
In-Reply-To: <20230304142844.6522-1-w@1wt.eu>
Defining S_I* flags in types.h can cause some build failures if
linux/stat.h is included prior to it. But if not defined, some toolchains
that include some glibc parts will in turn fail because linux/stat.h
already takes care of avoiding these definitions when glibc is present.
Let's preserve the macros here but first include linux/stat.h and check
for their definition before doing so. We also define the previously
missing permission macros so that we don't get a different behavior
depending on the first include found.
Cc: Feiyang Chen <chenfeiyang@loongson.cn>
Signed-off-by: Willy Tarreau <w@1wt.eu>
---
tools/include/nolibc/types.h | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/tools/include/nolibc/types.h b/tools/include/nolibc/types.h
index fbbc0e68c001..47a0997d2d74 100644
--- a/tools/include/nolibc/types.h
+++ b/tools/include/nolibc/types.h
@@ -9,6 +9,7 @@
#include "std.h"
#include <linux/time.h>
+#include <linux/stat.h>
/* Only the generic macros and types may be defined here. The arch-specific
@@ -16,7 +17,11 @@
* the layout of sys_stat_struct must not be defined here.
*/
-/* stat flags (WARNING, octal here) */
+/* stat flags (WARNING, octal here). We need to check for an existing
+ * definition because linux/stat.h may omit to define those if it finds
+ * that any glibc header was already included.
+ */
+#if !defined(S_IFMT)
#define S_IFDIR 0040000
#define S_IFCHR 0020000
#define S_IFBLK 0060000
@@ -34,6 +39,22 @@
#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
+#define S_IRWXU 00700
+#define S_IRUSR 00400
+#define S_IWUSR 00200
+#define S_IXUSR 00100
+
+#define S_IRWXG 00070
+#define S_IRGRP 00040
+#define S_IWGRP 00020
+#define S_IXGRP 00010
+
+#define S_IRWXO 00007
+#define S_IROTH 00004
+#define S_IWOTH 00002
+#define S_IXOTH 00001
+#endif
+
/* dirent types */
#define DT_UNKNOWN 0x0
#define DT_FIFO 0x1
--
2.17.5
next prev parent reply other threads:[~2023-03-04 14:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-04 14:28 [PATCH 0/5] tools/nolibc: cleanups, statx(), getuid() Willy Tarreau
2023-03-04 14:28 ` [PATCH 1/5] tools/nolibc: add getuid() and geteuid() Willy Tarreau
2023-03-04 14:28 ` [PATCH 2/5] selftests/nolibc: skip the chroot_root and link_dir tests when not privileged Willy Tarreau
2023-03-04 14:28 ` Willy Tarreau [this message]
2023-03-04 14:28 ` [PATCH 4/5] tools/nolibc: Include linux/fcntl.h and remove duplicate code Willy Tarreau
2023-03-04 14:28 ` [PATCH 5/5] tools/nolibc: Add statx() and make stat() rely on statx() if necessary 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=20230304142844.6522-4-w@1wt.eu \
--to=w@1wt.eu \
--cc=chenfeiyang@loongson.cn \
--cc=chenhuacai@loongson.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
/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®