ObjFW  Diff

Differences From Artifact [b72d21c5c5]:

To Artifact [b318936bd6]:


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
63
64
65
66
67
68
69
70
{
	char *file;
	size_t pathlen, suffixlen;
	void *handle;
	OFPlugin *(*init_plugin)();
	OFPlugin *plugin;

	if ((self = [super init])) {
		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];
		}
		free(file);

		if ((init_plugin = dlsym(handle, "init_plugin")) == NULL ||
		    (plugin = init_plugin()) == nil) {
			dlclose(handle);
			@throw [OFInitializationFailedException
			    newWithClass: self];
		}

		plugin->handle = handle;
		return plugin;
	}

	return self;
}

- free
{
	dlclose(handle);

	return [super free];
}
@end







<
|
|

|
|
|
|
|
|
|
|

|
|
|
<
|
|

|
|
|
|
<
|

|
|
<
<
<









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
63
64
{
	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];

	}
	free(file);

	if ((init_plugin = dlsym(handle, "init_plugin")) == NULL ||
	    (plugin = init_plugin()) == nil) {
		dlclose(handle);
		@throw [OFInitializationFailedException newWithClass: self];

	}

	plugin->handle = handle;
	return plugin;



}

- free
{
	dlclose(handle);

	return [super free];
}
@end