home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / libnix-0.8-src.lha / libnix-0.8 / sources / nix / stdlib / atexit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-12  |  663 b   |  36 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <errno.h>
  4. #include <stabs.h>
  5.  
  6. struct atexitnode
  7.   struct atexitnode *next;
  8.   void (*func)(void);
  9. };
  10.  
  11. static struct atexitnode *__funclist=NULL; /* List of functions to call at exit */
  12.  
  13. int atexit(void (*func)(void))
  14.   struct atexitnode *node;
  15.   if((node=(struct atexitnode *)malloc(sizeof(struct atexitnode)))==NULL)
  16.   { errno=ENOMEM;
  17.     return -1; }
  18.   else
  19.   { node->next=__funclist;
  20.     node->func=func;
  21.     __funclist=node;
  22.     return 0; }
  23. }
  24.  
  25. void __exitatexit(void)
  26. {
  27.   struct atexitnode *thisf=__funclist;
  28.   while(thisf!=NULL)
  29.   { (*thisf->func)();
  30.     thisf=thisf->next; }
  31. }
  32.  
  33. ADD2EXIT(__exitatexit,0);
  34.