Update.
[glibc.git] / elf / multiload.c
blob724c1ed562624202a371f278cb2c0cf50b897dff
1 #include <dlfcn.h>
2 #include <errno.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <unistd.h>
8 int
9 main (void)
11 void *a;
12 void *b;
13 void *c;
14 void *d;
15 char *wd;
16 char *base;
17 char *buf;
19 /* Change to the binary directory. */
20 if (chdir (OBJDIR) != 0)
22 printf ("cannot change to `%s': %m", OBJDIR);
23 exit (EXIT_FAILURE);
26 wd = getcwd (NULL, 0);
27 base = basename (wd);
28 buf = alloca (strlen (wd) + strlen (base) + 5 + sizeof "testobj1.so");
30 printf ("loading `%s'\n", "./testobj1.so");
31 a = dlopen ("./testobj1.so", RTLD_NOW);
32 if (a == NULL)
34 printf ("cannot load `./testobj1.so': %s\n", dlerror ());
35 exit (EXIT_FAILURE);
38 stpcpy (stpcpy (stpcpy (buf, "../"), base), "/testobj1.so");
39 printf ("loading `%s'\n", buf);
40 b = dlopen (buf, RTLD_NOW);
41 if (b == NULL)
43 printf ("cannot load `%s': %s\n", buf, dlerror ());
44 exit (EXIT_FAILURE);
47 stpcpy (stpcpy (buf, wd), "/testobj1.so");
48 printf ("loading `%s'\n", buf);
49 c = dlopen (buf, RTLD_NOW);
50 if (c == NULL)
52 printf ("cannot load `%s': %s\n", buf, dlerror ());
53 exit (EXIT_FAILURE);
56 stpcpy (stpcpy (stpcpy (stpcpy (buf, wd), "/../"), base), "/testobj1.so");
57 printf ("loading `%s'\n", buf);
58 d = dlopen (buf, RTLD_NOW);
59 if (d == NULL)
61 printf ("cannot load `%s': %s\n", buf, dlerror ());
62 exit (EXIT_FAILURE);
65 if (a != b || b != c || c != d)
67 puts ("shared object loaded more than once");
68 exit (EXIT_FAILURE);
71 return 0;
74 int
75 foo (int a)
77 return a;