]> ruderich.org/simon Gitweb - coloredstderr/coloredstderr.git/commitdiff
hookmacros.h: Reduce duplication in HOOK_VOID1().
authorSimon Ruderich <simon@ruderich.org>
Sat, 1 Jun 2013 20:44:22 +0000 (22:44 +0200)
committerSimon Ruderich <simon@ruderich.org>
Sat, 1 Jun 2013 20:44:22 +0000 (22:44 +0200)
src/hookmacros.h

index 9e1bd75fa6d60721bbf50a5709c14d5c9d38b46b..09e718a594f05216fb0034286ebb493ccdbd42cb 100644 (file)
 
 #define _HOOK_PRE(type, name) \
         int handle; \
-        type result; \
         DLSYM_FUNCTION(real_ ## name, #name);
 #define _HOOK_PRE_FD(type, name, fd) \
+        type result; \
+        _HOOK_PRE_FD_(type, name, fd)
+#define _HOOK_PRE_FD_(type, name, fd) \
         _HOOK_PRE(type, name) \
-        _HOOK_PRE_FD_ALONE(type, name, fd)
-#define _HOOK_PRE_FD_ALONE(type, name, fd) \
         handle = check_handle_fd(fd); \
         if (handle) { \
             handle_fd_pre(fd, handle); \
         }
 #define _HOOK_PRE_FILE(type, name, file) \
+        type result; \
         _HOOK_PRE(type, name) \
         handle = check_handle_fd(fileno(file)); \
         if (handle) { \
         }
 /* Save and restore the errno to make sure we return the errno of the original
  * function call. */
-#define _HOOK_POST_FD_ALONE(fd) \
+#define _HOOK_POST_FD_(fd) \
         if (handle) { \
             int saved_errno = errno; \
             handle_fd_post(fd, handle); \
             errno = saved_errno; \
         }
 #define _HOOK_POST_FD(fd) \
-        _HOOK_POST_FD_ALONE(fd) \
+        _HOOK_POST_FD_(fd) \
         return result;
 #define _HOOK_POST_FILE(file) \
         if (handle) { \
 #define HOOK_VOID1(type, name, fd, type1, arg1) \
     static type (*real_ ## name)(type1); \
     type name(type1 arg1) { \
-        int handle; \
-        DLSYM_FUNCTION(real_ ## name, #name); \
-        _HOOK_PRE_FD_ALONE(type, name, fd) \
+        _HOOK_PRE_FD_(type, name, fd) \
         real_ ## name(arg1); \
-        _HOOK_POST_FD_ALONE(fd) \
+        _HOOK_POST_FD_(fd) \
     }
 
 #define HOOK_FD3(type, name, fd, type1, arg1, type2, arg2, type3, arg3) \