library: Add facility to register custom init/deinit functions

These can be linked into the application to do initialization/cleanup
without having to modify the source code.
This commit is contained in:
Tobias Brunner
2025-04-10 08:31:09 +02:00
parent 1a20502573
commit a6f4146f45
2 changed files with 57 additions and 2 deletions
+19 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2018 Tobias Brunner
* Copyright (C) 2010-2025 Tobias Brunner
* Copyright (C) 2008 Martin Willi
*
* Copyright (C) secunet Security Networks AG
@@ -285,6 +285,24 @@ bool library_init(char *settings, const char *namespace);
*/
void library_deinit();
/**
* Custom function called during init/deinit of a library.
*
* @param init TRUE during init, FALSE during deinit
* @return FALSE if an error occurred and init should fail
*/
typedef bool (*library_init_t)(bool init);
/**
* Register a custom init function that's called at the end of library_init()
* and the start of library_deinit().
*
* To be called from __attribute__((constructor)) functions.
*
* @param init init function
*/
void library_init_register(library_init_t init);
/**
* Library instance, set after library_init() and before library_deinit() calls.
*/