From 405afc36e0929d887188be09a5886f79ff0ea1c4 Mon Sep 17 00:00:00 2001 From: gramanas Date: Sat, 22 Sep 2018 12:58:22 +0300 Subject: Standarize error codes --- src/ck.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'src/ck.c') diff --git a/src/ck.c b/src/ck.c index 0d093d3..b2119e7 100644 --- a/src/ck.c +++ b/src/ck.c @@ -33,45 +33,32 @@ #include "cklist.h" #include "ckutil.h" -void free_res(UserOpt *opt, Conf *conf) { - if (opt) { - free_user_opt(opt); - } - if (conf) { - free_conf(conf); - } -} - int main(int argc, char *argv[]) { UserOpt opt; + Conf conf = {.VC_dir = NULL, .SCRT_dir = NULL}; /* get user opt */ switch(parse_action(argc, argv, &opt)) { case APR_HELP: - free_res(&opt, NULL); print_parser_help(); - return 0; + goto error; case APR_ERR: print_parser_error(&opt); - free_res(&opt, NULL); - return 1; + goto error; case APR_OK: break; } - Conf conf = {.VC_dir = NULL, .SCRT_dir = NULL}; /* If the action is init don't load the config, skip to running init*/ if (opt.action != CKA_INIT) { /* If the db doesn't exist ck is not initialized in the config * location specified in opt */ if (!db_exists(&opt)) { printf("ck is not initialized in %s.\nRun ck init first.\n", opt.confDir); - free_res(&opt, NULL); - return 1; + goto error; } /* Finally parse the config file and exit on error */ if (!config_file_parse(&conf, &opt)) { - free_res(&opt, &conf); - return 1; + goto error; } } @@ -86,6 +73,8 @@ int main(int argc, char *argv[]) { default: break; } - free_res(&opt, &conf); + error: + free_user_opt(&opt); + free_conf(&conf); return 0; } -- cgit v1.2.3