From 9b8166b5cef192c332aea5bae430e4fc4dffdcba Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 7 Jun 2024 23:07:15 -0500 Subject: [PATCH] Update: The f_capability styles and use constant pointers in more places. --- level_0/f_capability/c/capability.c | 72 ++++++++----------------------------- 1 file changed, 15 insertions(+), 57 deletions(-) diff --git a/level_0/f_capability/c/capability.c b/level_0/f_capability/c/capability.c index 30b9555..b3fcce0 100644 --- a/level_0/f_capability/c/capability.c +++ b/level_0/f_capability/c/capability.c @@ -393,11 +393,7 @@ extern "C" { *ambient = cap_get_ambient(value); - if (*ambient == -1) { - return F_status_set_error(F_support_not); - } - - return F_okay; + return (*ambient == -1) ? F_status_set_error(F_support_not) : F_okay; } #endif // _di_f_capability_ambient_get_ @@ -505,10 +501,7 @@ extern "C" { #endif // _di_level_0_parameter_checking_ *destination = cap_dup(source); - - if (*destination) { - return F_okay; - } + if (*destination) return F_okay; if (errno == EINVAL) return F_status_set_error(F_parameter); if (errno == ENOMEM) return F_status_set_error(F_memory_not); @@ -547,10 +540,7 @@ extern "C" { #endif // _di_level_0_parameter_checking_ *capability = cap_copy_int(external); - - if (*capability) { - return F_okay; - } + if (*capability) return F_okay; if (errno == EINVAL) return F_status_set_error(F_parameter); if (errno == ENOMEM) return F_status_set_error(F_memory_not); @@ -586,10 +576,7 @@ extern "C" { #endif // _di_level_0_parameter_checking_ *capability = cap_get_fd(descriptor); - - if (*capability) { - return F_okay; - } + if (*capability) return F_okay; if (errno == EACCES) return F_status_set_error(F_access_denied); if (errno == EBADFD) return F_status_set_error(F_descriptor_not); @@ -633,10 +620,7 @@ extern "C" { #endif // _di_level_0_parameter_checking_ *capability = cap_get_file(path.string); - - if (*capability) { - return F_okay; - } + if (*capability) return F_okay; if (errno == EACCES) return F_status_set_error(F_access_denied); if (errno == EBADFD) return F_status_set_error(F_descriptor_not); @@ -729,10 +713,7 @@ extern "C" { #endif // _di_level_0_parameter_checking_ *capability = cap_from_text(text.string); - - if (*capability) { - return F_okay; - } + if (*capability) return F_okay; if (errno == EINVAL) return F_status_set_error(F_parameter); if (errno == ENOMEM) return F_status_set_error(F_memory_not); @@ -771,10 +752,7 @@ extern "C" { #endif // _di_level_0_parameter_checking_ *capability = cap_init(); - - if (*capability) { - return F_okay; - } + if (*capability) return F_okay; if (errno == EINVAL) return F_status_set_error(F_parameter); if (errno == ENOMEM) return F_status_set_error(F_memory_not); @@ -891,11 +869,7 @@ extern "C" { *bound = cap_get_bound(value); - if (*bound == -1) { - return F_status_set_error(F_known_not); - } - - return F_okay; + return (*bound == -1) ? F_status_set_error(F_known_not) : F_okay; } #endif // _di_f_capability_process_bound_get_ @@ -906,10 +880,7 @@ extern "C" { #endif // _di_level_0_parameter_checking_ *capability = cap_get_proc(); - - if (*capability) { - return F_okay; - } + if (*capability) return F_okay; if (errno == EINVAL) return F_status_set_error(F_parameter); if (errno == ENOMEM) return F_status_set_error(F_memory_not); @@ -925,10 +896,7 @@ extern "C" { #endif // _di_level_0_parameter_checking_ *capability = cap_get_pid(id); - - if (*capability) { - return F_okay; - } + if (*capability) return F_okay; return F_status_set_error(F_failure); } @@ -1017,11 +985,7 @@ extern "C" { #ifndef _di_f_capability_supported_ambient_ bool f_capability_supported_ambient(void) { - if (CAP_AMBIENT_SUPPORTED()) { - return F_true; - } - - return F_false; + return CAP_AMBIENT_SUPPORTED() ? F_true : F_false; } #endif // _di_f_capability_supported_ambient_ @@ -1032,11 +996,7 @@ extern "C" { #ifndef _di_f_capability_supported_code_ bool f_capability_supported_code(const f_capability_value_t code) { - if (CAP_IS_SUPPORTED(code)) { - return F_true; - } - - return F_false; + return CAP_IS_SUPPORTED(code) ? F_true : F_false; } #endif // _di_f_capability_supported_code_ @@ -1046,7 +1006,7 @@ extern "C" { if (!name) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - char *result = cap_to_name(code); + char * const result = cap_to_name(code); if (result) { const f_number_unsigned_t length = strlen(result); @@ -1091,13 +1051,11 @@ extern "C" { ssize_t length = 0; - char *result = cap_to_text(capability, &length); + char * const result = cap_to_text(capability, &length); if (result) { if (text->used + length + 1 > text->size) { - if (text->used + length + 1 > F_string_t_size_d) { - return F_status_set_error(F_string_too_large); - } + if (text->used + length + 1 > F_string_t_size_d) return F_status_set_error(F_string_too_large); { const f_status_t status = f_memory_array_resize(text->used + length + 1, sizeof(f_char_t), (void **) &text->string, &text->used, &text->size); -- 1.8.3.1