vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

atexit.c (481B)


      1 
      2 #include <stdlib.h>
      3 #include <unistd.h>
      4 
      5 #include "private.h"
      6 
      7 
      8 typedef void exitfunc(void);
      9 
     10 #define MAXEXITFUNCS	32	// POSIX's standard minimum
     11 
     12 static exitfunc *exitfuncs[MAXEXITFUNCS];
     13 static int nexitfuncs;
     14 
     15 
     16 static void callfuncs()
     17 {
     18 	// Call all exit handlers
     19 	for (int i = nexitfuncs-1; i >= 0; i--)
     20 		exitfuncs[i]();
     21 }
     22 
     23 int atexit(exitfunc *func)
     24 {
     25 	if (nexitfuncs == MAXEXITFUNCS)
     26 		return -1;
     27 
     28 	__exit_atexit = callfuncs;
     29 	exitfuncs[nexitfuncs++] = func;
     30 	return 0;
     31 }
     32