summaryrefslogtreecommitdiff
path: root/plugins/dumb/dumb-kode54/src/core/atexit.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/dumb/dumb-kode54/src/core/atexit.c')
-rw-r--r--plugins/dumb/dumb-kode54/src/core/atexit.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/plugins/dumb/dumb-kode54/src/core/atexit.c b/plugins/dumb/dumb-kode54/src/core/atexit.c
new file mode 100644
index 00000000..64814efd
--- /dev/null
+++ b/plugins/dumb/dumb-kode54/src/core/atexit.c
@@ -0,0 +1,71 @@
+/* _______ ____ __ ___ ___
+ * \ _ \ \ / \ / \ \ / / ' ' '
+ * | | \ \ | | || | \/ | . .
+ * | | | | | | || ||\ /| |
+ * | | | | | | || || \/ | | ' ' '
+ * | | | | | | || || | | . .
+ * | |_/ / \ \__// || | |
+ * /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque
+ * / \
+ * / . \
+ * atexit.c - Library Clean-up Management. / / \ \
+ * | < / \_
+ * By entheh. | \/ /\ /
+ * \_ / > /
+ * | \ / /
+ * | ' /
+ * \__/
+ */
+
+#include <stdlib.h>
+
+#include "dumb.h"
+#include "internal/dumb.h"
+
+
+
+typedef struct DUMB_ATEXIT_PROC
+{
+ struct DUMB_ATEXIT_PROC *next;
+ void (*proc)(void);
+}
+DUMB_ATEXIT_PROC;
+
+
+
+static DUMB_ATEXIT_PROC *dumb_atexit_proc = NULL;
+
+
+
+int dumb_atexit(void (*proc)(void))
+{
+ DUMB_ATEXIT_PROC *dap = dumb_atexit_proc;
+
+ while (dap) {
+ if (dap->proc == proc) return 0;
+ dap = dap->next;
+ }
+
+ dap = malloc(sizeof(*dap));
+
+ if (!dap)
+ return -1;
+
+ dap->next = dumb_atexit_proc;
+ dap->proc = proc;
+ dumb_atexit_proc = dap;
+
+ return 0;
+}
+
+
+
+void dumb_exit(void)
+{
+ while (dumb_atexit_proc) {
+ DUMB_ATEXIT_PROC *next = dumb_atexit_proc->next;
+ (*dumb_atexit_proc->proc)();
+ free(dumb_atexit_proc);
+ dumb_atexit_proc = next;
+ }
+}