From 66140e14e485af27f5234ae7b744a50dff3dd4c9 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 1 Jun 2013 22:47:23 +0200 Subject: [PATCH] hookmacros.h: Be more careful to restore the errno. check_handle_fd() or handle_fd_pre() might also modify it. --- src/hookmacros.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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; \ } \ -- 2.45.2