xref: /illumos-gate/usr/src/lib/gss_mechs/mech_krb5/krb5/krb/cleanup.h (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
17c478bd9Sstevel@tonic-gate #ifndef KRB5_CLEANUP
27c478bd9Sstevel@tonic-gate #define KRB5_CLEANUP
37c478bd9Sstevel@tonic-gate 
47c478bd9Sstevel@tonic-gate struct cleanup {
57c478bd9Sstevel@tonic-gate     void 		* arg;
6*505d05c7Sgtb     void		(*func)(void *);
77c478bd9Sstevel@tonic-gate };
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate #define CLEANUP_INIT(x)							\
107c478bd9Sstevel@tonic-gate     struct cleanup cleanup_data[x];					\
117c478bd9Sstevel@tonic-gate     int cleanup_count = 0;
127c478bd9Sstevel@tonic-gate 
137c478bd9Sstevel@tonic-gate #define CLEANUP_PUSH(x, y)						\
147c478bd9Sstevel@tonic-gate     cleanup_data[cleanup_count].arg = x;				\
157c478bd9Sstevel@tonic-gate     cleanup_data[cleanup_count].func = y;				\
167c478bd9Sstevel@tonic-gate     cleanup_count++;
177c478bd9Sstevel@tonic-gate 
187c478bd9Sstevel@tonic-gate #define CLEANUP_POP(x)							\
197c478bd9Sstevel@tonic-gate     if ((--cleanup_count) && x && (cleanup_data[cleanup_count].func)) 	\
207c478bd9Sstevel@tonic-gate 	cleanup_data[cleanup_count].func(cleanup_data[cleanup_count].arg);
217c478bd9Sstevel@tonic-gate 
227c478bd9Sstevel@tonic-gate #define CLEANUP_DONE()							\
237c478bd9Sstevel@tonic-gate     while(cleanup_count--) 						\
247c478bd9Sstevel@tonic-gate 	if (cleanup_data[cleanup_count].func)  				\
257c478bd9Sstevel@tonic-gate 	    cleanup_data[cleanup_count].func(cleanup_data[cleanup_count].arg);
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #endif
29