forked from gabryon99/jb-internship-2025-material
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_hook.h
More file actions
32 lines (28 loc) · 953 Bytes
/
Copy pathapi_hook.h
File metadata and controls
32 lines (28 loc) · 953 Bytes
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
#ifndef API_HOOK
#define API_HOOK
#include "render.h"
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
/* Defined function pointer hooks to the render library API */
typedef Render* (*fn_create_ctx)(Render*, int, int, const char*);
typedef int (*fn_init_ctx)(Render*);
typedef void (*fn_shutdown)(Render*);
typedef int (*fn_pump_loop)(Render*);
typedef int (*fn_draw)(Render*, int);
typedef unsigned long (*fn_time_ms)(void);
typedef int (*fn_get_dim)(void);
typedef const char* (*fn_get_title)(void);
typedef uint32_t* (*fn_alloc_fb)(Render*);
static void* dl(void* handle, const char* name) {
dlerror();
void* sym = dlsym(handle, name);
const char* err = dlerror();
if (!sym || err) {
fprintf(stderr, "Failed to resolve symbol '%s': %s\n", name, err ? err : "unknown error");
dlclose(handle);
exit(EXIT_FAILURE);
}
return sym;
}
#endif // API_HOOK