Mercurial > hg > octave-nkf > gnulib-hg
changeset 12148:3c9981d0d9c3
dup2: work around FreeBSD 6.1 bug
dup2(1,1000000) needs to fail with EBADF (per POSIX), not
EMFILE, based on our usage of it in other modules.
* m4/dup2.m4 (gl_FUNC_DUP2): Detect bug.
* doc/posix-functions/dup2.texi (dup2): Document it.
Reported by Nelson H. F. Beebe and Jim Meyering.
Signed-off-by: Eric Blake <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Fri, 09 Oct 2009 21:28:40 -0600 |
parents | a620bedbe958 |
children | 2804fee2b5e8 |
files | ChangeLog doc/posix-functions/dup2.texi m4/dup2.m4 |
diffstat | 3 files changed, 20 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2009-10-09 Eric Blake <ebb9@byu.net> + dup2: work around FreeBSD 6.1 bug + * m4/dup2.m4 (gl_FUNC_DUP2): Detect bug. + * doc/posix-functions/dup2.texi (dup2): Document it. + Reported by Nelson H. F. Beebe and Jim Meyering. + test-stat-time: port to buggy NFS clients * tests/test-stat-time.c (main) [W32]: Reduce ifdefs. (test_ctime): Also skip test if mtime and ctime are skewed.
--- a/doc/posix-functions/dup2.texi +++ b/doc/posix-functions/dup2.texi @@ -25,6 +25,12 @@ Linux releases between July 2008 and May 2009 (versions 2.6.27 to 2.6.29). @item +This function returns @code{EMFILE} instead of @code{EBADF} for +extremely large targets, which interferes with using +@code{dup2(fd,fd)==fd)} as the minimal @code{EBADF} filter: +FreeBSD 6.1, Cygwin 1.5. + +@item This function is missing on some older platforms. @end itemize
--- a/m4/dup2.m4 +++ b/m4/dup2.m4 @@ -1,4 +1,4 @@ -#serial 8 +#serial 9 dnl Copyright (C) 2002, 2005, 2007, 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, @@ -15,12 +15,16 @@ else AC_CACHE_CHECK([whether dup2 works], [gl_cv_func_dup2_works], [AC_RUN_IFELSE([ - AC_LANG_PROGRAM([[#include <unistd.h>]], + AC_LANG_PROGRAM([[#include <unistd.h> +#include <errno.h>]], [if (dup2 (1, 1) == 0) return 1; close (0); if (dup2 (0, 0) != -1) - return 1; + return 2; + /* Many gnulib modules require POSIX conformance of EBADF. */ + if (dup2 (1, 1000000) == -1 && errno != EBADF) + return 3; return 0; ]) ], @@ -33,6 +37,8 @@ linux*) # On linux between 2008-07-27 and 2009-05-11, dup2 of a # closed fd may yield -EBADF instead of -1 / errno=EBADF. gl_cv_func_dup2_works=no;; + freebsd*) # on FreeBSD 6.1, dup2(1,1000000) gives EMFILE, not EBADF. + gl_cv_func_dup2_works=no;; *) gl_cv_func_dup2_works=yes;; esac]) ])