kitty/kitty/cleanup.c
Kovid Goyal 55dc354e68
Improve at exit cleanup functions
Now they are run in a defined order not based on
the order of initialization
2021-04-01 11:48:36 +05:30

24 lines
529 B
C

/*
* cleanup.c
* Copyright (C) 2021 Kovid Goyal <kovid at kovidgoyal.net>
*
* Distributed under terms of the GPL3 license.
*/
#include "cleanup.h"
kitty_cleanup_at_exit_func exit_funcs[NUM_CLEANUP_FUNCS] = {0};
void
register_at_exit_cleanup_func(AtExitCleanupFunc which, kitty_cleanup_at_exit_func func) {
if (which < NUM_CLEANUP_FUNCS) exit_funcs[which] = func;
}
void
run_at_exit_cleanup_functions(void) {
for (unsigned i = 0; i < NUM_CLEANUP_FUNCS; i++) {
if (exit_funcs[i]) exit_funcs[i]();
}
}