[PATCH v2 2/2] samples: vfs: avoid libc AT_RENAME_* redefinitions

From: Masaharu Noguchi
Date: Mon Nov 10 2025 - 09:44:37 EST


Users building the sample after including libc headers such as stdio.h
may inherit libc's AT_RENAME_* macros before <linux/fcntl.h> is pulled
in. When that happens, the sample ends up with conflicting definitions
or the libc values leak into the rest of the build.

Drop any existing AT_RENAME_* macros before including the uapi header so
that the sample always uses the kernel values and does not trip -Werror
redefinition checks.

Signed-off-by: Masaharu Noguchi <nogunix@xxxxxxxxx>
---
samples/vfs/test-statx.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/samples/vfs/test-statx.c b/samples/vfs/test-statx.c
index 49c7a46cee07..0123ab4efe0a 100644
--- a/samples/vfs/test-statx.c
+++ b/samples/vfs/test-statx.c
@@ -20,7 +20,16 @@
#include <sys/syscall.h>
#include <sys/types.h>
#include <linux/stat.h>
+
+/* Undefine AT_RENAME_* macros that may have been set by libc headers
+ * (e.g. stdio.h) to avoid redefinition conflicts with uapi fcntl.h.
+ */
+#undef AT_RENAME_NOREPLACE
+#undef AT_RENAME_EXCHANGE
+#undef AT_RENAME_WHITEOUT
+
#include <linux/fcntl.h>
+
#define statx foo
#define statx_timestamp foo_timestamp
struct statx;
--
2.51.1