Skip to contentSkip to conversation

samples/vfs: Undefine conflicting AT_RENAME_* macros in test-statx

PATCH New Madhur Kumar 1 participant 1 message Oct 4, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 samples/vfs: Undefine conflicting AT_RENAME_* macros in test-statx

The test-statx program in samples/vfs/ includes both <stdio.h> and usr/include/linux/fcntl.h, leading to redefinition errors for AT_RENAME_NOREPLACE, AT_RENAME_EXCHANGE, and AT_RENAME_WHITEOUT. These macros, defined in both glibc headers (via <stdio.h>, likely including <fcntl.h>) and the kernel's usr/include/linux/fcntl.h, are not directly used in test-statx.c but cause a build failure with -Werror due to redefinition warnings like:

In file included from samples/vfs/test-statx.c:23:
usr/include/linux/fcntl.h:160:9: error: ‘AT_RENAME_NOREPLACE’ redefined [-Werror]
160 | #define AT_RENAME_NOREPLACE 0x0001
| ^~~~~~~~~~~~~~~~~~~
In file included from samples/vfs/test-statx.c:13:
/usr/include/stdio.h:171:10: note: this is the location of the previous definition 171 | # define AT_RENAME_NOREPLACE RENAME_NOREPLACE
| ^~~~~~~~~~~~~~~~~~~
usr/include/linux/fcntl.h:161:9: error: ‘AT_RENAME_EXCHANGE’ redefined [-Werror]
161 | #define AT_RENAME_EXCHANGE 0x0002
| ^~~~~~~~~~~~~~~~~~
/usr/include/stdio.h:173:10: note: this is the location of the previous definition 173 | # define AT_RENAME_EXCHANGE RENAME_EXCHANGE
| ^~~~~~~~~~~~~~~~~~
usr/include/linux/fcntl.h:162:9: error: ‘AT_RENAME_WHITEOUT’ redefined [-Werror]
162 | #define AT_RENAME_WHITEOUT 0x0004
| ^~~~~~~~~~~~~~~~~~
/usr/include/stdio.h:175:10: note: this is the location of the previous definition 175 | # define AT_RENAME_WHITEOUT RENAME_WHITEOUT
| ^~~~~~~~~~~~~~~~~~

Since test-statx relies on other kernel-specific definitions from usr/include/linux/fcntl.h, this patch adds #undef directives for the conflicting macros before including the kernel header, ensuring the kernel's definitions are used without warnings.

---
 samples/vfs/test-statx.c | 3 +++
 1 file changed, 3 insertions(+)
samples/vfs/test-statx.c +3 -0
index 49c7a46cee07..17332100a2b5 100644
@@ -20,6 +20,9 @@
 #include <sys/syscall.h>
 #include <sys/types.h>
 #include <linux/stat.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
Signature · 1 line
2.51.0