X-Git-Url: https://ruderich.org/simon/gitweb/?p=coloredstderr%2Fcoloredstderr.git;a=blobdiff_plain;f=src%2Fhookmacros.h;fp=src%2Fhookmacros.h;h=6f65d1e8e84ae86cd8974aea29fba3487201edd7;hp=09e718a594f05216fb0034286ebb493ccdbd42cb;hb=66140e14e485af27f5234ae7b744a50dff3dd4c9;hpb=73870d5ed5fc275c462eefff724e3b26502ce26a 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; \ } \