exit.c 667 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Header$ */
  6. #include <stdlib.h>
  7. #define NEXITS 32
  8. static void (*functab[NEXITS])(void);
  9. static int funccnt = 0;
  10. extern void _cleanup(void);
  11. extern void _exit(int);
  12. static void
  13. _calls(void)
  14. {
  15. register int i = funccnt;
  16. /* "Called in reversed order of their registration" */
  17. while (--i >= 0)
  18. (*functab[i])();
  19. }
  20. void
  21. exit(int status)
  22. {
  23. _calls();
  24. _cleanup() ;
  25. _exit(status) ;
  26. }
  27. int
  28. atexit(void (*func)(void))
  29. {
  30. if (funccnt >= NEXITS)
  31. return 1;
  32. functab[funccnt++] = func;
  33. return 0;
  34. }