xref: /illumos-gate/usr/src/lib/gss_mechs/mech_krb5/krb5/krb/cleanup.h (revision 2b24ab6b3865caeede9eeb9db6b83e1d89dcd1ea)
1 #pragma ident	"%Z%%M%	%I%	%E% SMI"
2 
3 #ifndef KRB5_CLEANUP
4 #define KRB5_CLEANUP
5 
6 struct cleanup {
7     void 		* arg;
8     void		(*func)(void *);
9 };
10 
11 #define CLEANUP_INIT(x)							\
12     struct cleanup cleanup_data[x];					\
13     int cleanup_count = 0;
14 
15 #define CLEANUP_PUSH(x, y)						\
16     cleanup_data[cleanup_count].arg = x;				\
17     cleanup_data[cleanup_count].func = y;				\
18     cleanup_count++;
19 
20 #define CLEANUP_POP(x)							\
21     if ((--cleanup_count) && x && (cleanup_data[cleanup_count].func)) 	\
22 	cleanup_data[cleanup_count].func(cleanup_data[cleanup_count].arg);
23 
24 #define CLEANUP_DONE()							\
25     while(cleanup_count--) 						\
26 	if (cleanup_data[cleanup_count].func)  				\
27 	    cleanup_data[cleanup_count].func(cleanup_data[cleanup_count].arg);
28 
29 
30 #endif
31