+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.
/* Copy a file descriptor, applying specific flags.
- Copyright (C) 2009-2023 Free Software Foundation, Inc.
+ Copyright (C) 2009-2024 Free Software Foundation, Inc.
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
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);