2 * Copyright (c) 1990 Regents of the University of California.
5 * %sccs.include.redist.c%
10 <<atexit>>---request execution of functions at program exit
17 int atexit (void (*<[function]>)(void));
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).
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
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.
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).
41 <<atexit>> is required by the ANSI standard, which also specifies that
42 implementations must support enrolling at least 32 functions.
44 Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
45 <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
52 * Register a function to be performed at exit.
56 atexit (void (*fn
) (void))
58 return __register_exitproc (__et_atexit
, fn
, NULL
, NULL
);