-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic_loader.c
More file actions
41 lines (33 loc) · 943 Bytes
/
Copy pathdynamic_loader.c
File metadata and controls
41 lines (33 loc) · 943 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
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <dlfcn.h>
#include "date_time_utils.h"
typedef Date (*GetCurrentDateFunc)();
typedef char* (*FormatDateFunc)(Date, char*, size_t);
int main() {
void* handle = dlopen("./libdate_time_utils.so", RTLD_LAZY);
if (!handle) {
fprintf(stderr, "Error: %s\n", dlerror());
return 1;
}
dlerror();
GetCurrentDateFunc get_current_date = (GetCurrentDateFunc)dlsym(handle, "get_current_date");
const char* error = dlerror();
if (error) {
fprintf(stderr, "Error loading get_current_date: %s\n", error);
dlclose(handle);
return 1;
}
FormatDateFunc format_date = (FormatDateFunc)dlsym(handle, "format_date");
error = dlerror();
if (error) {
fprintf(stderr, "Error loadingi format_date: %s\n", error);
dlclose(handle);
return 1;
}
Date today = get_current_date();
char buffer[20];
format_date(today, buffer, sizeof(buffer));
printf("Today's date: %s\n", buffer);
dlclose(handle);
return 0;
}