File: shared-initializer.c

package info (click to toggle)
pqiv 2.6-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 500 kB
  • ctags: 659
  • sloc: ansic: 6,227; sh: 318; makefile: 4
file content (31 lines) | stat: -rw-r--r-- 928 bytes parent folder | download
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
#include <string.h>
#include "../pqiv.h"

static const char *available_backends[] = {
	SHARED_BACKENDS
	NULL
};
file_type_handler_t file_type_handlers[sizeof(available_backends) / sizeof(char *)];

void initialize_file_type_handlers() {
	int i = 0;
	for(char **backend=(char **)&available_backends[0]; *backend; backend++) {
		gchar *backend_candidate = g_strdup_printf("pqiv-backend-%s.so", *backend);

		GModule *backend_module = g_module_open(backend_candidate, G_MODULE_BIND_LOCAL);
		if(backend_module) {
			gchar *backend_initializer = g_strdup_printf("file_type_%s_initializer", *backend);

			file_type_initializer_fn_t initializer;
			if(g_module_symbol(backend_module, backend_initializer, (gpointer *)&initializer)) {
				initializer(&file_type_handlers[i++]);
				g_module_make_resident(backend_module);
			}

			g_free(backend_initializer);
			g_module_close(backend_module);
		}

		g_free(backend_candidate);
	}
}