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
include
locale/tr/LC_MESSAGES
src/ctx

@ -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;
}