From 61ab7f66acb82b14d3ad6258726a3d2b9bdfcc66 Mon Sep 17 00:00:00 2001 From: ngn Date: Sun, 4 Aug 2024 15:24:37 +0300 Subject: [PATCH] new: seperate ctx init and new functions --- include/ctx.h | 3 ++- locale/tr/LC_MESSAGES/libmp.po | 2 +- src/ctx/ctx.c | 27 ++++++++++++++++++++++----- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/include/ctx.h b/include/ctx.h index 1c5887e..e3ae446 100644 --- a/include/ctx.h +++ b/include/ctx.h @@ -55,7 +55,8 @@ typedef bool (*lm_ctx_check_callback_t)( /* ############### ## ctx stuff ## ############### */ -bool lm_ctx_init(lm_ctx_t *ctx, char *root_dir, char *temp_dir, char *data_dir); +bool lm_ctx_init(lm_ctx_t *ctx); +bool lm_ctx_new(lm_ctx_t *ctx, char *root_dir, char *temp_dir, char *data_dir); void lm_ctx_free(lm_ctx_t *ctx); /* #################### diff --git a/locale/tr/LC_MESSAGES/libmp.po b/locale/tr/LC_MESSAGES/libmp.po index 29e45a1..3a3bd24 100644 --- a/locale/tr/LC_MESSAGES/libmp.po +++ b/locale/tr/LC_MESSAGES/libmp.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-08-04 13:06+0300\n" +"POT-Creation-Date: 2024-08-04 15:24+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/src/ctx/ctx.c b/src/ctx/ctx.c index dbb687d..64ce22a 100644 --- a/src/ctx/ctx.c +++ b/src/ctx/ctx.c @@ -8,6 +8,7 @@ #include #include #include +#include bool __lm_ctx_init_checkdir(char *path){ if(!mkdir_ifnot(path)){ @@ -28,17 +29,33 @@ bool __lm_ctx_init_checkdir(char *path){ return true; } -bool lm_ctx_init(lm_ctx_t *ctx, char *root_dir, char *temp_dir, char *data_dir) { +bool lm_ctx_init(lm_ctx_t *ctx) { + if(NULL == ctx){ + lm_error_set(LM_ERR_ArgNULL); + return false; + } + setlocale(LC_ALL, ""); textdomain("libmp"); - char *suberr = NULL; - bool ret = false; - bzero(ctx, sizeof(lm_ctx_t)); ctx->version = LM_VERSION; lm_error_clear(); + return true; +} + +bool lm_ctx_new(lm_ctx_t *ctx, char *root_dir, char *temp_dir, char *data_dir) { + if(NULL == ctx){ + lm_error_set(LM_ERR_ArgNULL); + return false; + } + + char *suberr = NULL; + bool ret = false; + + lm_ctx_init(ctx); + if(root_dir != NULL && !__lm_ctx_init_checkdir(root_dir)){ suberr = lm_strerror_dup(); pdebug(__func__, "check failed for specified root directory: %s", lm_strerror()); @@ -83,7 +100,7 @@ void lm_ctx_free(lm_ctx_t *ctx) { if(NULL != ctx->db) lm_database_free(ctx->db); - + lm_error_clear(); return; }