summaryrefslogtreecommitdiff
path: root/common/compat.c
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2006-01-28 02:52:38 +0000
committerStef Walter <stef@memberwebs.com>2006-01-28 02:52:38 +0000
commitc127605b17195e34a73b7a8c8d401769cdf60795 (patch)
tree138853c9c6869d7d76413dbbb3763d7a42423aa4 /common/compat.c
parentfbfb057e8bed90f73850d8e871e4d70e8fa705ce (diff)
Move config parser stuff into common directory for use by other binaries.
Diffstat (limited to 'common/compat.c')
-rw-r--r--common/compat.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/common/compat.c b/common/compat.c
index 9d2f53f..0c6c833 100644
--- a/common/compat.c
+++ b/common/compat.c
@@ -179,3 +179,54 @@ strlcat(char* dst, const char* src, size_t siz)
}
#endif /* HAVE_STRLCAT */
+
+#ifndef HAVE_ATEXITV
+
+typedef void (*voidfunc)(void*);
+typedef struct _exit_stack
+{
+ voidfunc func;
+ void* data;
+
+ /* We have a list of these beauties */
+ struct _exit_stack* next;
+}
+exit_stack;
+
+/* Our exit stack */
+static exit_stack* atexits = NULL;
+static int atexit_registered = 0;
+
+static void
+atexit_do_stack(void)
+{
+ exit_stack* next;
+ for(; atexits; atexits = next)
+ {
+ next = atexits->next;
+ (atexits->func)(atexits->data);
+ free(atexits);
+ }
+}
+
+void
+atexitv(voidfunc func, void* data)
+{
+ exit_stack* ae;
+
+ ASSERT(func);
+
+ ae = (exit_stack*)calloc(1, sizeof(exit_stack));
+ if(ae)
+ {
+ ae->func = func;
+ ae->data = data;
+ ae->next = atexits;
+ atexits = ae;
+
+ if(!atexit_registered)
+ atexit(atexit_do_stack);
+ }
+}
+
+#endif /* HAVE_ATEXITV */