13
0
livetrax/libs/tk/suil/dylib.h

79 lines
1.6 KiB
C
Raw Permalink Normal View History

/*
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