home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / MM1 / SOUNDUTILS / tracker.4.6.lzh / TRACKER4.6 / autoinit.c < prev    next >
Text File  |  1994-11-24  |  965b  |  60 lines

  1. /* autoinit.c 
  2.     vi:ts=3 sw=3:
  3.  */
  4.  
  5. /* $Id: autoinit.c,v 4.4 1994/11/15 16:11:01 espie Exp espie $ 
  6.  * $Log: autoinit.c,v $
  7.  * Revision 4.4  1994/11/15  16:11:01  espie
  8.  * *** empty log message ***
  9.  *
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14.  
  15. #include "defs.h"
  16. #include "extern.h"
  17.  
  18. ID("$Id: autoinit.c,v 4.4 1994/11/15 16:11:01 espie Exp espie $")
  19.  
  20. LOCAL struct clist
  21.     {
  22.     struct clist *next;
  23.     void (*func) P((void));
  24.     } *list = 0;
  25.     
  26.  
  27. void at_end(cleanup)
  28. void (*cleanup) P((void));
  29.     {
  30. #ifdef USE_AT_EXIT
  31.     atexit(cleanup);
  32. #else
  33.     struct clist *new;
  34.     new = (struct clist *)malloc(sizeof(struct clist));
  35.     if (!new)
  36.         {
  37.         (*cleanup)();
  38.         end_all("Allocation problem");
  39.         }
  40.     new->next = list;
  41.     new->func = cleanup;
  42.     list = new;
  43. #endif
  44.     }
  45.     
  46. void end_all(s)
  47. char *s;
  48.     {
  49. #ifndef USE_AT_EXIT
  50.     struct clist *p;
  51. #endif
  52.     if (s)
  53.         notice(s);
  54. #ifndef USE_AT_EXIT
  55.     for (p = list; p; p = p->next)
  56.         (p->func)();            /* don't bother freeing (malloc) */
  57. #endif
  58.     exit(s ? 10 : 0);
  59.     }
  60.