diff options
author | Trumeet <yuuta@yuuta.moe> | 2022-07-20 18:12:22 -0700 |
---|---|---|
committer | Trumeet <yuuta@yuuta.moe> | 2022-07-20 18:12:22 -0700 |
commit | b4afa06e383325f4a0c751a64ca896d769db07a8 (patch) | |
tree | 7647fdd73d4f487de778c27aea99bf890458b647 /client/libacron/library.c | |
parent | da14a17298c67d83e6da4732f47304954acc26fc (diff) | |
download | acron-b4afa06e383325f4a0c751a64ca896d769db07a8.tar acron-b4afa06e383325f4a0c751a64ca896d769db07a8.tar.gz acron-b4afa06e383325f4a0c751a64ca896d769db07a8.tar.bz2 acron-b4afa06e383325f4a0c751a64ca896d769db07a8.zip |
libac: First Commit
Diffstat (limited to 'client/libacron/library.c')
-rw-r--r-- | client/libacron/library.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/client/libacron/library.c b/client/libacron/library.c new file mode 100644 index 0000000..dfc45e2 --- /dev/null +++ b/client/libacron/library.c @@ -0,0 +1,44 @@ +#include "libac.h" +#include "config.h" +#include "helpers.h" + +#include <stdlib.h> + +_Thread_local struct libac_config *config = NULL; + +int ac_init(const libac_config_t *c) { + if (config) { + return AC_E_ALREADY_INITIALIZED; + } + + int r; + if ((r = SALLOC(libac_config_t, &config))) { + return r; + } + + if (c->tok) { + config->tok = c->tok; + } else { + if (!(config->tok = json_tokener_new())) { + r = AC_E_MEMORY_ALLOCATION; + goto fail; + } + } + if (c->out) { + config->out = c->out; + } + return AC_E_OK; + fail: + ac_free(); + return r; +} + +int ac_free(void) { + AC_CHECK_INIT; + if (config->tok) { + json_tokener_free(config->tok); + config->tok = NULL; + } + free(config); + config = NULL; +}
\ No newline at end of file |