xref: /original-bsd/lib/libc/stdlib/exit.c (revision 6884d44a)
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.4 (Berkeley) 02/23/91";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include "atexit.h"
15 
16 void (*__cleanup)();
17 
18 /*
19  * Exit, flushing stdio buffers if necessary.
20  */
21 void
22 exit(status)
23 	int status;
24 {
25 	register struct atexit *p;
26 	register int n;
27 
28 	for (p = __atexit; p; p = p->next)
29 		for (n = p->ind; --n >= 0;)
30 			(*p->fns[n])();
31 	if (__cleanup)
32 		(*__cleanup)();
33 	_exit(status);
34 }
35