xref: /original-bsd/lib/libc/stdlib/exit.c (revision 31e799e3)
1 /*-
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)exit.c	5.3 (Berkeley) 01/20/91";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include "atexit.h"
13 
14 void (*__cleanup)();
15 
16 /*
17  * Exit, flushing stdio buffers if necessary.
18  */
19 exit(status)
20 	int status;
21 {
22 	register struct atexit *p;
23 	register int n;
24 
25 	for (p = __atexit; p; p = p->next)
26 		for (n = p->ind; --n >= 0;)
27 			(*p->fns[n])();
28 	if (__cleanup)
29 		(*__cleanup)();
30 	_exit(status);
31 }
32