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
|
* the packaging of this file.
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#import "OFPlugin.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
@implementation OFPlugin
+ pluginFromFile: (OFString*)path
{
OFAutoreleasePool *pool;
OFString *file;
void *handle;
OFPlugin *(*init_plugin)();
OFPlugin *plugin;
pool = [[OFAutoreleasePool alloc] init];
file = [OFMutableString stringWithString: path];
[file appendCString: PLUGIN_SUFFIX];
if ((handle = dlopen([file cString], RTLD_LAZY)) == NULL)
@throw [OFInitializationFailedException newWithClass: self];
[pool release];
if ((init_plugin = dlsym(handle, "init_plugin")) == NULL ||
(plugin = init_plugin()) == nil) {
dlclose(handle);
@throw [OFInitializationFailedException newWithClass: self];
}
plugin->handle = handle;
return plugin;
}
|
>
>
>
>
>
>
>
>
>
|
|
|
|
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
|
* the packaging of this file.
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
#ifndef _WIN32
#include <dlfcn.h>
#endif
#import "OFPlugin.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#ifdef _WIN32
#define dlopen(file, mode) LoadLibrary(file)
#define dlsym(handle, symbol) GetProcAddress(handle, symbol)
#define dlclose(handle) FreeLibrary(handle)
#endif
@implementation OFPlugin
+ pluginFromFile: (OFString*)path
{
OFAutoreleasePool *pool;
OFString *file;
of_plugin_handle_t handle;
OFPlugin *(*init_plugin)();
OFPlugin *plugin;
pool = [[OFAutoreleasePool alloc] init];
file = [OFMutableString stringWithString: path];
[file appendCString: PLUGIN_SUFFIX];
if ((handle = dlopen([file cString], RTLD_LAZY)) == NULL)
@throw [OFInitializationFailedException newWithClass: self];
[pool release];
init_plugin = (OFPlugin*(*)())dlsym(handle, "init_plugin");
if (init_plugin == NULL || (plugin = init_plugin()) == nil) {
dlclose(handle);
@throw [OFInitializationFailedException newWithClass: self];
}
plugin->handle = handle;
return plugin;
}
|