]> git.ipfire.org Git - thirdparty/glibc.git/blame - elf/tst-dlmopen1mod.c
test-container: Fix "unused code" warnings on HURD
[thirdparty/glibc.git] / elf / tst-dlmopen1mod.c
CommitLineData
c0f62c56
UD
1#include <dlfcn.h>
2#include <stdio.h>
3#include <gnu/lib-names.h>
4
5
b1f68750
UD
6static int cnt;
7
8static void
9__attribute ((constructor))
10constr (void)
11{
12 ++cnt;
13}
14
15
c0f62c56
UD
16int
17foo (Lmid_t ns2)
18{
19 void *h = dlopen (LIBC_SO, RTLD_LAZY|RTLD_NOLOAD);
20 if (h == NULL)
21 {
22 printf ("cannot get handle for %s: %s\n", LIBC_SO, dlerror ());
23 return 1;
24 }
25
26 Lmid_t ns = -10;
27 if (dlinfo (h, RTLD_DI_LMID, &ns) != 0)
28 {
29 printf ("dlinfo for %s in %s failed: %s\n",
30 LIBC_SO, __func__, dlerror ());
31 return 1;
32 }
33
34 if (ns != ns2)
35 {
36 printf ("namespace for %s not LM_ID_BASE\n", LIBC_SO);
37 return 1;
38 }
39
40 if (dlclose (h) != 0)
41 {
42 printf ("dlclose for %s in %s failed: %s\n",
43 LIBC_SO, __func__, dlerror ());
44 return 1;
45 }
46
b1f68750
UD
47 if (cnt == 0)
48 {
49 puts ("constructor did not run");
50 return 1;
51 }
52 else if (cnt != 1)
53 {
54 puts ("constructor did not run exactly once");
55 return 1;
56 }
57
c0f62c56
UD
58 return 0;
59}