From: Bruno Haible Date: Fri, 23 Sep 2011 18:55:00 +0000 (+0200) Subject: dup2: Make code more maintainable. X-Git-Tag: v0.1~1775 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=feb7da5e51db75738e91cce135c1906f7dc10948;p=gnulib.git dup2: Make code more maintainable. * lib/dup2.c (dup2_nothrow): New function, extracted from rpl_dup2. (rpl_dup2): Use it. * m4/dup2.m4 (gl_PREREQ_DUP2): New macro. * modules/dup2 (configure.ac): Invoke it. Reported by Paul Eggert. --- diff --git a/ChangeLog b/ChangeLog index 9485f561d..74677b0a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2011-09-23 Bruno Haible + dup2: Make code more maintainable. + * lib/dup2.c (dup2_nothrow): New function, extracted from rpl_dup2. + (rpl_dup2): Use it. + * m4/dup2.m4 (gl_PREREQ_DUP2): New macro. + * modules/dup2 (configure.ac): Invoke it. + Reported by Paul Eggert. + +2011-09-23 Bruno Haible + msvc-inval: Fix compilation error. * lib/msvc-inval.h: Include . diff --git a/lib/dup2.c b/lib/dup2.c index 234bdfe50..b8798f3f0 100644 --- a/lib/dup2.c +++ b/lib/dup2.c @@ -37,6 +37,29 @@ # undef dup2 +# if HAVE_MSVC_INVALID_PARAMETER_HANDLER +static inline int +dup2_nothrow (int fd, int desired_fd) +{ + int result; + + TRY_MSVC_INVAL + { + result = dup2 (fd, desired_fd); + } + CATCH_MSVC_INVAL + { + result = -1; + errno = EBADF; + } + DONE_MSVC_INVAL; + + return result; +} +# else +# define dup2_nothrow dup2 +# endif + int rpl_dup2 (int fd, int desired_fd) { @@ -79,16 +102,7 @@ rpl_dup2 (int fd, int desired_fd) return fcntl (fd, F_GETFL) == -1 ? -1 : fd; # endif - TRY_MSVC_INVAL - { - result = dup2 (fd, desired_fd); - } - CATCH_MSVC_INVAL - { - result = -1; - errno = EBADF; - } - DONE_MSVC_INVAL; + result = dup2_nothrow (fd, desired_fd); # ifdef __linux__ /* Correct a Linux return value. diff --git a/m4/dup2.m4 b/m4/dup2.m4 index 5c2cc9674..cc641fe95 100644 --- a/m4/dup2.m4 +++ b/m4/dup2.m4 @@ -1,4 +1,4 @@ -#serial 14 +#serial 15 dnl Copyright (C) 2002, 2005, 2007, 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, @@ -71,3 +71,9 @@ AC_DEFUN([gl_FUNC_DUP2], fi ]) ]) + +# Prerequisites of lib/dup2.c. +AC_DEFUN([gl_PREREQ_DUP2]. +[ + AC_REQUIRE([AC_C_INLINE]) +]) diff --git a/modules/dup2 b/modules/dup2 index a94dc1716..2317db3cd 100644 --- a/modules/dup2 +++ b/modules/dup2 @@ -14,6 +14,7 @@ configure.ac: gl_FUNC_DUP2 if test $HAVE_DUP2 = 0 || test $REPLACE_DUP2 = 1; then AC_LIBOBJ([dup2]) + gl_PREREQ_DUP2 fi gl_UNISTD_MODULE_INDICATOR([dup2])