From: Bruno Haible Date: Sun, 23 Aug 2009 22:56:31 +0000 (+0200) Subject: Tolerate declared but missing dup3 syscall. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49e5954ef6b0ac412149f63da197c7bd5ca9bb6f;p=pspp Tolerate declared but missing dup3 syscall. --- diff --git a/ChangeLog b/ChangeLog index 3f8349d429..a24ed56193 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-08-23 Bruno Haible + + 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 Tolerate declared but missing pipe2 syscall. diff --git a/lib/dup3.c b/lib/dup3.c index b9fb341f3b..62cdb53d31 100644 --- a/lib/dup3.c +++ b/lib/dup3.c @@ -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; diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 2f3be17400..e81d35c675 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -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 ) @@ -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 . */ -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) \ diff --git a/m4/dup3.m4 b/m4/dup3.m4 index e4fe7a6abc..0640ca934b 100644 --- a/m4/dup3.m4 +++ b/m4/dup3.m4 @@ -1,4 +1,4 @@ -# 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 ]) diff --git a/modules/dup3 b/modules/dup3 index 38bdcf039c..46650441db 100644 --- a/modules/dup3 +++ b/modules/dup3 @@ -16,6 +16,7 @@ gl_FUNC_DUP3 gl_UNISTD_MODULE_INDICATOR([dup3]) Makefile.am: +lib_SOURCES += dup3.c Include: