diff options
Diffstat (limited to 'src/shared/config.c')
-rw-r--r-- | src/shared/config.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/shared/config.c b/src/shared/config.c new file mode 100644 index 0000000..56f930a --- /dev/null +++ b/src/shared/config.c @@ -0,0 +1,60 @@ +/* + * crash-manager + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include <assert.h> +#include <iniparser.h> +#include <stdbool.h> +#include <stdlib.h> +#include <string.h> + +#include "config.h" +#include "defs.h" +#include "log.h" +#include "util.h" + +bool config_init(config_t *c, const char *const path) +{ + assert(c); + assert(path); + + dictionary *ini = iniparser_load(path); + if (!ini) { + _E("Failed to load config file %s", path); + return false; + } + + bool ret = false; + +#define GET(type, key, defval) iniparser_get##type(ini, LOG_DUMP_SECTION ":" key, defval) + + c->crash_root_path = strdup(GET(string, "CrashRootPath", CRASH_ROOT_PATH)); + if (!c->crash_root_path) + goto out; + +#undef GET + + ret = true; +out: + iniparser_freedict(ini); + return ret; +} + +void config_free(config_t *c) +{ + assert(c); + + free(c->crash_root_path); +} |