atexit Function (tigcc.a)

stdlib.h

short atexit (atexit_t func);

Registers a termination function.

atexit registers the function pointed to by func as an exit function. Upon normal termination of the program (including termination using the exit function), func is called just before returning to the TIOS. Each call to atexit registers another exit function. The number of function which can be registered depends on the current number of free handles. All registered termination functions are executed on a last-in, first-out basis (the last function registered is the first to be executed). atexit returns 0 on success and nonzero on failure (no space left to register the function).

Note: Termination functions are not called on abnormal termination of the program (i.e. if an error is thrown from the program).

atexit does not work with enter_ghost_space. However, if a program is already executed in the ghost space (because of ExePack compression or because it has been called from a launcher), there should not be any problems.


Uses: HeapAllocPtr, HeapFreePtr, realloc