+2009-08-23 Bruno Haible <bruno@clisp.org>
+
+ Tolerate declared but missing dup3 syscall.
+ * lib/dup3.c (dup3): Invoke original dup3 function first, if available.
+ * lib/unistd.in.h (dup3): If the function is already present,
+ override it.
+ * m4/dup3.m4 (gl_FUNC_DUP3): Remove AC_LIBOBJ invocation.
+ * modules/dup3 (Makefile.am): Compile dup3.c always.
+ Reported by Paolo Bonzini.
+
2009-08-23 Bruno Haible <bruno@clisp.org>
Tolerate declared but missing pipe2 syscall.
int
dup3 (int oldfd, int newfd, int flags)
{
+#if HAVE_DUP3
+# undef dup3
+ /* Try the system call first, if it exists. (We may be running with a glibc
+ that has the function but with an older kernel that lacks it.) */
+ {
+ int result = dup3 (oldfd, newfd, flags);
+ if (!(result < 0 && errno == ENOSYS))
+ return result;
+ }
+#endif
+
if (oldfd < 0 || newfd < 0 || newfd >= getdtablesize ())
{
errno = EBADF;
#if @GNULIB_DUP3@
-# if !@HAVE_DUP3@
/* Copy the file descriptor OLDFD into file descriptor NEWFD, with the
specified flags.
The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
Return newfd if successful, otherwise -1 and errno set.
See the Linux man page at
<http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>. */
-extern int dup3 (int oldfd, int newfd, int flags);
+# if @HAVE_DUP3@
+# define dup3 rpl_dup3
# endif
+extern int dup3 (int oldfd, int newfd, int flags);
#elif defined GNULIB_POSIXCHECK
# undef dup3
# define dup3(o,n,f) \
-# dup3.m4 serial 1
+# dup3.m4 serial 2
dnl Copyright (C) 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
AC_CHECK_FUNCS_ONCE([dup3])
if test $ac_cv_func_dup3 != yes; then
HAVE_DUP3=0
- AC_LIBOBJ([dup3])
fi
])
gl_UNISTD_MODULE_INDICATOR([dup3])
Makefile.am:
+lib_SOURCES += dup3.c
Include:
<unistd.h>