]> ruderich.org/simon Gitweb - coloredstderr/coloredstderr.git/commitdiff
hookmacros.h: Remove duplication in _HOOK_PRE_FD_/_HOOK_PRE_FILE.
authorSimon Ruderich <simon@ruderich.org>
Thu, 13 Jun 2013 14:35:55 +0000 (16:35 +0200)
committerSimon Ruderich <simon@ruderich.org>
Thu, 13 Jun 2013 19:44:55 +0000 (21:44 +0200)
src/hookmacros.h

index b8b70ec03bf035fc26c927de13e5caaaa7331daa..42273e4fd3f35c2f7ba1fda7695317b566fb54b3 100644 (file)
@@ -54,7 +54,7 @@
  *     return result;
  */
 
-#define _HOOK_PRE(type, name) \
+#define _HOOK_PRE(type, name, fd) \
         int handle; \
         if (unlikely(!(real_ ## name ))) { \
             *(void **) (&(real_ ## name)) = dlsym_function(#name); \
             if (unlikely(!initialized)) { \
                 init_from_environment(); \
             } \
-        }
-#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) \
+        } \
+        /* Check if this fd should be handled. */ \
         if (unlikely(tracked_fds_find(fd))) { \
             if (unlikely(force_write_to_non_tty)) { \
                 handle = 1; \
             } \
         } else { \
             handle = 0; \
-        } \
+        }
+#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, fd) \
         if (unlikely(handle)) { \
             handle_fd_pre(fd); \
         }
 #define _HOOK_PRE_FILE(type, name, file) \
         type result; \
-        _HOOK_PRE(type, name) \
-        if (unlikely(tracked_fds_find(fileno(file)))) { \
-            if (unlikely(force_write_to_non_tty)) { \
-                handle = 1; \
-            } else { \
-                handle = isatty_noinline(fileno(file)); \
-            } \
-        } else { \
-            handle = 0; \
-        } \
+        _HOOK_PRE(type, name, fileno(file)) \
         if (unlikely(handle)) { \
             handle_file_pre(file); \
         }