xref: /freebsd/contrib/netbsd-tests/lib/csu/h_initfini_common.cxx (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1 #include <unistd.h>
2 
3 #ifdef CHECK_STACK_ALIGNMENT
4 #include <stdlib.h>
5 
6 extern "C" int check_stack_alignment(void);
7 #endif
8 
9 class Test {
10 public:
11 	Test()
12 	{
13 		static const char msg[] = "constructor executed\n";
14 		write(STDOUT_FILENO, msg, sizeof(msg) - 1);
15 #ifdef CHECK_STACK_ALIGNMENT
16 		if (!check_stack_alignment()) {
17 			static const char msg2[] = "stack unaligned \n";
18 			write(STDOUT_FILENO, msg2, sizeof(msg2) - 1);
19 			exit(1);
20 		}
21 #endif
22 	}
23 	~Test()
24 	{
25 		static const char msg[] = "destructor executed\n";
26 		write(STDOUT_FILENO, msg, sizeof(msg) - 1);
27 #ifdef CHECK_STACK_ALIGNMENT
28 		if (!check_stack_alignment()) {
29 			static const char msg2[] = "stack unaligned \n";
30 			write(STDOUT_FILENO, msg2, sizeof(msg2) - 1);
31 			exit(1);
32 		}
33 #endif
34 	}
35 };
36 
37 Test test;
38