From a043a09da7eb4d6cd1256aaddf0f9eefc735085b Mon Sep 17 00:00:00 2001 From: "Chris D. Faulhaber" Date: Mon, 3 Dec 2001 00:51:36 +0000 Subject: [PATCH] style(9) cleanups mostly consisting of: o explicitly check return values and variables against a value o return x; -> return (x); o fix inconsistent sysexits usage by nuking it (partially suggested by bde) Obtained from: TrustedBSD Project --- bin/setfacl/file.c | 29 ++++++++++++++------------- bin/setfacl/mask.c | 17 ++++++++-------- bin/setfacl/merge.c | 46 ++++++++++++++++++++----------------------- bin/setfacl/remove.c | 37 +++++++++++++++++++--------------- bin/setfacl/setfacl.c | 38 +++++++++++++++++------------------ bin/setfacl/util.c | 5 ++--- 6 files changed, 85 insertions(+), 87 deletions(-) diff --git a/bin/setfacl/file.c b/bin/setfacl/file.c index 3e3c80504a6d..d2cdb9894318 100644 --- a/bin/setfacl/file.c +++ b/bin/setfacl/file.c @@ -32,43 +32,44 @@ #include #include #include -#include #include "setfacl.h" -/* read acl text from a file and return the corresponding acl */ +/* + * read acl text from a file and return the corresponding acl + */ acl_t get_acl_from_file(const char *filename) { FILE *file; char buf[BUFSIZ]; - if (!filename) - err(EX_USAGE, "(null) filename in get_acl_from_file()"); + if (filename == NULL) + err(1, "(null) filename in get_acl_from_file()"); bzero(&buf, sizeof(buf)); - if (!strcmp(filename, "-")) { - if (have_stdin) - err(EX_USAGE, "cannot specify more than one stdin"); + if (strcmp(filename, "-") == 0) { + if (have_stdin != 0) + err(1, "cannot specify more than one stdin"); file = stdin; have_stdin = 1; } else { file = fopen(filename, "r"); - if (!file) - err(EX_OSERR, "fopen() %s failed", filename); + if (file == NULL) + err(1, "fopen() %s failed", filename); } fread(buf, sizeof(buf), (size_t)1, file); - if (ferror(file)) { + if (ferror(file) != 0) { fclose(file); - err(EX_USAGE, "error reading from %s", filename); - } else if (!feof(file)) { + err(1, "error reading from %s", filename); + } else if (feof(file) == 0) { fclose(file); - errx(EX_USAGE, "line too long in %s", filename); + errx(1, "line too long in %s", filename); } fclose(file); - return acl_from_text(buf); + return (acl_from_text(buf)); } diff --git a/bin/setfacl/mask.c b/bin/setfacl/mask.c index fd4409ae096d..0851be1bff23 100644 --- a/bin/setfacl/mask.c +++ b/bin/setfacl/mask.c @@ -34,7 +34,6 @@ #include #include #include -#include #include "setfacl.h" @@ -55,13 +54,13 @@ set_acl_mask(acl_t *prev_acl) * specified ACL mask entry. */ if (have_mask) - return 0; + return (0); acl = acl_dup(*prev_acl); - if (!acl) - err(EX_OSERR, "acl_dup() failed"); + if (acl == NULL) + err(1, "acl_dup() failed"); - if (!n_flag) { + if (n_flag == 0) { /* * If no mask entry is specified and the -n option is not * specified, then the permissions of the resulting ACL mask @@ -72,7 +71,7 @@ set_acl_mask(acl_t *prev_acl) if (acl_calc_mask(&acl)) { warn("acl_calc_mask() failed"); acl_free(acl); - return -1; + return (-1); } } else { /* @@ -90,7 +89,7 @@ set_acl_mask(acl_t *prev_acl) if (tag == ACL_MASK) { acl_free(acl); - return 0; + return (0); } } @@ -102,11 +101,11 @@ set_acl_mask(acl_t *prev_acl) */ warnx("warning: no mask entry"); acl_free(acl); - return 0; + return (0); } **prev_acl = *acl; acl_free(acl); - return 0; + return (0); } diff --git a/bin/setfacl/merge.c b/bin/setfacl/merge.c index acb01f4ce6e5..b9c17b3bd80f 100644 --- a/bin/setfacl/merge.c +++ b/bin/setfacl/merge.c @@ -32,11 +32,12 @@ #include #include -#include #include "setfacl.h" -/* merge acl into existing file's ACL */ +/* + * merge an ACL into existing file's ACL + */ int merge_acl(acl_t acl, acl_t *prev_acl) { @@ -51,8 +52,8 @@ merge_acl(acl_t acl, acl_t *prev_acl) acl_new = acl_dup(prev_acl[0]); else acl_new = acl_dup(prev_acl[1]); - if (!acl_new) - err(EX_OSERR, "acl_dup() failed"); + if (acl_new == NULL) + err(1, "acl_dup() failed"); entry_id = ACL_FIRST_ENTRY; @@ -62,21 +63,20 @@ merge_acl(acl_t acl, acl_t *prev_acl) /* keep track of existing ACL_MASK entries */ if (acl_get_tag_type(entry, &tag) == -1) - err(EX_OSERR, - "acl_get_tag_type() failed - invalid ACL entry"); + err(1, "acl_get_tag_type() failed - invalid ACL entry"); if (tag == ACL_MASK) have_mask = 1; /* check against the existing ACL entries */ entry_id_new = ACL_FIRST_ENTRY; - while (!have_entry && + while (have_entry == 0 && acl_get_entry(acl_new, entry_id_new, &entry_new) == 1) { entry_id_new = ACL_NEXT_ENTRY; if (acl_get_tag_type(entry, &tag) == -1) - err(EX_OSERR, "acl_get_tag_type() failed"); + err(1, "acl_get_tag_type() failed"); if (acl_get_tag_type(entry_new, &tag_new) == -1) - err(EX_OSERR, "acl_get_tag_type() failed"); + err(1, "acl_get_tag_type() failed"); if (tag != tag_new) continue; @@ -85,27 +85,25 @@ merge_acl(acl_t acl, acl_t *prev_acl) case ACL_GROUP: id = acl_get_qualifier(entry); if (id == NULL) - err(EX_OSERR, - "acl_get_qualifier() failed"); + err(1, "acl_get_qualifier() failed"); id_new = acl_get_qualifier(entry_new); if (id_new == NULL) - err(EX_OSERR, - "acl_get_qualifier() failed"); + err(1, "acl_get_qualifier() failed"); if (*id == *id_new) { /* any other matches */ if (acl_get_permset(entry, &permset) == -1) - err(EX_OSERR, + err(1, "acl_get_permset() failed"); if (acl_set_permset(entry_new, permset) == -1) - err(EX_OSERR, + err(1, "acl_set_permset() failed"); have_entry = 1; } acl_free(id); acl_free(id_new); - if (!have_entry) + if (have_entry == 0) break; /* FALLTHROUGH */ case ACL_USER_OBJ: @@ -113,28 +111,26 @@ merge_acl(acl_t acl, acl_t *prev_acl) case ACL_OTHER: case ACL_MASK: if (acl_get_permset(entry, &permset) == -1) - err(EX_OSERR, - "acl_get_permset() failed"); + err(1, "acl_get_permset() failed"); if (acl_set_permset(entry_new, permset) == -1) - err(EX_OSERR, - "acl_set_permset() failed"); + err(1, "acl_set_permset() failed"); have_entry = 1; break; default: /* should never be here */ - errx(EX_OSERR, "Invalid tag type: %i", tag); + errx(1, "Invalid tag type: %i", tag); break; } } /* if this entry has not been found, it must be new */ - if (!have_entry) { + if (have_entry == 0) { if (acl_create_entry(&acl_new, &entry_new) == -1) { acl_free(acl_new); - return -1; + return (-1); } if (acl_copy_entry(entry_new, entry) == -1) - err(EX_OSERR, "acl_copy_entry() failed"); + err(1, "acl_copy_entry() failed"); } } @@ -148,5 +144,5 @@ merge_acl(acl_t acl, acl_t *prev_acl) } - return 0; + return (0); } diff --git a/bin/setfacl/remove.c b/bin/setfacl/remove.c index e987df77b96e..0911dd8b9a4b 100644 --- a/bin/setfacl/remove.c +++ b/bin/setfacl/remove.c @@ -33,11 +33,12 @@ #include #include #include -#include #include "setfacl.h" -/* remove ACL entries from an ACL */ +/* + * remove ACL entries from an ACL + */ int remove_acl(acl_t acl, acl_t *prev_acl) { @@ -52,8 +53,8 @@ remove_acl(acl_t acl, acl_t *prev_acl) acl_new = acl_dup(prev_acl[0]); else acl_new = acl_dup(prev_acl[1]); - if (!acl_new) - err(EX_OSERR, "acl_dup() failed"); + if (acl_new == NULL) + err(1, "acl_dup() failed"); tag = ACL_UNDEFINED_TAG; @@ -80,12 +81,14 @@ remove_acl(acl_t acl, acl_t *prev_acl) } if (carried_error) - return -1; + return (-1); - return 0; + return (0); } -/* remove default entries */ +/* + * remove default entries + */ int remove_default(acl_t *prev_acl) { @@ -93,16 +96,18 @@ remove_default(acl_t *prev_acl) if (prev_acl[1]) { acl_free(prev_acl[1]); prev_acl[1] = acl_init(ACL_MAX_ENTRIES); - if (!prev_acl[1]) + if (prev_acl[1] == NULL) err(1, "acl_init() failed"); } else { warn("cannot remove default ACL"); - return -1; + return (-1); } - return 0; + return (0); } -/* remove extended entries */ +/* + * remove extended entries + */ void remove_ext(acl_t *prev_acl) { @@ -116,13 +121,13 @@ remove_ext(acl_t *prev_acl) acl_old = acl_dup(prev_acl[0]); else acl_old = acl_dup(prev_acl[1]); - if (!acl_old) - err(EX_OSERR, "acl_dup() failed"); + if (acl_old == NULL) + err(1, "acl_dup() failed"); have_mask_entry = 0; acl_new = acl_init(ACL_MAX_ENTRIES); - if (!acl_new) - err(EX_OSERR, "%s", "acl_init() failed"); + if (acl_new == NULL) + err(1, "acl_init() failed"); tag = ACL_UNDEFINED_TAG; /* only save the default user/group/other entries */ @@ -157,7 +162,7 @@ remove_ext(acl_t *prev_acl) break; } } - if (have_mask_entry && !n_flag) { + if (have_mask_entry && n_flag == 0) { if (acl_calc_mask(&acl_new) == -1) err(1, "acl_calc_mask() failed"); } else { diff --git a/bin/setfacl/setfacl.c b/bin/setfacl/setfacl.c index 072bca876dfd..d69c7c9bcd78 100644 --- a/bin/setfacl/setfacl.c +++ b/bin/setfacl/setfacl.c @@ -36,7 +36,6 @@ #include #include #include -#include #include #include "setfacl.h" @@ -67,21 +66,21 @@ get_file_acls(const char *filename) if (stat(filename, &sb) == -1) { warn("stat() of %s failed", filename); - return NULL; + return (NULL); } acl = zmalloc(sizeof(acl_t) * 2); acl[0] = acl_get_file(filename, ACL_TYPE_ACCESS); - if (!acl[0]) - err(EX_OSERR, "acl_get_file() failed"); + if (acl[0] == NULL) + err(1, "acl_get_file() failed"); if (S_ISDIR(sb.st_mode)) { acl[1] = acl_get_file(filename, ACL_TYPE_DEFAULT); - if (!acl[1]) - err(EX_OSERR, "acl_get_file() failed"); + if (acl[1] == NULL) + err(1, "acl_get_file() failed"); } else acl[1] = NULL; - return acl; + return (acl); } static void @@ -90,7 +89,7 @@ usage(void) fprintf(stderr, "usage: setfacl [-bdknv] [-m entries] [-M file1] " "[-x entries] [-X file2] [file ...]\n"); - exit(EX_USAGE); + exit(1); } int @@ -114,8 +113,8 @@ main(int argc, char *argv[]) case 'M': entry = zmalloc(sizeof(struct sf_entry)); entry->acl = get_acl_from_file(optarg); - if (!entry->acl) - err(EX_OSERR, "get_acl_from_file() failed"); + if (entry->acl == NULL) + err(1, "get_acl_from_file() failed"); entry->op = OP_MERGE_ACL; TAILQ_INSERT_TAIL(&entrylist, entry, next); break; @@ -141,8 +140,8 @@ main(int argc, char *argv[]) case 'm': entry = zmalloc(sizeof(struct sf_entry)); entry->acl = acl_from_text(optarg); - if (!entry->acl) - err(EX_USAGE, "acl_from_text() failed"); + if (entry->acl == NULL) + err(1, "acl_from_text() failed"); entry->op = OP_MERGE_ACL; TAILQ_INSERT_TAIL(&entrylist, entry, next); break; @@ -152,8 +151,8 @@ main(int argc, char *argv[]) case 'x': entry = zmalloc(sizeof(struct sf_entry)); entry->acl = acl_from_text(optarg); - if (!entry->acl) - err(EX_USAGE, "acl_from_text() failed"); + if (entry->acl == NULL) + err(1, "acl_from_text() failed"); entry->op = OP_REMOVE_ACL; TAILQ_INSERT_TAIL(&entrylist, entry, next); break; @@ -164,13 +163,13 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if (!n_flag && TAILQ_EMPTY(&entrylist)) + if (n_flag == 0 && TAILQ_EMPTY(&entrylist)) usage(); /* take list of files from stdin */ - if (argc == 0 || !strcmp(argv[0], "-")) { + if (argc == 0 || strcmp(argv[0], "-") == 0) { if (have_stdin) - err(EX_USAGE, "cannot have more than one stdin"); + err(1, "cannot have more than one stdin"); have_stdin = 1; bzero(&filename, sizeof(filename)); while (fgets(filename, (int)sizeof(filename), stdin)) { @@ -186,7 +185,7 @@ main(int argc, char *argv[]) TAILQ_FOREACH(file, &filelist, next) { /* get our initial access and default ACL's */ acl = get_file_acls(file->filename); - if (!acl) + if (acl == NULL) continue; if ((acl_type == ACL_TYPE_DEFAULT) && !acl[1]) { warnx("Default ACL not valid for %s", file->filename); @@ -221,7 +220,6 @@ main(int argc, char *argv[]) local_error += remove_acl(entry->acl, acl); need_mask = 1; break; - /* NOTREACHED */ } } @@ -250,5 +248,5 @@ main(int argc, char *argv[]) free(acl); } - return carried_error; + return (carried_error); } diff --git a/bin/setfacl/util.c b/bin/setfacl/util.c index f4fef77adb47..2c1a6e273b04 100644 --- a/bin/setfacl/util.c +++ b/bin/setfacl/util.c @@ -29,7 +29,6 @@ #include #include #include -#include #include "setfacl.h" @@ -40,6 +39,6 @@ zmalloc(size_t size) ptr = calloc(1, size); if (ptr == NULL) - err(EX_OSERR, "calloc() failed"); - return ptr; + err(1, "calloc() failed"); + return (ptr); }