diff options
Diffstat (limited to 'src/dylib.h')
-rw-r--r-- | src/dylib.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/dylib.h b/src/dylib.h new file mode 100644 index 0000000..246693c --- /dev/null +++ b/src/dylib.h @@ -0,0 +1,78 @@ +/* + Copyright 2020 David Robillard <http://drobilla.net> + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#ifndef SUIL_DYLIB_H +#define SUIL_DYLIB_H + +#ifdef _WIN32 + +#include <windows.h> + +enum DylibFlags { + DYLIB_GLOBAL = 0, + DYLIB_LAZY = 1, + DYLIB_NOW = 2, +}; + +static inline void* +dylib_open(const char* const filename, const int flags) +{ + return LoadLibrary(filename); +} + +static inline int +dylib_close(void* const handle) +{ + return !FreeLibrary((HMODULE)handle); +} + +static inline const char* +dylib_error(void) +{ + return "Unknown error"; +} + +#else + +#include <dlfcn.h> + +enum DylibFlags { + DYLIB_GLOBAL = RTLD_GLOBAL, + DYLIB_LAZY = RTLD_LAZY, + DYLIB_NOW = RTLD_NOW, +}; + +static inline void* +dylib_open(const char* const filename, const int flags) +{ + return dlopen(filename, flags); +} + +static inline int +dylib_close(void* const handle) +{ + return dlclose(handle); +} + +static inline const char* +dylib_error(void) +{ + return dlerror(); +} + +#endif + +#endif // SUIL_DYLIB_H |