From 3773b830ba1eae6e912e06290f291b0052e85ad8 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Mon, 10 Jun 2013 05:43:31 +0200 Subject: [PATCH] ldpreload.h: Split macro into function and macro. --- src/ldpreload.h | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/ldpreload.h b/src/ldpreload.h index a3d646e..6ef2911 100644 --- a/src/ldpreload.h +++ b/src/ldpreload.h @@ -28,24 +28,32 @@ #include /* dlsym() */ #include +#include +/* Load the function name using dlsym() and return it. Terminate program on + * failure. Split in function and macro to reduce code inserted into the + * function using the macro. */ +static void *dlsym_function(char const *name) { + void *result; + + int saved_errno = errno; /* just in case */ + + /* Clear possibly existing error. */ + dlerror(); + result = dlsym(RTLD_NEXT, name); + /* Not much we can do. Most likely the other output functions failed to + * load too. */ + if (dlerror() != NULL) { + abort(); + } + + errno = saved_errno; + return result; +} -/* Load the function name using dlsym() if necessary and store it in pointer. - * Terminate program on failure. */ #define DLSYM_FUNCTION(pointer, name) \ - if (NULL == (pointer)) { \ - int saved_errnox = errno; \ - char *error; \ - dlerror(); /* Clear possibly existing error. */ \ - \ - *(void **) (&(pointer)) = dlsym(RTLD_NEXT, (name)); \ - \ - if (NULL != (error = dlerror())) { \ - /* Not much we can do. Most likely the other output functions \ - * failed to load too. */ \ - abort(); \ - } \ - errno = saved_errnox; \ + if (!(pointer)) { \ + *(void **) (&(pointer)) = dlsym_function(name); \ } #endif -- 2.43.2