logo

utils-std

Collection of commonly available Unix tools
commit: b97dde853e8d068f67fab7ade82fdeb7124fb516
parent 59a64b48f468b19a6a2aa8322e6807fcc7ce2892
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 23 Apr 2024 08:45:51 +0200

cmd/id: Remove optional brackets on early returns

Diffstat:

Mcmd/id.c135++++++++++++++++---------------------------------------------------------------
1 file changed, 27 insertions(+), 108 deletions(-)

diff --git a/cmd/id.c b/cmd/id.c @@ -21,36 +21,21 @@ simple_list_groups(struct passwd *pw, int ngroups, gid_t *groups) if(name_flag) { struct group *lgr = getgrgid(groups[i]); - if(lgr == NULL) - { - return 1; - } + if(lgr == NULL) return 1; int sep = ' '; - if(i == ngroups - 1) - { - sep = '\n'; - } + if(i == ngroups - 1) sep = '\n'; int ret = printf("%s%c", lgr->gr_name, sep); - if(ret < 0) - { - return 1; - } + if(ret < 0) return 1; } else { int sep = ' '; - if(i == ngroups - 1) - { - sep = '\n'; - } + if(i == ngroups - 1) sep = '\n'; int ret = printf("%u%c", groups[i], sep); - if(ret < 0) - { - return 1; - } + if(ret < 0) return 1; } } @@ -68,44 +53,26 @@ list_groups(struct passwd *pw, int ngroups, gid_t *groups) if(name_flag) { - if(lgr == NULL) - { - return 1; - } + if(lgr == NULL) return 1; int sep = ' '; - if(i == ngroups - 1) - { - sep = '\0'; - } + if(i == ngroups - 1) sep = '\0'; int ret = printf("%s%c", lgr->gr_name, sep); - if(ret < 0) - { - return 1; - } + if(ret < 0) return 1; } else { int ret = printf("%u", groups[i]); - if(ret < 0) - { - return 1; - } + if(ret < 0) return 1; if(lgr != NULL) { int ret = printf("(%s)", lgr->gr_name); - if(ret < 0) - { - return 1; - } + if(ret < 0) return 1; } - if(i != ngroups - 1) - { - printf(","); - } + if(i != ngroups - 1) printf(","); } } @@ -117,19 +84,13 @@ print_gid(char *field, struct group *gr, gid_t gid) { if(gr && gr->gr_name) { - if(name_flag) - { - return printf("%s=%s", field, gr->gr_name); - } + if(name_flag) return printf("%s=%s", field, gr->gr_name); return printf("%s=%u(%s)", field, gid, gr->gr_name); } else { - if(name_flag) - { - return -1; - } + if(name_flag) return -1; return printf("%s=%u", field, gid); } @@ -140,19 +101,13 @@ print_uid(char *field, struct passwd *pw, uid_t uid) { if(pw && pw->pw_name) { - if(name_flag) - { - return printf("%s=%s", field, pw->pw_name); - } + if(name_flag) return printf("%s=%s", field, pw->pw_name); return printf("%s=%u(%s)", field, uid, pw->pw_name); } else { - if(name_flag) - { - return -1; - } + if(name_flag) return -1; return printf("%s=%u", field, uid); } @@ -163,10 +118,7 @@ safe_getpwuid(uid_t uid, struct passwd *res) { struct passwd *pw = getpwuid(uid); - if(pw != NULL) - { - *res = *pw; - } + if(pw != NULL) *res = *pw; } enum id_modes @@ -285,10 +237,7 @@ main(int argc, char *argv[]) if(mode == ID_GID) { - if(!real_flag) - { - gid = egid; - } + if(!real_flag) gid = egid; if(!name_flag) { @@ -308,20 +257,14 @@ main(int argc, char *argv[]) } } - if(ret < 0) - { - goto failure; - } + if(ret < 0) goto failure; goto done; } if(mode == ID_UID) { - if(!real_flag) - { - uid = euid; - } + if(!real_flag) uid = euid; if(!name_flag) { @@ -341,10 +284,7 @@ main(int argc, char *argv[]) } } - if(ret < 0) - { - goto failure; - } + if(ret < 0) goto failure; goto done; } @@ -360,55 +300,34 @@ main(int argc, char *argv[]) ret = simple_list_groups(&epw, ngroups, groups); } - if(ret != 0) - { - goto failure; - } + if(ret != 0) goto failure; goto done; } ret = print_uid("uid", &pw, uid); - if(ret < 0) - { - goto failure; - } + if(ret < 0) goto failure; if(euid != uid) { ret = print_uid(" euid", &epw, euid); - if(ret < 0) - { - goto failure; - } + if(ret < 0) goto failure; } ret = print_gid(" gid", gr, gid); - if(ret < 0) - { - goto failure; - } + if(ret < 0) goto failure; if(egid != gid) { ret = print_gid(" egid", egr, egid); - if(ret < 0) - { - goto failure; - } + if(ret < 0) goto failure; } - if(list_groups(&pw, ngroups, groups) != 0) - { - goto failure; - } + if(list_groups(&pw, ngroups, groups) != 0) goto failure; ret = printf("\n"); - if(ret < 0) - { - goto failure; - } + if(ret < 0) goto failure; done: free(groups);