Skip to content

Commit

Permalink
tools/nolibc: check for S_I* macros before defining them
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
  • Loading branch information
Willy Tarreau authored and Paul E. McKenney committed Mar 20, 2023
1 parent 3e2d337 commit 1c3a4c1
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tools/include/nolibc/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@

#include "std.h"
#include <linux/time.h>
#include <linux/stat.h>


/* Only the generic macros and types may be defined here. The arch-specific
* ones such as the O_RDONLY and related macros used by fcntl() and open(), or
* 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
Expand All @@ -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
Expand Down

0 comments on commit 1c3a4c1

Please sign in to comment.