File: app.c

package info (click to toggle)
mk-configure 0.37.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,112 kB
  • sloc: ansic: 5,441; makefile: 1,412; sh: 1,086; cpp: 200; perl: 101; yacc: 85; lex: 21
file content (47 lines) | stat: -rw-r--r-- 849 bytes parent folder | download | duplicates (5)
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
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>

typedef void (*plugin_func_t) (void);

/* Function "putter" is for plugins only, it is not used by
   application. On some platforms it is not exported by default, this
   is why EXPORT_DYNAMIC is set to "yes"
*/
void putter (char *s);
void putter (char *s)
{
	printf ("%s\n", s);
}

int main (int argc, char **argv)
{
	void *pd;
	plugin_func_t f;
	int i;

	--argc; ++argv;

	for (i=0; i < argc; ++i){
		pd = dlopen (argv [i], RTLD_LAZY);
		if (!pd){
			fprintf (stderr, "dlopen(3) failed: %s\n", dlerror ());
			return 1;
		}

		f = (plugin_func_t) dlsym (pd, "print_message");
		if (!f){
			fprintf (stderr, "dlsym(3) failed: %s\n", dlerror ());
			return 1;
		}

		f ();

		if (dlclose (pd)){
			fprintf (stderr, "dlclose(3) failed: %s\n", dlerror ());
			return 1;
		}
	}

	return 0;
}