-
Notifications
You must be signed in to change notification settings - Fork 0
/
muk-dl.h
37 lines (31 loc) · 922 Bytes
/
muk-dl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-License-Identifier: MIT
#ifndef MUK_DL_H
#define MUK_DL_H
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <dlfcn.h>
// this is for function symbols, or other symbols that are not optional.
static inline void * MUK_DLSYM(void * restrict handle, const char * restrict symbol)
{
void * fp = dlsym(handle, symbol);
if (fp == NULL) {
//fprintf(stderr, "MUK_DLSYM: failed to find %s - %s\n", symbol, dlerror() );
//fflush(0);
}
return fp;
}
// this is for cases where symbols are optional, i.e. predefined handles,
// where we provide the value to use where the symbol is not found.
static inline void * MUK_DLSYM_OPT(void * restrict handle, const char * restrict symbol, void * fallback)
{
void * p = dlsym(handle, symbol);
if (p == NULL) {
p = fallback;
}
return p;
}
#endif