]> Savannah Git Hosting - gnulib.git/commitdiff
dup3: Fix behavior for equal file descriptors on NetBSD.
authorCollin Funk <collin.funk1@gmail.com>
Sat, 18 May 2024 23:34:55 +0000 (16:34 -0700)
committerBruno Haible <bruno@clisp.org>
Wed, 22 May 2024 08:44:17 +0000 (10:44 +0200)
* lib/dup3.c (dup3) [__NetBSD__]: Check for equal file descriptors upon
a successful call to dup3. If they are equal fail with errno == EINVAL.

ChangeLog
lib/dup3.c

index 8f78d27e8a22198a46bb182e842587b2480cad78..47a23af94e84aa5a6b495bd376db27a8a6222d98 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-05-18  Collin Funk  <collin.funk1@gmail.com>
+
+       dup3: Fix behavior for equal file descriptors on NetBSD.
+       * lib/dup3.c (dup3) [__NetBSD__]: Check for equal file descriptors upon
+       a successful call to dup3. If they are equal fail with errno == EINVAL.
+
 2024-05-17  Bruno Haible  <bruno@clisp.org>
 
        unistd: Fix compilation error with MSVC in C++ mode.
index a810d3be19ba845de84286c2b70d88f82045427c..d1ebb0d88ca758f9804f8f752e5228c93cfe068f 100644 (file)
@@ -45,6 +45,15 @@ dup3 (int oldfd, int newfd, int flags)
         if (!(result < 0 && errno == ENOSYS))
           {
             have_dup3_really = 1;
+            /* On NetBSD dup3 is a no-op when oldfd == newfd, but we are
+               expected to fail with error EINVAL.  */
+# ifdef __NetBSD__
+            if (newfd == oldfd)
+              {
+                errno = EINVAL;
+                return -1;
+              }
+# endif
 # if REPLACE_FCHDIR
             if (0 <= result)
               result = _gl_register_dup (oldfd, newfd);