ObjFW  Diff

Differences From Artifact [0c45c3aa04]:

To Artifact [6ef03d99d0]:


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
#include <string.h>
#include <dlfcn.h>

#import "OFPlugin.h"
#import "OFExceptions.h"

@implementation OFPlugin
+ pluginFromFile: (const char*)path
{
	char *file;
	size_t pathlen, suffixlen;
	void *handle;
	OFPlugin *(*init_plugin)();
	OFPlugin *plugin;

	pathlen = strlen(path);
	suffixlen = strlen(PLUGIN_SUFFIX);

	if ((file = malloc(pathlen + suffixlen + 1)) == NULL) {
		@throw [OFNoMemException newWithClass: self
					      andSize: pathlen +
					      suffixlen + 1];
	}
	memcpy(file, path, pathlen);
	memcpy(file + pathlen, PLUGIN_SUFFIX, suffixlen);
	file[pathlen + suffixlen] = 0;

	if ((handle = dlopen(file, RTLD_NOW)) == NULL) {
		free(file);
		@throw [OFInitializationFailedException newWithClass: self];
	}







|







|







|







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
#include <string.h>
#include <dlfcn.h>

#import "OFPlugin.h"
#import "OFExceptions.h"

@implementation OFPlugin
+ pluginFromFile: (OFString*)path
{
	char *file;
	size_t pathlen, suffixlen;
	void *handle;
	OFPlugin *(*init_plugin)();
	OFPlugin *plugin;

	pathlen = [path length];
	suffixlen = strlen(PLUGIN_SUFFIX);

	if ((file = malloc(pathlen + suffixlen + 1)) == NULL) {
		@throw [OFNoMemException newWithClass: self
					      andSize: pathlen +
					      suffixlen + 1];
	}
	memcpy(file, [path cString], pathlen);
	memcpy(file + pathlen, PLUGIN_SUFFIX, suffixlen);
	file[pathlen + suffixlen] = 0;

	if ((handle = dlopen(file, RTLD_NOW)) == NULL) {
		free(file);
		@throw [OFInitializationFailedException newWithClass: self];
	}