diff options
author | Bruno Haible <bruno@clisp.org> | 2011-09-23 20:55:00 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2011-09-23 20:55:00 +0200 |
commit | feb7da5e51db75738e91cce135c1906f7dc10948 (patch) | |
tree | 9de740f4f714829d6ae7fba33a570870ed9e1a9f | |
parent | 27ba0d3030c9932731e6b55549733ae0090a1b62 (diff) | |
download | gnulib-feb7da5e51db75738e91cce135c1906f7dc10948.tar.gz |
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.
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | lib/dup2.c | 34 | ||||
-rw-r--r-- | m4/dup2.m4 | 8 | ||||
-rw-r--r-- | modules/dup2 | 1 |
4 files changed, 41 insertions, 11 deletions
@@ -1,5 +1,14 @@ 2011-09-23 Bruno Haible <bruno@clisp.org> + 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 <bruno@clisp.org> + msvc-inval: Fix compilation error. * lib/msvc-inval.h: Include <excpt.h>. diff --git a/lib/dup2.c b/lib/dup2.c index 234bdfe50b..b8798f3f0a 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 5c2cc9674c..cc641fe955 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 a94dc17162..2317db3cdf 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]) |