From 332485a61701a72ba8c8aa25eef602c4f1ef92a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Thu, 30 Apr 2015 20:06:23 +0000 Subject: provide a wrapper around sys_close() that always works, even with old Pd-versions (where we fallback to close()) svn path=/trunk/externals/iem/iemmatrix/; revision=17458 --- src/iemmatrix.h | 6 ++++++ src/iemmatrix_utility.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/iemmatrix.h b/src/iemmatrix.h index dc02288..72d6d57 100644 --- a/src/iemmatrix.h +++ b/src/iemmatrix.h @@ -197,6 +197,12 @@ t_matrixfloat*mtx_doTranspose(t_matrixfloat*output, int row, int col); t_matrixfloat*mtx_doMultiply(int rowA, t_matrixfloat*A, int colArowB, t_matrixfloat*B, int colB); +/** wrapper functions in iemmatrix_utility.c + * + * iemmatrix_fdclose == sys_close + */ +int iemmatrix_fdclose(int fd); + /* for debugging purposes */ #define MARK startpost("MARK[%s:%d@%s]", __FILE__, __LINE__, __FUNCTION__), post diff --git a/src/iemmatrix_utility.c b/src/iemmatrix_utility.c index 5d3d208..53cc2bc 100644 --- a/src/iemmatrix_utility.c +++ b/src/iemmatrix_utility.c @@ -16,6 +16,22 @@ G.Holzmann: this has been in mtx_matrix.c before now here should be the shared code !!! */ +#if defined __linux__ || defined __APPLE__ +# define DL_OPEN +#endif + +#ifdef DL_OPEN +# define _GNU_SOURCE +# include +#endif + +#if defined _WIN32 +# include +# include +# define close _close +#endif + +#include #include "iemmatrix.h" @@ -520,3 +536,29 @@ t_matrixfloat*mtx_doMultiply(int rowA, t_matrixfloat*A, int colArowB, t_matrixfl } return result; } + + +static void*get_function(const char*name) { +#ifdef DL_OPEN + return (void*)dlsym(RTLD_DEFAULT, name); +#elif defined _WIN32 + return (void*)GetProcAddress( GetModuleHandle("pd.dll"), name); +#else + // no loader for older Pd's.... +#endif + return NULL; +} +typedef int (*fdclose_fun_t)(int fd); +static fdclose_fun_t get_sysclose() { + fdclose_fun_t my_close=(fdclose_fun_t)get_function("sys_close"); + if(!my_close) + my_close=close; + return my_close; +} + + +int iemmatrix_fdclose(int fd) { + static fdclose_fun_t my_close=0; + if(!my_close)my_close=get_sysclose(); + return my_close(fd); +} -- cgit v1.2.1