Back to index

glibc  2.9
Functions
exit.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sysdep.h>
#include "exit.h"
#include "set-hooks.h"

Go to the source code of this file.

Functions

void exit (int status)

Function Documentation

void exit ( int  status)

Definition at line 33 of file exit.c.

{
  /* We do it this way to handle recursive calls to exit () made by
     the functions registered with `atexit' and `on_exit'. We call
     everyone on the list and use the status value in the last
     exit (). */
  while (__exit_funcs != NULL)
    {
      struct exit_function_list *old;

      while (__exit_funcs->idx > 0)
       {
         const struct exit_function *const f =
           &__exit_funcs->fns[--__exit_funcs->idx];
         switch (f->flavor)
           {
             void (*atfct) (void);
             void (*onfct) (int status, void *arg);
             void (*cxafct) (void *arg, int status);

           case ef_free:
           case ef_us:
             break;
           case ef_on:
             onfct = f->func.on.fn;
#ifdef PTR_DEMANGLE
             PTR_DEMANGLE (onfct);
#endif
             onfct (status, f->func.on.arg);
             break;
           case ef_at:
             atfct = f->func.at;
#ifdef PTR_DEMANGLE
             PTR_DEMANGLE (atfct);
#endif
             atfct ();
             break;
           case ef_cxa:
             cxafct = f->func.cxa.fn;
#ifdef PTR_DEMANGLE
             PTR_DEMANGLE (cxafct);
#endif
             cxafct (f->func.cxa.arg, status);
             break;
           }
       }

      old = __exit_funcs;
      __exit_funcs = __exit_funcs->next;
      if (__exit_funcs != NULL)
       /* Don't free the last element in the chain, this is the statically
          allocate element.  */
       free (old);
    }

  RUN_HOOK (__libc_atexit, ());

  _exit (status);
}