xref: /onnv-gate/usr/src/lib/libast/common/vmalloc/vmexit.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 #if defined(_UWIN)
234887Schin 
_STUB_vmexit()244887Schin void _STUB_vmexit(){}
254887Schin 
264887Schin #else
274887Schin 
284887Schin #include	"vmhdr.h"
294887Schin 
304887Schin /*
314887Schin **	Any required functions for process exiting.
324887Schin **	Written by Kiem-Phong Vo, kpv@research.att.com (05/25/93).
334887Schin */
344887Schin #if _PACKAGE_ast || _lib_atexit
354887Schin 
_STUB_vmexit()364887Schin void _STUB_vmexit(){}
374887Schin 
384887Schin #else
394887Schin 
404887Schin #if _lib_onexit
414887Schin 
424887Schin #if __STD_C
atexit(void (* exitf)(void))434887Schin int atexit(void (*exitf)(void))
444887Schin #else
454887Schin int atexit(exitf)
464887Schin void	(*exitf)();
474887Schin #endif
484887Schin {
494887Schin 	return onexit(exitf);
504887Schin }
514887Schin 
524887Schin #else /*!_lib_onexit*/
534887Schin 
544887Schin typedef struct _exit_s
554887Schin {	struct _exit_s*	next;
564887Schin 	void(*		exitf)_ARG_((void));
574887Schin } Exit_t;
584887Schin static Exit_t*	Exit;
594887Schin 
604887Schin #if __STD_C
atexit(void (* exitf)(void))614887Schin atexit(void (*exitf)(void))
624887Schin #else
634887Schin atexit(exitf)
644887Schin void	(*exitf)();
654887Schin #endif
664887Schin {	Exit_t*	e;
674887Schin 
684887Schin 	if(!(e = (Exit_t*)malloc(sizeof(Exit_t))) )
694887Schin 		return -1;
704887Schin 	e->exitf = exitf;
714887Schin 	e->next = Exit;
724887Schin 	Exit = e;
734887Schin 	return 0;
744887Schin }
754887Schin 
764887Schin #if __STD_C
exit(int type)774887Schin void exit(int type)
784887Schin #else
794887Schin void exit(type)
804887Schin int	type;
814887Schin #endif
824887Schin {
834887Schin 	Exit_t*	e;
844887Schin 
854887Schin 	for(e = Exit; e; e = e->next)
864887Schin 		(*e->exitf)();
874887Schin 
884887Schin #if _exit_cleanup
894887Schin 	_cleanup();
904887Schin #endif
914887Schin 
924887Schin 	_exit(type);
934887Schin 	return type;
944887Schin }
954887Schin 
964887Schin #endif	/* _lib_onexit || _lib_on_exit */
974887Schin 
984887Schin #endif /*!PACKAGE_ast*/
994887Schin 
1004887Schin #endif
101