add some more file fns and a Ctrl-C handler

This commit is contained in:
Tenari
2026-04-09 18:55:52 -05:00
parent f67e4a3d9b
commit 7ec8dc5815
4 changed files with 78 additions and 0 deletions
+12
View File
@@ -1,11 +1,23 @@
#include "all.h"
global pthread_key_t linux_thread_context_key;
global void (*_ctrl_c_handler_fn_ptr)() = NULL;
// ThreadContext
void osInit() {
pthread_key_create(&linux_thread_context_key, NULL);
}
void _osGenericSignalHandler(i32 signal) {
if (signal == SIGINT && _ctrl_c_handler_fn_ptr != NULL) {
_ctrl_c_handler_fn_ptr();
}
}
void osSetCtrlCCallback(void (*handler)()) {
_ctrl_c_handler_fn_ptr = handler;
signal(SIGINT, _osGenericSignalHandler);
}
void* osThreadContextGet() {
return pthread_getspecific(linux_thread_context_key);
}