xref: /minix3/tests/lib/csu/h_initfini3.cxx (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc #include <dlfcn.h>
2*11be35a1SLionel Sambuc #include <err.h>
3*11be35a1SLionel Sambuc #include <unistd.h>
4*11be35a1SLionel Sambuc 
5*11be35a1SLionel Sambuc int
main(void)6*11be35a1SLionel Sambuc main(void)
7*11be35a1SLionel Sambuc {
8*11be35a1SLionel Sambuc 	static const char msg1[] = "main started\n";
9*11be35a1SLionel Sambuc 	static const char msg2[] = "main after dlopen\n";
10*11be35a1SLionel Sambuc 	static const char msg3[] = "main terminated\n";
11*11be35a1SLionel Sambuc 
12*11be35a1SLionel Sambuc 	void *handle;
13*11be35a1SLionel Sambuc 
14*11be35a1SLionel Sambuc 	write(STDOUT_FILENO, msg1, sizeof(msg1) - 1);
15*11be35a1SLionel Sambuc 	handle = dlopen("h_initfini3_dso.so", RTLD_NOW | RTLD_LOCAL);
16*11be35a1SLionel Sambuc 	if (handle == NULL)
17*11be35a1SLionel Sambuc 		err(1, "dlopen");
18*11be35a1SLionel Sambuc 	write(STDOUT_FILENO, msg2, sizeof(msg2) - 1);
19*11be35a1SLionel Sambuc 	dlclose(handle);
20*11be35a1SLionel Sambuc 	write(STDOUT_FILENO, msg3, sizeof(msg3) - 1);
21*11be35a1SLionel Sambuc 	return 0;
22*11be35a1SLionel Sambuc }
23