* m4/fcntl.m4 (gl_FUNC_FCNTL): Also catch Haiku errno bug.
* lib/fcntl.c (rpl_fcntl) [F_DUPFD]: Work around Haiku losing
cloexec bit on duplication.
* doc/posix-functions/fcntl.texi (fcntl): Document the bug.
Signed-off-by: Eric Blake <eblake@redhat.com>
+2011-01-26 Eric Blake <eblake@redhat.com>
+
+ fcntl: work around Haiku F_DUPFD bugs
+ * m4/fcntl.m4 (gl_FUNC_FCNTL): Also catch Haiku errno bug.
+ * lib/fcntl.c (rpl_fcntl) [F_DUPFD]: Work around Haiku losing
+ cloexec bit on duplication.
+ * doc/posix-functions/fcntl.texi (fcntl): Document the bug.
+
2011-01-26 Bruno Haible <bruno@clisp.org>
Enable memory leak tests on AIX.
@item
The @code{F_DUPFD} action of this function does not reject
out-of-range targets properly on some platforms:
-Cygwin 1.5.x.
+Cygwin 1.5.x, Haiku.
+
+@item
+The @code{F_DUPFD} action of this function mistakenly clears
+FD_CLOEXEC on the source descriptor on some platforms:
+Haiku.
@item
This function is missing on some platforms:
errno = EINVAL;
else
{
+ /* Haiku alpha 2 loses fd flags on original. */
+ int flags = fcntl (fd, F_GETFD);
+ if (flags < 0)
+ {
+ result = -1;
+ break;
+ }
result = fcntl (fd, action, target);
+ if (0 <= result && fcntl (fd, F_SETFD, flags) == -1)
+ {
+ int saved_errno = errno;
+ close (result);
+ result = -1;
+ errno = saved_errno;
+ }
# if REPLACE_FCHDIR
if (0 <= result)
result = _gl_register_dup (fd, result);
-# fcntl.m4 serial 3
+# fcntl.m4 serial 4
dnl Copyright (C) 2009-2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
gl_REPLACE_FCNTL
else
dnl cygwin 1.5.x F_DUPFD has wrong errno, and allows negative target
+ dnl haiku alpha 2 F_DUPFD has wrong errno
AC_CACHE_CHECK([whether fcntl handles F_DUPFD correctly],
[gl_cv_func_fcntl_f_dupfd_works],
[AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#include <fcntl.h>
-]], [[return fcntl (0, F_DUPFD, -1) != -1;
+#include <errno.h>
+]], [[int result = 0;
+ if (fcntl (0, F_DUPFD, -1) != -1) result |= 1;
+ if (errno != EINVAL) result |= 2;
+ return result;
]])],
[gl_cv_func_fcntl_f_dupfd_works=yes],
[gl_cv_func_fcntl_f_dupfd_works=no],