1 /*
2  * Copyright (c) 1990 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 /*
9 FUNCTION
10 <<atexit>>---request execution of functions at program exit
11 
12 INDEX
13 	atexit
14 
15 SYNOPSIS
16 	#include <stdlib.h>
17 	int atexit (void (*<[function]>)(void));
18 
19 DESCRIPTION
20 You can use <<atexit>> to enroll functions in a list of functions that
21 will be called when your program terminates normally.  The argument is
22 a pointer to a user-defined function (which must not require arguments and
23 must not return a result).
24 
25 The functions are kept in a LIFO stack; that is, the last function
26 enrolled by <<atexit>> will be the first to execute when your program
27 exits.
28 
29 There is no built-in limit to the number of functions you can enroll
30 in this list; however, after every group of 32 functions is enrolled,
31 <<atexit>> will call <<malloc>> to get space for the next part of the
32 list.   The initial list of 32 functions is statically allocated, so
33 you can always count on at least that many slots available.
34 
35 RETURNS
36 <<atexit>> returns <<0>> if it succeeds in enrolling your function,
37 <<-1>> if it fails (possible only if no space was available for
38 <<malloc>> to extend the list of functions).
39 
40 PORTABILITY
41 <<atexit>> is required by the ANSI standard, which also specifies that
42 implementations must support enrolling at least 32 functions.
43 
44 Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
45 <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
46 */
47 
48 #include <stdlib.h>
49 #include "atexit.h"
50 
51 /*
52  * Register a function to be performed at exit.
53  */
54 
55 int
atexit(void (* fn)(void))56 atexit (void (*fn) (void))
57 {
58   return __register_exitproc (__et_atexit, fn, NULL, NULL);
59 }
60