1: #include <dlfcn.h>
2: #include <stdio.h>
3:
4:
5:
6: #define TEST_ROUNDS 10
7:
8:
9: static const char unknown[] = "a-file-with-this-name-does-not-exist";
10: static const char exists[] = "failtestmod.so";
11:
12:
13: int
14: main (void)
15: {
16: int i;
17:
18: setvbuf (stdout, NULL, _IONBF, 0);
19:
20: for (i = 0; i < TEST_ROUNDS; ++i)
21: {
22: void *dsc;
23:
24: printf ("Round %d: Try loading \"%s\"\n", i, unknown);
25:
26: dsc = dlopen (unknown, RTLD_NOW);
27: if (dsc != NULL)
28: {
29: printf ("We found a file of name \"%s\": this should not happen\n",
30: unknown);
31: return 1;
32: }
33:
34: printf ("Round %d: loading \"%s\" failed\n", i, unknown);
35:
36:
37: dsc = dlopen (exists, RTLD_NOW);
38: if (dsc == NULL)
39: {
40: printf ("Could not load \"%s\": %s\n", exists, dlerror ());
41: return 1;
42: }
43:
44: printf ("Round %d: Loaded \"%s\"\n", i, exists);
45:
46: dlclose (dsc);
47:
48: printf ("Round %d: Unloaded \"%s\"\n", i, exists);
49: }
50:
51: return 0;
52: }
53:
54:
55: extern void foo (void);
56:
57: void
58: foo (void)
59: {
60: }