xref: /csrg-svn/lib/libc/stdlib/exit.c (revision 46599)
146050Sbostic /*-
246050Sbostic  * Copyright (c) 1990 The Regents of the University of California.
346050Sbostic  * All rights reserved.
446050Sbostic  *
546050Sbostic  * %sccs.include.redist.c%
646050Sbostic  */
746050Sbostic 
826641Sdonn #if defined(LIBC_SCCS) && !defined(lint)
9*46599Sdonn static char sccsid[] = "@(#)exit.c	5.4 (Berkeley) 02/23/91";
1046050Sbostic #endif /* LIBC_SCCS and not lint */
1113264Sroot 
12*46599Sdonn #include <stdlib.h>
13*46599Sdonn #include <unistd.h>
1446050Sbostic #include "atexit.h"
1546050Sbostic 
1646050Sbostic void (*__cleanup)();
1746050Sbostic 
1846050Sbostic /*
1946050Sbostic  * Exit, flushing stdio buffers if necessary.
2046050Sbostic  */
21*46599Sdonn void
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