-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibload.c
More file actions
64 lines (48 loc) · 1.47 KB
/
libload.c
File metadata and controls
64 lines (48 loc) · 1.47 KB
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
57
58
59
60
61
62
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// needed for the dynamic loading
#include <dlfcn.h>
// the following is needed for the PATH_MAX
#include <dirent.h>
//following is included because of the chdir
#include <unistd.h>
#include "DebugPrint.h"
#define BUFFLEN 10024
int
LoadObject (char *name, int depth)
{
void *ClassHandle;
int *ClassMsgFunc;
char *error;
char hereName[BUFFLEN];
char DebugMsg[BUFFLEN];
//LPVCLASS pnewDevClass;
char bundlePath[PATH_MAX];
char * ignore = getcwd( bundlePath, PATH_MAX );
if (ignore == NULL) ;
fflush(NULL);
//printf("\n");
snprintf (hereName, BUFFLEN-10, "%s/%s", bundlePath, name);
ClassHandle = dlopen(hereName, RTLD_LAZY);
if (!ClassHandle) {
//fputs(dlerror(), stderr);
snprintf((char *)&DebugMsg, BUFFLEN-10, "Failed to load %s", hereName);
DebugPrint ( (char *)&DebugMsg, __FILE__, __LINE__, PROG_FLOW);
return 0;
} else {
snprintf((char *)&DebugMsg, BUFFLEN-1, "Loaded %s", name);
DebugPrint ((char *)&DebugMsg, __FILE__, __LINE__, PROG_FLOW);
}
ClassMsgFunc = dlsym(ClassHandle, "Handle_Message");
if (ClassMsgFunc == NULL) ;
if ((error = dlerror()) != NULL) {
// couldn't find the proper start point, unload library
dlclose(ClassHandle);
//fputs(error, stderr);
DebugPrint ( "Failed to find HandleMessage in Library.", __FILE__, __LINE__, ERROR);
return 0;
} else
DebugPrint ( "Found HandleMessage in Library.", __FILE__, __LINE__, PROG_FLOW);
return 0;
}