]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
openat2-tests: port to FreeBSD, NetBSD
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 29 Oct 2025 00:03:28 +0000 (17:03 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 29 Oct 2025 04:17:08 +0000 (21:17 -0700)
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2025-10/msg00117.html
* tests/test-openat2.c (is_nofollow_error): New function.
(do_test_resolve): Use it.

ChangeLog
tests/test-openat2.c

index 415568a156a43abf2ddfff2b3d5a95a70aa08868..3ccd074a4cb27233528948123eadc939025e73bc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2025-10-28  Paul Eggert  <eggert@cs.ucla.edu>
+
+       openat2-tests: port to FreeBSD, NetBSD
+       Problem reported by Bruno Haible in:
+       https://lists.gnu.org/r/bug-gnulib/2025-10/msg00117.html
+       * tests/test-openat2.c (is_nofollow_error): New function.
+       (do_test_resolve): Use it.
+
 2025-10-28  Bruno Haible  <bruno@clisp.org>
 
        posix_spawn_file_actions_addclose: Fix test failure on NetBSD 10.0.
index 0ac7aca6f3c0485de4ba9d3c9786c8ec35d6a2a2..fc93a7a9a910fded2767f02d1311d436cc38e92f 100644 (file)
@@ -317,6 +317,20 @@ do_test_flags (void)
     }
 }
 
+static bool
+is_nofollow_error (int err)
+{
+#ifdef EFTYPE /* NetBSD openat+O_NOFOLLOW on symlink */
+  if (err == EFTYPE)
+    return true;
+#endif
+#ifdef EMLINK /* FreeBSD openat+O_NOFOLLOW on symlink */
+  if (err == EMLINK)
+    return true;
+#endif
+  return err == ELOOP;
+}
+
 static void
 do_test_resolve (void)
 {
@@ -331,7 +345,7 @@ do_test_resolve (void)
                    .resolve = RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS,
                  }),
                sizeof (struct open_how));
-  ASSERT (errno == ELOOP || errno == EXDEV);
+  ASSERT ((errno == EXDEV) | is_nofollow_error (errno));
   ASSERT (fd == -1);
 
   /* Same as before, ESCAPING_LINK_2 links to ESCAPING_LINK.  */
@@ -342,7 +356,7 @@ do_test_resolve (void)
                    .resolve = RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS,
                  }),
                sizeof (struct open_how));
-  ASSERT (errno == ELOOP || errno == EXDEV);
+  ASSERT ((errno == EXDEV) | is_nofollow_error (errno));
   ASSERT (fd == -1);
 
   /* ESCAPING_LINK links to the temporary directory itself (dfd).  */
@@ -353,7 +367,7 @@ do_test_resolve (void)
                    .resolve = RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS,
                  }),
                sizeof (struct open_how));
-  ASSERT (errno == ELOOP || errno == EXDEV);
+  ASSERT ((errno == EXDEV) | is_nofollow_error (errno));
   ASSERT (fd == -1);
 
   /* Although it points to a valid file in same path, the link refers to
@@ -365,7 +379,7 @@ do_test_resolve (void)
                    .resolve = RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS,
                  }),
                sizeof (struct open_how));
-  ASSERT (errno == ELOOP || errno == EXDEV);
+  ASSERT ((errno == EXDEV) | is_nofollow_error (errno));
   ASSERT (fd == -1);
 
   fd = openat2 (dfd,
@@ -375,7 +389,7 @@ do_test_resolve (void)
                    .resolve = RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS,
                  }),
                sizeof (struct open_how));
-  ASSERT (errno == ELOOP);
+  ASSERT (is_nofollow_error (errno));
   ASSERT (fd == -1);
 
   fd = openat2 (dfd,
@@ -385,7 +399,7 @@ do_test_resolve (void)
                    .resolve = RESOLVE_IN_ROOT | RESOLVE_NO_SYMLINKS,
                  }),
               sizeof (struct open_how));
-  ASSERT (errno == ELOOP | errno == ENOENT);
+  ASSERT ((errno == ENOENT) | is_nofollow_error (errno));
   ASSERT (fd == -1);
 
   {