17c478bdstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
27c478bdstevel@tonic-gate
37c478bdstevel@tonic-gate#ifndef KRB5_CLEANUP
47c478bdstevel@tonic-gate#define KRB5_CLEANUP
57c478bdstevel@tonic-gate
67c478bdstevel@tonic-gatestruct cleanup {
77c478bdstevel@tonic-gate    void 		* arg;
8505d05cgtb    void		(*func)(void *);
97c478bdstevel@tonic-gate};
107c478bdstevel@tonic-gate
117c478bdstevel@tonic-gate#define CLEANUP_INIT(x)							\
127c478bdstevel@tonic-gate    struct cleanup cleanup_data[x];					\
137c478bdstevel@tonic-gate    int cleanup_count = 0;
147c478bdstevel@tonic-gate
157c478bdstevel@tonic-gate#define CLEANUP_PUSH(x, y)						\
167c478bdstevel@tonic-gate    cleanup_data[cleanup_count].arg = x;				\
177c478bdstevel@tonic-gate    cleanup_data[cleanup_count].func = y;				\
187c478bdstevel@tonic-gate    cleanup_count++;
197c478bdstevel@tonic-gate
207c478bdstevel@tonic-gate#define CLEANUP_POP(x)							\
217c478bdstevel@tonic-gate    if ((--cleanup_count) && x && (cleanup_data[cleanup_count].func)) 	\
227c478bdstevel@tonic-gate	cleanup_data[cleanup_count].func(cleanup_data[cleanup_count].arg);
237c478bdstevel@tonic-gate
247c478bdstevel@tonic-gate#define CLEANUP_DONE()							\
257c478bdstevel@tonic-gate    while(cleanup_count--) 						\
267c478bdstevel@tonic-gate	if (cleanup_data[cleanup_count].func)  				\
277c478bdstevel@tonic-gate	    cleanup_data[cleanup_count].func(cleanup_data[cleanup_count].arg);
287c478bdstevel@tonic-gate
297c478bdstevel@tonic-gate
307c478bdstevel@tonic-gate#endif
31