-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFACT_libs.c
56 lines (47 loc) · 1.61 KB
/
FACT_libs.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* This file is part of FACT.
*
* FACT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FACT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with FACT. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FACT.h"
#include "FACT_vm.h"
#include "FACT_error.h"
#include "FACT_types.h"
#include "FACT_scope.h"
#include <dlfcn.h>
/**
* FACT_load_lib:
* This function simply loads a library, searches for the "MOD_MAP" symbol
* and loads all of the listed functions. It's very simple and probably
* flawed. I'll fix that later.
*/
void FACT_load_lib (char *lib_name)
{
void *lib;
size_t i;
FACT_scope_t temp;
struct mapping {
const char *func_name;
void (*func)(void);
} *map;
lib = dlopen (lib_name, RTLD_LAZY);
if (lib == NULL)
FACT_throw_error (CURR_THIS, "could not load library \"%s\"", lib_name);
map = (struct mapping *) dlsym (lib, "MOD_MAP");
if (map == NULL)
FACT_throw_error (CURR_THIS, "could not find MOD_MAP symbol in library \"%s\"", lib_name);
for (i = 0; map[i].func_name != NULL && map[i].func != NULL; i++) {
temp = FACT_add_scope (CURR_THIS, (char *) map[i].func_name);
temp->extrn_func = map[i].func;
}
}