xref: /onnv-gate/usr/src/lib/libast/common/cdt/dtclose.c (revision 12068:08a39a083754)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
184887Schin *                  David Korn <dgk@research.att.com>                   *
194887Schin *                   Phong Vo <kpv@research.att.com>                    *
204887Schin *                                                                      *
214887Schin ***********************************************************************/
224887Schin #include	"dthdr.h"
234887Schin 
244887Schin /*	Close a dictionary
254887Schin **
264887Schin **	Written by Kiem-Phong Vo (05/25/96)
274887Schin */
284887Schin #if __STD_C
dtclose(reg Dt_t * dt)294887Schin int dtclose(reg Dt_t* dt)
304887Schin #else
314887Schin int dtclose(dt)
324887Schin reg Dt_t*	dt;
334887Schin #endif
344887Schin {
354887Schin 	Dtdisc_t	*disc;
364887Schin 	int		ev = 0;
374887Schin 
384887Schin 	if(!dt || dt->nview > 0 ) /* can't close if being viewed */
394887Schin 		return -1;
404887Schin 
414887Schin 	/* announce the close event to see if we should continue */
424887Schin 	disc = dt->disc;
434887Schin 	if(disc->eventf &&
444887Schin 	   (ev = (*disc->eventf)(dt,DT_CLOSE,NIL(Void_t*),disc)) < 0)
454887Schin 		return -1;
464887Schin 
474887Schin 	if(dt->view)	/* turn off viewing */
484887Schin 		dtview(dt,NIL(Dt_t*));
494887Schin 
504887Schin 	if(ev == 0) /* release all allocated data */
514887Schin 	{	(void)(*(dt->meth->searchf))(dt,NIL(Void_t*),DT_CLEAR);
524887Schin 		if(dtsize(dt) > 0)
534887Schin 			return -1;
544887Schin 
554887Schin 		if(dt->data->ntab > 0)
564887Schin 			(*dt->memoryf)(dt,(Void_t*)dt->data->htab,0,disc);
574887Schin 		(*dt->memoryf)(dt,(Void_t*)dt->data,0,disc);
584887Schin 	}
594887Schin 
604887Schin 	if(dt->type == DT_MALLOC)
614887Schin 		free((Void_t*)dt);
624887Schin 	else if(ev == 0 && dt->type == DT_MEMORYF)
634887Schin 		(*dt->memoryf)(dt, (Void_t*)dt, 0, disc);
644887Schin 
654887Schin 	if(disc->eventf)
664887Schin 		(void)(*disc->eventf)(dt, DT_ENDCLOSE, NIL(Void_t*), disc);
674887Schin 
684887Schin 	return 0;
694887Schin }
70