Mercurial > hg > octave-nkf > gnulib-hg
changeset 15751:6cad6a3713b8
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.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 23 Sep 2011 20:55:00 +0200 |
parents | dcb82e84f6fe |
children | b86e9061a6d0 |
files | ChangeLog lib/dup2.c m4/dup2.m4 modules/dup2 |
diffstat | 4 files changed, 41 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +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.
--- 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 @@ 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.
--- 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 @@ fi ]) ]) + +# Prerequisites of lib/dup2.c. +AC_DEFUN([gl_PREREQ_DUP2]. +[ + AC_REQUIRE([AC_C_INLINE]) +])