home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / CLIBSRC1.ZIP / ATEXIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.7 KB  |  55 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - atexit.c
  3.  *
  4.  * function(s)
  5.  *        atexit - registers termination function
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #include <stdlib.h>
  18.  
  19. #define MAX_ATEXIT      32
  20.  
  21. int             _atexitcnt = 0;         /* count of atexit functions */
  22. atexit_t        _atexittbl[MAX_ATEXIT]; /* array of atexit function pointers */
  23.  
  24.  
  25. /*-------------------------------------------------------------------------*
  26.  
  27. Name            atexit - registers termination function
  28.  
  29. Usage           #include <stdlib.h>
  30.                 int atexit(atexit_t func);
  31.  
  32. Prototype in    stdlib.h
  33.  
  34. Description     atexit registers provided to by func as an "exit function".
  35.                 Upon normal  termination of the  program, exit calls  *func
  36.                 (without  args)  just  before  returning  to  the operating
  37.                 system.
  38.  
  39.                 Each call to atexit registers  another exit function; up to
  40.                 32  functions can  be registered  and they  are executed on
  41.                 last in, first out basis.
  42.  
  43. Return value    atexit returns 0 on success and non-zero on failure(no space
  44.                 left to register the function)
  45.  
  46. *---------------------------------------------------------------------------*/
  47. int atexit(atexit_t func)
  48. {
  49.         if (_atexitcnt == MAX_ATEXIT)
  50.                 return(1);
  51.         _atexittbl[_atexitcnt++] = func;
  52.         return(0);
  53. }
  54.  
  55.