xref: /csrg-svn/lib/libc/stdlib/exit.c (revision 61180)
146050Sbostic /*-
2*61180Sbostic  * Copyright (c) 1990, 1993
3*61180Sbostic  *	The Regents of the University of California.  All rights reserved.
446050Sbostic  *
546050Sbostic  * %sccs.include.redist.c%
646050Sbostic  */
746050Sbostic 
826641Sdonn #if defined(LIBC_SCCS) && !defined(lint)
9*61180Sbostic static char sccsid[] = "@(#)exit.c	8.1 (Berkeley) 06/04/93";
1046050Sbostic #endif /* LIBC_SCCS and not lint */
1113264Sroot 
1246599Sdonn #include <stdlib.h>
1346599Sdonn #include <unistd.h>
1446050Sbostic #include "atexit.h"
1546050Sbostic 
1646050Sbostic void (*__cleanup)();
1746050Sbostic 
1846050Sbostic /*
1946050Sbostic  * Exit, flushing stdio buffers if necessary.
2046050Sbostic  */
2146599Sdonn void
exit(status)2246050Sbostic exit(status)
2346050Sbostic 	int status;
2413264Sroot {
2546050Sbostic 	register struct atexit *p;
2646050Sbostic 	register int n;
2713264Sroot 
2846050Sbostic 	for (p = __atexit; p; p = p->next)
2946050Sbostic 		for (n = p->ind; --n >= 0;)
3046050Sbostic 			(*p->fns[n])();
3146050Sbostic 	if (__cleanup)
3246050Sbostic 		(*__cleanup)();
3346050Sbostic 	_exit(status);
3413264Sroot }
35