From: Collin Funk Date: Thu, 13 Mar 2025 01:55:26 +0000 (-0700) Subject: dup3: Fix behavior for equal file descriptors on Haiku. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=0424f0108e1beaf45b897a456aab49a03bd2cb0c;p=gnulib.git dup3: Fix behavior for equal file descriptors on Haiku. * lib/dup3.c (dup3) [__HAIKU__]: Set errno to EINVAL and return -1 if both file descriptors are equal. * doc/posix-functions/dup3.texi: Document the Haiku bug. --- diff --git a/ChangeLog b/ChangeLog index 329f4e424e..0a7c7f1dd7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2025-03-12 Collin Funk + + dup3: Fix behavior for equal file descriptors on Haiku. + * lib/dup3.c (dup3) [__HAIKU__]: Set errno to EINVAL and return -1 if + both file descriptors are equal. + * doc/posix-functions/dup3.texi: Document the Haiku bug. + 2025-03-10 Bruno Haible quotearg: Avoid undefined behaviour. diff --git a/doc/posix-functions/dup3.texi b/doc/posix-functions/dup3.texi index e7e4a507d0..3e9bd79fb0 100644 --- a/doc/posix-functions/dup3.texi +++ b/doc/posix-functions/dup3.texi @@ -22,7 +22,8 @@ Cygwin 1.7.25. @item This function mistakenly succeeds when given two equal file descriptors on some platforms: @c https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=58266 -NetBSD 10.0. +@c https://dev.haiku-os.org/ticket/19476 +NetBSD 10.0, Haiku. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/dup3.c b/lib/dup3.c index 70c55990b0..2d5d51a769 100644 --- a/lib/dup3.c +++ b/lib/dup3.c @@ -46,8 +46,10 @@ dup3 (int oldfd, int newfd, int flags) { 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__ + expected to fail with error EINVAL. + + Likewise on Haiku. */ +# if defined __NetBSD__ || defined __HAIKU__ if (newfd == oldfd) { errno = EINVAL;