new: seperate ctx init and new functions

This commit is contained in:
ngn 2024-08-04 15:24:37 +03:00
parent d2d6679060
commit 61ab7f66ac
3 changed files with 25 additions and 7 deletions

View File

@ -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);
/* ####################

View File

@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"

View File

@ -8,6 +8,7 @@
#include <locale.h>
#include <string.h>
#include <stdio.h>
#include <strings.h>
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;
}