Update contrib.
3 * Portions Copyright (c) 1990-2006 Nokia Corporation and/or its subsidiary(-ies).
8 * Copyright (c) 1990 Regents of the University of California.
11 * %sccs.include.redist.c%
16 <<atexit>>---request execution of functions at program exit
23 int atexit(void (*<[function]>)(void);
27 int atexit((<[function]>)
28 void (*<[function]>)();
31 You can use <<atexit>> to enroll functions in a list of functions that
32 will be called when your program terminates normally. The argument is
33 a pointer to a user-defined function (which must not require arguments and
34 must not return a result).
36 The functions are kept in a LIFO stack; that is, the last function
37 enrolled by <<atexit>> will be the first to execute when your program
40 There is no built-in limit to the number of functions you can enroll
41 in this list; however, after every group of 32 functions is enrolled,
42 <<atexit>> will call <<malloc>> to get space for the next part of the
43 list. The initial list of 32 functions is statically allocated, so
44 you can always count on at least that many slots available.
47 <<atexit>> returns <<0>> if it succeeds in enrolling your function,
48 <<-1>> if it fails (possible only if no space was available for
49 <<malloc>> to extend the list of functions or the library globals could not
53 <<atexit>> is required by the ANSI standard, which also specifies that
54 implementations must support enrolling at least 32 functions.
56 Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
57 <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
65 * Register a function to be performed at exit.
66 * NB. MSVC 5.0 has a built-in prototype for atexit, so we have to use a #define
67 * to map the name atexit to _epoc32_atexit
71 @return On Success, returns 0.
72 On Failure, returns -1.
76 _epoc32_atexit (void (*fn)(void))
78 register struct _atexit *p;
79 struct _reent *rp = _REENT2;
81 return -1; // Memory for library globals is not allocated (errno not set).
83 if ((p = rp->_atexit) == NULL)
84 rp->_atexit = p = &rp->_atexit0;
85 if (p->_ind >= _ATEXIT_SIZE)
87 if ((p = (struct _atexit *) malloc (sizeof *p)) == NULL)
90 p->_next = rp->_atexit;
93 p->_fns[p->_ind++] = fn;
98 _atexit_processing_r (struct _reent *rp)
100 register struct _atexit *p;
103 for (p = rp->_atexit; p; p = p->_next)
104 for (n = p->_ind; --n >= 0;)
107 (*rp->__cleanup) (rp);