File: reldep7.c

package info (click to toggle)
glibc 2.19-13
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 202,472 kB
  • ctags: 140,344
  • sloc: ansic: 969,274; asm: 241,208; sh: 10,047; makefile: 8,467; cpp: 3,595; perl: 2,077; pascal: 1,839; awk: 1,704; yacc: 317; sed: 73
file content (58 lines) | stat: -rw-r--r-- 1,176 bytes parent folder | download | duplicates (45)
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
48
49
50
51
52
53
54
55
56
57
58
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>

int
main (void)
{
  void *h1;
  void *h2;
  void *mod1_bar, *mod2_bar;

  h1 = dlopen ("reldep7mod1.so", RTLD_GLOBAL | RTLD_LAZY);
  if (h1 == NULL)
    {
      printf ("cannot open reldep7mod1.so: %s\n", dlerror ());
      exit (1);
    }

  h2 = dlopen ("reldep7mod2.so", RTLD_GLOBAL | RTLD_LAZY);
  if (h2 == NULL)
    {
      printf ("cannot open reldep7mod1.so: %s\n", dlerror ());
      exit (1);
    }

  mod1_bar = dlsym (h1, "mod1_bar");
  if (mod1_bar == NULL)
    {
      printf ("cannot get address of \"mod1_bar\": %s\n", dlerror ());
      exit (1);
    }

  mod2_bar = dlsym (h2, "mod2_bar");
  if (mod2_bar == NULL)
    {
      printf ("cannot get address of \"mod2_bar\": %s\n", dlerror ());
      exit (1);
    }

  printf ("%d\n", ((int (*) (void)) mod1_bar) ());
  printf ("%d\n", ((int (*) (void)) mod2_bar) ());

  if (dlclose (h1) != 0)
    {
      printf ("closing h1 failed: %s\n", dlerror ());
      exit (1);
    }

  printf ("%d\n", ((int (*) (void)) mod2_bar) ());

  if (dlclose (h2) != 0)
    {
      printf ("closing h2 failed: %s\n", dlerror ());
      exit (1);
    }

  return 0;
}