Collin Funk wrote:
> FreeBSD 16.0, which is not yet released, adds renameat2 and the
> RENAME_NOREPLACE flags [1]. In coreutils, one can see the following test
> failure:
> 
>      depbase=`echo src/copy.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
>      gcc -std=gnu23  -I. -I./lib  -Ilib -I./lib -Isrc -I./src -D_THREAD_SAFE 
> -I/usr/local/include   -g -O2 -MT src/copy.o -MD -MP -MF $depbase.Tpo -c -o 
> src/copy.o src/copy.c &&\
>      mv -f $depbase.Tpo $depbase.Po
>      src/copy.c: In function 'copy_internal':
>      src/copy.c:2149:51: error: 'RENAME_EXCHANGE' undeclared (first use in 
> this function)
>       2149 |                                     x->exchange ? 
> RENAME_EXCHANGE : 0)
>            |                                                   ^~~~~~~~~~~~~~~
>      src/copy.c:2149:51: note: each undeclared identifier is reported only 
> once for each function it appears in
> 
> This is because src/copy.c includes sys/fcntl.h transitively through
> some other system header. This causes RENAME_EXCHANGE to be defined
> before Gnulib's lib/renameatu.h, which causes lib/renameatu.h to not
> define the flags that the system does not support.
> 
> I pushed the attached patch to fix this by defining the macros
> individually if they are not defined. I also pushed a patch to test that
> the macros are defined and unique.

Thanks for finding and fixing this!

Let me strengthen this test a bit. Also, the word "unique" is often ambiguous;
let me try to make the comment unambiguous.


2026-03-30  Bruno Haible  <[email protected]>

        renameatu tests: Enhance test of the RENAME_* macros.
        * tests/test-renameatu.c (main): Test that the RENAME_* macro values are
        disjoint.

diff --git a/tests/test-renameatu.c b/tests/test-renameatu.c
index 0d7f274e18..c63a5cd898 100644
--- a/tests/test-renameatu.c
+++ b/tests/test-renameatu.c
@@ -59,7 +59,7 @@ main (void)
   char *cwd;
   int result;
 
-  /* Test that the RENAME_* macros are defined and unique.  */
+  /* Test that the RENAME_* macros are defined and have distinct values.  */
   switch (0)
     {
     case RENAME_NOREPLACE:
@@ -68,6 +68,10 @@ main (void)
     default:
       ;
     }
+  /* Test that the RENAME_* macros have disjoint values (as bit sets).  */
+  ASSERT ((RENAME_NOREPLACE & RENAME_EXCHANGE) == 0);
+  ASSERT ((RENAME_NOREPLACE & RENAME_WHITEOUT) == 0);
+  ASSERT ((RENAME_EXCHANGE & RENAME_WHITEOUT) == 0);
 
   /* Clean up any trash from prior testsuite runs.  */
   ignore_value (system ("rm -rf " BASE "*"));




Reply via email to