1 /*
2  * Copyright (c) 2014 Henri Kemppainen <duclare@guu.fi>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #include <dlfcn.h>
18 #include <stdio.h>
19 
20 int
21 main()
22 {
23         void *libaa, *libbb;
24 	int flag = RTLD_NOW;
25 
26         if ((libaa = dlopen("libaa.so", flag)) == NULL) {
27                 printf("dlopen(\"libaa.so\", %d) FAILED\n", flag);
28                 return 1;
29         }
30 
31 	if ((libbb = dlopen("libbb.so", flag)) == NULL) {
32 		printf("dlopen(\"libbb.so\", %d) FAILED\n", flag);
33 		return 1;
34 	}
35 
36         if (dlclose(libbb)) {
37                 printf("dlclose(libbb) FAILED\n%s\n", dlerror());
38 		return 1;
39         }
40 
41 	if ((libbb = dlopen("libbb.so", flag)) == NULL) {
42 		printf("dlopen(\"libbb.so\", %d) FAILED\n", flag);
43 		return 1;
44 	}
45 
46         if (dlclose(libbb)) {
47                 printf("dlclose(libbb) FAILED\n%s\n", dlerror());
48 		return 1;
49         }
50 
51         if (dlclose(libaa)) {
52                 printf("dlclose(libaa) FAILED\n%s\n", dlerror());
53 		return 1;
54         }
55 
56 	return 0;
57 }
58 
59