source: trunk/libs/newlib/src/newlib/libc/stdlib/on_exit.c @ 577

Last change on this file since 577 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.1 KB
Line 
1/*
2 * Copyright (c) 1990 Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 *
7 * This function is a modified version of atexit.c
8 */
9
10/*
11FUNCTION
12<<on_exit>>---request execution of function with argument at program exit
13
14INDEX
15        on_exit
16
17SYNOPSIS
18        #include <stdlib.h>
19        int on_exit (void (*<[function]>)(int, void *), void *<[arg]>);
20
21DESCRIPTION
22You can use <<on_exit>> to enroll functions in a list of functions that
23will be called when your program terminates normally.  The argument is
24a pointer to a user-defined function which takes two arguments.  The
25first is the status code passed to exit and the second argument is of type
26pointer to void.  The function must not return a result.  The value
27of <[arg]> is registered and passed as the argument to <[function]>.
28
29The functions are kept in a LIFO stack; that is, the last function
30enrolled by <<atexit>> or <<on_exit>> will be the first to execute when
31your program exits.  You can intermix functions using <<atexit>> and
32<<on_exit>>.
33
34There is no built-in limit to the number of functions you can enroll
35in 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
37of the list.   The initial list of 32 functions is statically allocated, so
38you can always count on at least that many slots available.
39
40RETURNS
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).
44
45PORTABILITY
46<<on_exit>> is a non-standard glibc extension
47
48Supporting OS subroutines required: None
49*/
50
51#include <stddef.h>
52#include <stdlib.h>
53#include "atexit.h"
54
55#ifdef _REENT_SMALL
56
57#include "on_exit_args.h"
58
59/* force linking of static instance of _on_exit_args */
60const void * const __on_exit_dummy = &__on_exit_args;
61
62#endif  /* def _REENT_SMALL */
63
64/*
65 * Register a function to be performed at exit.
66 */
67
68int
69on_exit (void (*fn) (int, void *),
70        void *arg)
71{
72  return __register_exitproc (__et_onexit, (void (*)(void)) fn, arg, NULL);
73}
Note: See TracBrowser for help on using the repository browser.