From: Simon Ruderich Date: Sat, 1 Jun 2013 20:47:23 +0000 (+0200) Subject: hookmacros.h: Be more careful to restore the errno. X-Git-Tag: 0.1~125 X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=66140e14e485af27f5234ae7b744a50dff3dd4c9;p=coloredstderr%2Fcoloredstderr.git hookmacros.h: Be more careful to restore the errno. check_handle_fd() or handle_fd_pre() might also modify it. --- diff --git a/src/hookmacros.h b/src/hookmacros.h index 09e718a..6f65d1e 100644 --- a/src/hookmacros.h +++ b/src/hookmacros.h @@ -26,6 +26,7 @@ #define _HOOK_PRE(type, name) \ int handle; \ + int saved_errno = errno; \ DLSYM_FUNCTION(real_ ## name, #name); #define _HOOK_PRE_FD(type, name, fd) \ type result; \ @@ -35,19 +36,21 @@ handle = check_handle_fd(fd); \ if (handle) { \ handle_fd_pre(fd, handle); \ - } + } \ + errno = saved_errno; #define _HOOK_PRE_FILE(type, name, file) \ type result; \ _HOOK_PRE(type, name) \ handle = check_handle_fd(fileno(file)); \ if (handle) { \ handle_file_pre(file, handle); \ - } + } \ + errno = saved_errno; /* Save and restore the errno to make sure we return the errno of the original * function call. */ #define _HOOK_POST_FD_(fd) \ if (handle) { \ - int saved_errno = errno; \ + saved_errno = errno; \ handle_fd_post(fd, handle); \ errno = saved_errno; \ } @@ -56,7 +59,7 @@ return result; #define _HOOK_POST_FILE(file) \ if (handle) { \ - int saved_errno = errno; \ + saved_errno = errno; \ handle_file_post(file, handle); \ errno = saved_errno; \ } \