2 * Copyright (c) 1990 Regents of the University of California.
5 * %sccs.include.redist.c%
7 * This function is a modified version of atexit.c
12 <<on_exit>>---request execution of function with argument at program exit
19 int on_exit (void (*<[function]>)(int, void *), void *<[arg]>);
22 You can use <<on_exit>> to enroll functions in a list of functions that
23 will be called when your program terminates normally. The argument is
24 a pointer to a user-defined function which takes two arguments. The
25 first is the status code passed to exit and the second argument is of type
26 pointer to void. The function must not return a result. The value
27 of <[arg]> is registered and passed as the argument to <[function]>.
29 The functions are kept in a LIFO stack; that is, the last function
30 enrolled by <<atexit>> or <<on_exit>> will be the first to execute when
31 your program exits. You can intermix functions using <<atexit>> and
34 There is no built-in limit to the number of functions you can enroll
35 in this list; however, after every group of 32 functions is enrolled,
36 <<atexit>>/<<on_exit>> will call <<malloc>> to get space for the next part
37 of the list. The initial list of 32 functions is statically allocated, so
38 you can always count on at least that many slots available.
41 <<on_exit>> returns <<0>> if it succeeds in enrolling your function,
42 <<-1>> if it fails (possible only if no space was available for
43 <<malloc>> to extend the list of functions).
46 <<on_exit>> is a non-standard glibc extension
48 Supporting OS subroutines required: None
57 #include "on_exit_args.h"
59 /* force linking of static instance of _on_exit_args */
60 const void * const __on_exit_dummy
= &__on_exit_args
;
62 #endif /* def _REENT_SMALL */
65 * Register a function to be performed at exit.
69 on_exit (void (*fn
) (int, void *),
72 return __register_exitproc (__et_onexit
, (void (*)(void)) fn
, arg
, NULL
);