xref: /onnv-gate/usr/src/lib/gss_mechs/mech_krb5/krb5/krb/cleanup.h (revision 781:57319a72b15f)
10Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
20Sstevel@tonic-gate 
30Sstevel@tonic-gate #ifndef KRB5_CLEANUP
40Sstevel@tonic-gate #define KRB5_CLEANUP
50Sstevel@tonic-gate 
60Sstevel@tonic-gate struct cleanup {
70Sstevel@tonic-gate     void 		* arg;
8*781Sgtb     void		(*func)(void *);
90Sstevel@tonic-gate };
100Sstevel@tonic-gate 
110Sstevel@tonic-gate #define CLEANUP_INIT(x)							\
120Sstevel@tonic-gate     struct cleanup cleanup_data[x];					\
130Sstevel@tonic-gate     int cleanup_count = 0;
140Sstevel@tonic-gate 
150Sstevel@tonic-gate #define CLEANUP_PUSH(x, y)						\
160Sstevel@tonic-gate     cleanup_data[cleanup_count].arg = x;				\
170Sstevel@tonic-gate     cleanup_data[cleanup_count].func = y;				\
180Sstevel@tonic-gate     cleanup_count++;
190Sstevel@tonic-gate 
200Sstevel@tonic-gate #define CLEANUP_POP(x)							\
210Sstevel@tonic-gate     if ((--cleanup_count) && x && (cleanup_data[cleanup_count].func)) 	\
220Sstevel@tonic-gate 	cleanup_data[cleanup_count].func(cleanup_data[cleanup_count].arg);
230Sstevel@tonic-gate 
240Sstevel@tonic-gate #define CLEANUP_DONE()							\
250Sstevel@tonic-gate     while(cleanup_count--) 						\
260Sstevel@tonic-gate 	if (cleanup_data[cleanup_count].func)  				\
270Sstevel@tonic-gate 	    cleanup_data[cleanup_count].func(cleanup_data[cleanup_count].arg);
280Sstevel@tonic-gate 
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #endif
31