Commit 49e5954e authored by Bruno Haible's avatar Bruno Haible
Browse files

Tolerate declared but missing dup3 syscall.

parent b23a8463
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.
......@@ -48,6 +48,17 @@
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;
......
......@@ -179,7 +179,6 @@ extern int dup2 (int oldfd, int newfd);
#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>)
......@@ -188,8 +187,10 @@ extern int dup2 (int oldfd, int newfd);
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,
......@@ -14,6 +14,5 @@ AC_DEFUN([gl_FUNC_DUP3],
AC_CHECK_FUNCS_ONCE([dup3])
if test $ac_cv_func_dup3 != yes; then
HAVE_DUP3=0
AC_LIBOBJ([dup3])
fi
])
......@@ -16,6 +16,7 @@ gl_FUNC_DUP3
gl_UNISTD_MODULE_INDICATOR([dup3])
Makefile.am:
lib_SOURCES += dup3.c
Include:
<unistd.h>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment