home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 1.ddi / CLIB1.ZIP / ATEXIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  1.9 KB  |  57 lines

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