home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / exit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-27  |  1.7 KB  |  65 lines

  1. /* 
  2.  * exit.c --
  3.  *
  4.  *    This file contains the source code for the "exit" library
  5.  *    procedure.
  6.  *
  7.  * Copyright 1988 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifndef lint
  18. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/exit.c,v 1.9 92/03/27 13:41:59 rab Exp $ SPRITE (Berkeley)";
  19. #endif not lint
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <sprite.h>
  24. #include <proc.h>
  25.  
  26. /*
  27.  * Variables shared with atexit.c, and on_exit.c:
  28.  */
  29.  
  30. void (*_exitHandlers[32])();        /* Function table. */
  31. int _exitNumHandlers = 0;        /* Number of functions currently
  32.                      * registered in table. */
  33. long _exitHandlerArgs[32];        /* Arguments to pass to functions. */
  34. int _exitTableSize = 32;        /* Number of entries in table. */
  35.  
  36. /*
  37.  *----------------------------------------------------------------------
  38.  *
  39.  * exit --
  40.  *
  41.  *    Terminate the process.
  42.  *
  43.  * Results:
  44.  *    Never returns.
  45.  *
  46.  * Side effects:
  47.  *    Any procedures registered by calls to "atexit" are invoked,
  48.  *    and any open I/O streams are flushed and closed.
  49.  *
  50.  *----------------------------------------------------------------------
  51.  */
  52.  
  53. int
  54. exit(status)
  55.     int status;            /* Status to return to parent process.  0 is
  56.                  * the normal value for "success". */
  57. {
  58.     while (_exitNumHandlers > 0) {
  59.     _exitNumHandlers -= 1;
  60.     (*_exitHandlers[_exitNumHandlers])(_exitHandlerArgs[_exitNumHandlers]);
  61.     }
  62.     _cleanup();
  63.     _exit(status);
  64. }
  65.