From d335b43735a6538f990d9f12ca4019d7377df492 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 7 Jul 2024 19:30:15 -0500 Subject: [PATCH] Cleanup: Minor style improvements and make pointers constant where possible. --- level_2/fll_execute/c/execute.c | 37 ++++++++------------------------- level_2/fll_execute/c/private-execute.c | 16 +++++++------- 2 files changed, 17 insertions(+), 36 deletions(-) diff --git a/level_2/fll_execute/c/execute.c b/level_2/fll_execute/c/execute.c index e38acdb..3ca04b2 100644 --- a/level_2/fll_execute/c/execute.c +++ b/level_2/fll_execute/c/execute.c @@ -123,10 +123,7 @@ extern "C" { if (last_slash) { status = f_file_exists(program.used ? program : arguments.array[0], F_true); - - if (status != F_true) { - return F_status_set_error(F_file_found_not); - } + if (status != F_true) return F_status_set_error(F_file_found_not); path.string = program.used ? program.string : arguments.array[0].string; path.used = program.used ? program.used : arguments.array[0].used; @@ -172,15 +169,9 @@ extern "C" { status = F_status_set_fine(status); // Don't consider bad/non-accessible paths an error, just ignore them. - if (status == F_name) { - continue; - } - else if (status == F_directory) { - continue; - } - else if (status == F_access_denied) { - continue; - } + if (status == F_name) continue; + else if (status == F_directory) continue; + else if (status == F_access_denied) continue; } } @@ -262,7 +253,7 @@ extern "C" { } if (result) { - int *r = (int *) result; + int * const r = (int *) result; *r = code; } @@ -270,11 +261,7 @@ extern "C" { exit(code); } - if (code) { - return F_status_set_error(F_failure); - } - - return F_okay; + return code ? F_status_set_error(F_failure) : F_okay; } #endif // _di_fll_execute_into_ @@ -372,15 +359,9 @@ extern "C" { status = F_status_set_fine(status); // Don't consider bad/non-accessible paths an error, just ignore them. - if (status == F_name) { - continue; - } - else if (status == F_directory) { - continue; - } - else if (status == F_access_denied) { - continue; - } + if (status == F_name) continue; + else if (status == F_directory) continue; + else if (status == F_access_denied) continue; } } diff --git a/level_2/fll_execute/c/private-execute.c b/level_2/fll_execute/c/private-execute.c index ca8400e..50484c3 100644 --- a/level_2/fll_execute/c/private-execute.c +++ b/level_2/fll_execute/c/private-execute.c @@ -222,7 +222,7 @@ extern "C" { // Have the parent perform all appropriate access controls and then send either '0' for no error or '1' for error to the child. { - const f_string_static_t *string_result = &f_string_ascii_0_s; + const f_string_static_t * const string_result = &f_string_ascii_0_s; const f_file_t file = macro_f_file_t_initialize_2(0, descriptors[1], F_file_flag_write_only_d); const f_status_t status = private_fll_execute_as_parent(*as, id_process, parameter, string_result); @@ -240,7 +240,7 @@ extern "C" { if (parameter && parameter->option & FL_execute_parameter_option_return_d) { if (result != 0) { - pid_t *r = (pid_t *) result; + pid_t * const r = (pid_t *) result; *r = id_process; } @@ -281,7 +281,7 @@ extern "C" { close(descriptors[0]); if (result) { - int *r = (int *) result; + int * const r = (int *) result; *r = F_execute_failure; } @@ -358,7 +358,7 @@ extern "C" { } if (result) { - int *r = (int *) result; + int * const r = (int *) result; *r = code; } @@ -392,7 +392,7 @@ extern "C" { close(descriptors[0]); { - const f_string_static_t *string_result = &f_string_ascii_0_s; + const f_string_static_t * string_result = &f_string_ascii_0_s; const f_file_t file = macro_f_file_t_initialize_2(0, descriptors[1], F_file_flag_write_only_d); @@ -422,7 +422,7 @@ extern "C" { if (parameter && parameter->option & FL_execute_parameter_option_return_d) { if (result != 0) { - pid_t *r = (pid_t *) result; + pid_t * const r = (pid_t *) result; *r = id_process; } @@ -463,7 +463,7 @@ extern "C" { close(descriptors[0]); if (result) { - f_status_t *r = (f_status_t *) result; + f_status_t * const r = (f_status_t *) result; *r = F_status_set_error(F_failure); } @@ -541,7 +541,7 @@ extern "C" { } if (result) { - int *r = (int *) result; + int * const r = (int *) result; *r = code; } -- 1.8.3.1