-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex29.c
37 lines (27 loc) · 776 Bytes
/
ex29.c
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
#include <stdio.h>
#include "dbg.h"
#include <dlfcn.h>
typedef int (*lib_function) (const char *data);
int main(int argc, char *argv[])
{
int rc = 0;
check(argc == 4, "USAGE: ex29 libex29.so function data");
char *lib_file = argv[1];
char *func_to_run = argv[2];
char *data = argv[3];
void *lib = dlopen(lib_file, RTLD_NOW);
check(lib != NULL, "Failed to open the library %s: %s", lib_file,
dlerror());
lib_function func = dlsym(lib, func_to_run);
check(func != NULL,
"Did not find %s function in the library %s: %s", func_to_run,
lib_file, dlerror());
rc = func(data);
check(rc == 0, "Function %s return %d for data: %s", func_to_run,
rc, data);
rc = dlclose(lib);
check(rc == 0, "Failed to close %s", lib_file);
return 0;
error:
return 1;
}