home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / ansi / stdlib / exit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-23  |  934 b   |  39 lines

  1. /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
  2. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  3. #include <libc/stubs.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include <fcntl.h>
  7. #include <dos.h>
  8. #include <io.h>
  9. #include <libc/atexit.h>
  10.  
  11. struct __atexit *__atexit_ptr = 0;
  12.  
  13. void (*__stdio_cleanup_hook)(void);
  14.  
  15. typedef void (*FUNC)(void);
  16. extern FUNC djgpp_first_dtor[] __asm__("djgpp_first_dtor");
  17. extern FUNC djgpp_last_dtor[] __asm__("djgpp_last_dtor");
  18.  
  19. void
  20. exit(int status)
  21. {
  22.   int i;
  23.   struct __atexit *a = __atexit_ptr;
  24.   __atexit_ptr = 0; /* to prevent infinite loops */
  25.   while (a)
  26.   {
  27.     (a->__function)();
  28.     a = a->__next;
  29.   }
  30.   if (__stdio_cleanup_hook)
  31.     __stdio_cleanup_hook();
  32.   for (i=0; i<djgpp_last_dtor-djgpp_first_dtor; i++)
  33.     djgpp_first_dtor[i]();
  34.  
  35.   /* in case the program set it this way */
  36.   setmode(0, O_TEXT);
  37.   _exit(status);
  38. }
  39.