From f7b03c0695b313a0ddd527d4bbd6c50c010bd7e4 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 29 Jul 2020 22:44:53 -0400 Subject: bftw: Rename bftw_typeflag to bftw_type, and make it not a bitmask --- bftw.c | 54 ++++++++++++++++++++++++------------------------ bftw.h | 38 +++++++++++++++++----------------- color.c | 10 ++++----- eval.c | 72 +++++++++++++++++++++++++++++++--------------------------------- fsade.c | 12 +++++------ opt.c | 4 ++-- parse.c | 9 ++++---- printf.c | 12 +++++------ util.c | 2 +- 9 files changed, 106 insertions(+), 107 deletions(-) diff --git a/bftw.c b/bftw.c index b5c50bb..b33e579 100644 --- a/bftw.c +++ b/bftw.c @@ -73,7 +73,7 @@ struct bftw_file { int fd; /** This file's type, if known. */ - enum bftw_typeflag typeflag; + enum bftw_type type; /** The device number, for cycle detection. */ dev_t dev; /** The inode number, for cycle detection. */ @@ -325,7 +325,7 @@ static struct bftw_file *bftw_file_new(struct bftw_cache *cache, struct bftw_fil file->refcount = 1; file->fd = -1; - file->typeflag = BFTW_UNKNOWN; + file->type = BFTW_UNKNOWN; file->dev = -1; file->ino = -1; @@ -754,7 +754,7 @@ err: return -1; } -enum bftw_typeflag bftw_mode_typeflag(mode_t mode) { +enum bftw_type bftw_mode_to_type(mode_t mode) { switch (mode & S_IFMT) { #ifdef S_IFBLK case S_IFBLK: @@ -802,7 +802,7 @@ enum bftw_typeflag bftw_mode_typeflag(mode_t mode) { } } -static enum bftw_typeflag bftw_dirent_typeflag(const struct dirent *de) { +static enum bftw_type bftw_dirent_type(const struct dirent *de) { #if defined(_DIRENT_HAVE_D_TYPE) || defined(DT_UNKNOWN) switch (de->d_type) { #ifdef DT_BLK @@ -886,18 +886,18 @@ const struct bfs_stat *bftw_stat(const struct BFTW *ftwbuf, enum bfs_stat_flag f return ret; } -enum bftw_typeflag bftw_typeflag(const struct BFTW *ftwbuf, enum bfs_stat_flag flags) { +enum bftw_type bftw_type(const struct BFTW *ftwbuf, enum bfs_stat_flag flags) { if (ftwbuf->stat_flags & BFS_STAT_NOFOLLOW) { - if ((flags & BFS_STAT_NOFOLLOW) || ftwbuf->typeflag != BFTW_LNK) { - return ftwbuf->typeflag; + if ((flags & BFS_STAT_NOFOLLOW) || ftwbuf->type != BFTW_LNK) { + return ftwbuf->type; } - } else if ((flags & (BFS_STAT_NOFOLLOW | BFS_STAT_TRYFOLLOW)) == BFS_STAT_TRYFOLLOW || ftwbuf->typeflag == BFTW_LNK) { - return ftwbuf->typeflag; + } else if ((flags & (BFS_STAT_NOFOLLOW | BFS_STAT_TRYFOLLOW)) == BFS_STAT_TRYFOLLOW || ftwbuf->type == BFTW_LNK) { + return ftwbuf->type; } const struct bfs_stat *statbuf = bftw_stat(ftwbuf, flags); if (statbuf) { - return bftw_mode_typeflag(statbuf->mode); + return bftw_mode_to_type(statbuf->mode); } else { return BFTW_ERROR; } @@ -934,15 +934,15 @@ static bool bftw_need_stat(const struct bftw_state *state) { } const struct BFTW *ftwbuf = &state->ftwbuf; - if (ftwbuf->typeflag == BFTW_UNKNOWN) { + if (ftwbuf->type == BFTW_UNKNOWN) { return true; } - if (ftwbuf->typeflag == BFTW_LNK && !(ftwbuf->stat_flags & BFS_STAT_NOFOLLOW)) { + if (ftwbuf->type == BFTW_LNK && !(ftwbuf->stat_flags & BFS_STAT_NOFOLLOW)) { return true; } - if (ftwbuf->typeflag == BFTW_DIR) { + if (ftwbuf->type == BFTW_DIR) { if (state->flags & (BFTW_DETECT_CYCLES | BFTW_MOUNT | BFTW_XDEV)) { return true; } @@ -1007,7 +1007,7 @@ static void bftw_init_ftwbuf(struct bftw_state *state, enum bftw_visit visit) { ftwbuf->root = file ? file->root->name : ftwbuf->path; ftwbuf->depth = 0; ftwbuf->visit = visit; - ftwbuf->typeflag = BFTW_UNKNOWN; + ftwbuf->type = BFTW_UNKNOWN; ftwbuf->error = reader->error; ftwbuf->at_fd = AT_FDCWD; ftwbuf->at_path = ftwbuf->path; @@ -1019,12 +1019,12 @@ static void bftw_init_ftwbuf(struct bftw_state *state, enum bftw_visit visit) { if (de) { parent = file; ftwbuf->depth = file->depth + 1; - ftwbuf->typeflag = bftw_dirent_typeflag(de); + ftwbuf->type = bftw_dirent_type(de); ftwbuf->nameoff = bftw_child_nameoff(file); } else if (file) { parent = file->parent; ftwbuf->depth = file->depth; - ftwbuf->typeflag = file->typeflag; + ftwbuf->type = file->type; ftwbuf->nameoff = file->nameoff; } @@ -1044,7 +1044,7 @@ static void bftw_init_ftwbuf(struct bftw_state *state, enum bftw_visit visit) { } if (ftwbuf->error != 0) { - ftwbuf->typeflag = BFTW_ERROR; + ftwbuf->type = BFTW_ERROR; return; } @@ -1061,18 +1061,18 @@ static void bftw_init_ftwbuf(struct bftw_state *state, enum bftw_visit visit) { if (bftw_need_stat(state)) { statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags); if (statbuf) { - ftwbuf->typeflag = bftw_mode_typeflag(statbuf->mode); + ftwbuf->type = bftw_mode_to_type(statbuf->mode); } else { - ftwbuf->typeflag = BFTW_ERROR; + ftwbuf->type = BFTW_ERROR; ftwbuf->error = errno; return; } } - if (ftwbuf->typeflag == BFTW_DIR && (state->flags & BFTW_DETECT_CYCLES)) { + if (ftwbuf->type == BFTW_DIR && (state->flags & BFTW_DETECT_CYCLES)) { for (const struct bftw_file *ancestor = parent; ancestor; ancestor = ancestor->parent) { if (ancestor->dev == statbuf->dev && ancestor->ino == statbuf->ino) { - ftwbuf->typeflag = BFTW_ERROR; + ftwbuf->type = BFTW_ERROR; ftwbuf->error = ELOOP; return; } @@ -1122,7 +1122,7 @@ static enum bftw_action bftw_visit(struct bftw_state *state, const char *name, e bftw_init_ftwbuf(state, visit); // Never give the callback BFTW_ERROR unless BFTW_RECOVER is specified - if (ftwbuf->typeflag == BFTW_ERROR && !(state->flags & BFTW_RECOVER)) { + if (ftwbuf->type == BFTW_ERROR && !(state->flags & BFTW_RECOVER)) { state->error = ftwbuf->error; return BFTW_STOP; } @@ -1143,7 +1143,7 @@ static enum bftw_action bftw_visit(struct bftw_state *state, const char *name, e return BFTW_STOP; } - if (visit != BFTW_PRE || ftwbuf->typeflag != BFTW_DIR) { + if (visit != BFTW_PRE || ftwbuf->type != BFTW_DIR) { ret = BFTW_PRUNE; goto done; } @@ -1174,7 +1174,7 @@ static int bftw_push(struct bftw_state *state, const char *name, bool fill_id) { struct dirent *de = state->reader.de; if (de) { - file->typeflag = bftw_dirent_typeflag(de); + file->type = bftw_dirent_type(de); } if (fill_id) { @@ -1523,7 +1523,7 @@ static enum bftw_action bftw_ids_callback(const struct BFTW *ftwbuf, void *ptr) mutbuf->visit = state->visit; } - if (ftwbuf->typeflag == BFTW_ERROR) { + if (ftwbuf->type == BFTW_ERROR) { if (ftwbuf->depth + 1 >= state->min_depth) { return state->delegate(ftwbuf, state->ptr); } else { @@ -1550,13 +1550,13 @@ static enum bftw_action bftw_ids_callback(const struct BFTW *ftwbuf, void *ptr) switch (ret) { case BFTW_CONTINUE: - if (ftwbuf->typeflag == BFTW_DIR && ftwbuf->depth + 1 >= state->max_depth) { + if (ftwbuf->type == BFTW_DIR && ftwbuf->depth + 1 >= state->max_depth) { state->bottom = false; ret = BFTW_PRUNE; } break; case BFTW_PRUNE: - if (ftwbuf->typeflag == BFTW_DIR) { + if (ftwbuf->type == BFTW_DIR) { if (!trie_insert_str(&state->pruned, ftwbuf->path)) { state->error = errno; state->quit = true; diff --git a/bftw.h b/bftw.h index 4aecaf7..4bd9811 100644 --- a/bftw.h +++ b/bftw.h @@ -29,37 +29,37 @@ /** * Possible file types. */ -enum bftw_typeflag { +enum bftw_type { + /** An error occurred for this file. */ + BFTW_ERROR = -1, /** Unknown type. */ - BFTW_UNKNOWN = 0, + BFTW_UNKNOWN, /** Block device. */ - BFTW_BLK = 1 << 0, + BFTW_BLK, /** Character device. */ - BFTW_CHR = 1 << 1, + BFTW_CHR, /** Directory. */ - BFTW_DIR = 1 << 2, + BFTW_DIR, /** Solaris door. */ - BFTW_DOOR = 1 << 3, + BFTW_DOOR, /** Pipe. */ - BFTW_FIFO = 1 << 4, + BFTW_FIFO, /** Symbolic link. */ - BFTW_LNK = 1 << 5, + BFTW_LNK, /** Solaris event port. */ - BFTW_PORT = 1 << 6, + BFTW_PORT, /** Regular file. */ - BFTW_REG = 1 << 7, + BFTW_REG, /** Socket. */ - BFTW_SOCK = 1 << 8, + BFTW_SOCK, /** BSD whiteout. */ - BFTW_WHT = 1 << 9, - /** An error occurred for this file. */ - BFTW_ERROR = 1 << 10, + BFTW_WHT, }; /** - * Convert a bfs_stat() mode to a bftw() typeflag. + * Convert a bfs_stat() mode to a bftw_type. */ -enum bftw_typeflag bftw_mode_typeflag(mode_t mode); +enum bftw_type bftw_mode_to_type(mode_t mode); /** * Possible visit occurrences. @@ -100,8 +100,8 @@ struct BFTW { enum bftw_visit visit; /** The file type. */ - enum bftw_typeflag typeflag; - /** The errno that occurred, if typeflag == BFTW_ERROR. */ + enum bftw_type type; + /** The errno that occurred, if type == BFTW_ERROR. */ int error; /** A parent file descriptor for the *at() family of calls. */ @@ -142,7 +142,7 @@ const struct bfs_stat *bftw_stat(const struct BFTW *ftwbuf, enum bfs_stat_flag f * @return * The type of the file, or BFTW_ERROR if an error occurred. */ -enum bftw_typeflag bftw_typeflag(const struct BFTW *ftwbuf, enum bfs_stat_flag flags); +enum bftw_type bftw_type(const struct BFTW *ftwbuf, enum bfs_stat_flag flags); /** * Walk actions returned by the bftw() callback. diff --git a/color.c b/color.c index cfb3f47..11684ef 100644 --- a/color.c +++ b/color.c @@ -557,15 +557,15 @@ static bool is_link_broken(const struct BFTW *ftwbuf) { /** Get the color for a file. */ static const char *file_color(const struct colors *colors, const char *filename, const struct BFTW *ftwbuf, enum bfs_stat_flag flags) { - enum bftw_typeflag typeflag = bftw_typeflag(ftwbuf, flags); - if (typeflag == BFTW_ERROR) { + enum bftw_type type = bftw_type(ftwbuf, flags); + if (type == BFTW_ERROR) { goto error; } const struct bfs_stat *statbuf = NULL; const char *color = NULL; - switch (typeflag) { + switch (type) { case BFTW_REG: if (colors->setuid || colors->setgid || colors->executable || colors->multi_hard) { statbuf = bftw_stat(ftwbuf, flags); @@ -719,7 +719,7 @@ static int print_colored(const struct colors *colors, const char *esc, const cha static ssize_t first_broken_offset(const char *path, const struct BFTW *ftwbuf, enum bfs_stat_flag flags, size_t max) { ssize_t ret = max; - if (bftw_typeflag(ftwbuf, flags) != BFTW_ERROR) { + if (bftw_type(ftwbuf, flags) != BFTW_ERROR) { goto out; } @@ -830,7 +830,7 @@ static int print_path(CFILE *cfile, const struct BFTW *ftwbuf) { } enum bfs_stat_flag flags = ftwbuf->stat_flags; - if (colors && colors->link_as_target && ftwbuf->typeflag == BFTW_LNK) { + if (colors && colors->link_as_target && ftwbuf->type == BFTW_LNK) { flags = BFS_STAT_TRYFOLLOW; } diff --git a/eval.c b/eval.c index 5885fb8..5475f87 100644 --- a/eval.c +++ b/eval.c @@ -324,7 +324,7 @@ bool eval_delete(const struct expr *expr, struct eval_state *state) { int flag = 0; // We need to know the actual type of the path, not what it points to - enum bftw_typeflag type = bftw_typeflag(ftwbuf, BFS_STAT_NOFOLLOW); + enum bftw_type type = bftw_type(ftwbuf, BFS_STAT_NOFOLLOW); if (type == BFTW_DIR) { flag |= AT_REMOVEDIR; } else if (type == BFTW_ERROR) { @@ -394,7 +394,7 @@ bool eval_empty(const struct expr *expr, struct eval_state *state) { bool ret = false; const struct BFTW *ftwbuf = state->ftwbuf; - if (ftwbuf->typeflag == BFTW_DIR) { + if (ftwbuf->type == BFTW_DIR) { int dfd = openat(ftwbuf->at_fd, ftwbuf->at_path, O_RDONLY | O_CLOEXEC | O_DIRECTORY); if (dfd < 0) { eval_report_error(state); @@ -416,7 +416,7 @@ bool eval_empty(const struct expr *expr, struct eval_state *state) { } closedir(dir); - } else if (ftwbuf->typeflag == BFTW_REG) { + } else if (ftwbuf->type == BFTW_REG) { const struct bfs_stat *statbuf = eval_stat(state); if (statbuf) { ret = statbuf->size == 0; @@ -480,7 +480,7 @@ bool eval_lname(const struct expr *expr, struct eval_state *state) { char *name = NULL; const struct BFTW *ftwbuf = state->ftwbuf; - if (ftwbuf->typeflag != BFTW_LNK) { + if (ftwbuf->type != BFTW_LNK) { goto done; } @@ -548,7 +548,7 @@ bool eval_perm(const struct expr *expr, struct eval_state *state) { mode_t mode = statbuf->mode; mode_t target; - if (state->ftwbuf->typeflag == BFTW_DIR) { + if (state->ftwbuf->type == BFTW_DIR) { target = expr->dir_mode; } else { target = expr->file_mode; @@ -616,7 +616,7 @@ bool eval_fls(const struct expr *expr, struct eval_state *state) { } } - if (ftwbuf->typeflag & (BFTW_BLK | BFTW_CHR)) { + if (ftwbuf->type == BFTW_BLK || ftwbuf->type == BFTW_CHR) { int ma = bfs_major(statbuf->rdev); int mi = bfs_minor(statbuf->rdev); if (fprintf(file, " %3d, %3d", ma, mi) < 0) { @@ -654,7 +654,7 @@ bool eval_fls(const struct expr *expr, struct eval_state *state) { goto error; } - if (ftwbuf->typeflag == BFTW_LNK) { + if (ftwbuf->type == BFTW_LNK) { if (cfprintf(cfile, " -> %pL", ftwbuf) < 0) { goto error; } @@ -847,7 +847,7 @@ bool eval_sparse(const struct expr *expr, struct eval_state *state) { * -type test. */ bool eval_type(const struct expr *expr, struct eval_state *state) { - return state->ftwbuf->typeflag & expr->idata; + return (1 << state->ftwbuf->type) & expr->idata; } /** @@ -869,12 +869,12 @@ bool eval_xattr(const struct expr *expr, struct eval_state *state) { bool eval_xtype(const struct expr *expr, struct eval_state *state) { const struct BFTW *ftwbuf = state->ftwbuf; enum bfs_stat_flag flags = ftwbuf->stat_flags ^ (BFS_STAT_NOFOLLOW | BFS_STAT_TRYFOLLOW); - enum bftw_typeflag type = bftw_typeflag(ftwbuf, flags); + enum bftw_type type = bftw_type(ftwbuf, flags); if (type == BFTW_ERROR) { eval_report_error(state); return false; } else { - return type & expr->idata; + return (1 << type) & expr->idata; } } @@ -1087,35 +1087,33 @@ static void debug_stats(const struct cmdline *cmdline, const struct BFTW *ftwbuf } } -/** - * Dump the bftw_typeflag for -D search. - */ -static const char *dump_bftw_typeflag(enum bftw_typeflag type) { -#define DUMP_BFTW_TYPEFLAG_CASE(flag) \ - case flag: \ - return #flag - - switch (type) { - DUMP_BFTW_TYPEFLAG_CASE(BFTW_BLK); - DUMP_BFTW_TYPEFLAG_CASE(BFTW_CHR); - DUMP_BFTW_TYPEFLAG_CASE(BFTW_DIR); - DUMP_BFTW_TYPEFLAG_CASE(BFTW_DOOR); - DUMP_BFTW_TYPEFLAG_CASE(BFTW_FIFO); - DUMP_BFTW_TYPEFLAG_CASE(BFTW_LNK); - DUMP_BFTW_TYPEFLAG_CASE(BFTW_PORT); - DUMP_BFTW_TYPEFLAG_CASE(BFTW_REG); - DUMP_BFTW_TYPEFLAG_CASE(BFTW_SOCK); - DUMP_BFTW_TYPEFLAG_CASE(BFTW_WHT); +#define DUMP_BFTW_MAP(value) [value] = #value - DUMP_BFTW_TYPEFLAG_CASE(BFTW_ERROR); +/** + * Dump the bftw_type for -D search. + */ +static const char *dump_bftw_type(enum bftw_type type) { + static const char *types[] = { + DUMP_BFTW_MAP(BFTW_UNKNOWN), + DUMP_BFTW_MAP(BFTW_BLK), + DUMP_BFTW_MAP(BFTW_CHR), + DUMP_BFTW_MAP(BFTW_DIR), + DUMP_BFTW_MAP(BFTW_DOOR), + DUMP_BFTW_MAP(BFTW_FIFO), + DUMP_BFTW_MAP(BFTW_LNK), + DUMP_BFTW_MAP(BFTW_PORT), + DUMP_BFTW_MAP(BFTW_REG), + DUMP_BFTW_MAP(BFTW_SOCK), + DUMP_BFTW_MAP(BFTW_WHT), + }; - default: - DUMP_BFTW_TYPEFLAG_CASE(BFTW_UNKNOWN); + if (type == BFTW_ERROR) { + return "BFTW_ERROR"; + } else { + return types[type]; } } -#define DUMP_BFTW_MAP(value) [value] = #value - /** * Dump the bftw_visit for -D search. */ @@ -1166,7 +1164,7 @@ static enum bftw_action cmdline_callback(const struct BFTW *ftwbuf, void *ptr) { state.ret = &args->ret; state.quit = false; - if (ftwbuf->typeflag == BFTW_ERROR) { + if (ftwbuf->type == BFTW_ERROR) { if (!eval_should_ignore(&state, ftwbuf->error)) { args->ret = EXIT_FAILURE; eval_error(&state, "%s.\n", strerror(ftwbuf->error)); @@ -1200,7 +1198,7 @@ static enum bftw_action cmdline_callback(const struct BFTW *ftwbuf, void *ptr) { // In -depth mode, only handle directories on the BFTW_POST visit enum bftw_visit expected_visit = BFTW_PRE; if ((cmdline->flags & BFTW_DEPTH) - && (cmdline->strategy == BFTW_IDS || ftwbuf->typeflag == BFTW_DIR) + && (cmdline->strategy == BFTW_IDS || ftwbuf->type == BFTW_DIR) && ftwbuf->depth < cmdline->maxdepth) { expected_visit = BFTW_POST; } @@ -1219,7 +1217,7 @@ done: fprintf(stderr, "\t.root = \"%s\",\n", ftwbuf->root); fprintf(stderr, "\t.depth = %zu,\n", ftwbuf->depth); fprintf(stderr, "\t.visit = %s,\n", dump_bftw_visit(ftwbuf->visit)); - fprintf(stderr, "\t.typeflag = %s,\n", dump_bftw_typeflag(ftwbuf->typeflag)); + fprintf(stderr, "\t.type = %s,\n", dump_bftw_type(ftwbuf->type)); fprintf(stderr, "\t.error = %d,\n", ftwbuf->error); fprintf(stderr, "}) == %s\n", dump_bftw_action(state.action)); } diff --git a/fsade.c b/fsade.c index a4c50ee..acd39bb 100644 --- a/fsade.c +++ b/fsade.c @@ -199,7 +199,7 @@ int bfs_check_acl(const struct BFTW *ftwbuf) { }; static const size_t n_acl_types = sizeof(acl_types)/sizeof(acl_types[0]); - if (ftwbuf->typeflag == BFTW_LNK) { + if (ftwbuf->type == BFTW_LNK) { return 0; } @@ -209,7 +209,7 @@ int bfs_check_acl(const struct BFTW *ftwbuf) { for (size_t i = 0; i < n_acl_types && ret <= 0; ++i) { acl_type_t type = acl_types[i]; - if (type == ACL_TYPE_DEFAULT && ftwbuf->typeflag != BFTW_DIR) { + if (type == ACL_TYPE_DEFAULT && ftwbuf->type != BFTW_DIR) { // ACL_TYPE_DEFAULT is supported only for directories, // otherwise acl_get_file() gives EACCESS continue; @@ -246,7 +246,7 @@ int bfs_check_acl(const struct BFTW *ftwbuf) { #if BFS_CAN_CHECK_CAPABILITIES int bfs_check_capabilities(const struct BFTW *ftwbuf) { - if (ftwbuf->typeflag == BFTW_LNK) { + if (ftwbuf->type == BFTW_LNK) { return 0; } @@ -297,17 +297,17 @@ int bfs_check_xattrs(const struct BFTW *ftwbuf) { #if BFS_HAS_SYS_EXTATTR ssize_t (*extattr_list)(const char *, int, void*, size_t) = - ftwbuf->typeflag == BFTW_LNK ? extattr_list_link : extattr_list_file; + ftwbuf->type == BFTW_LNK ? extattr_list_link : extattr_list_file; len = extattr_list(path, EXTATTR_NAMESPACE_SYSTEM, NULL, 0); if (len <= 0) { len = extattr_list(path, EXTATTR_NAMESPACE_USER, NULL, 0); } #elif __APPLE__ - int options = ftwbuf->typeflag == BFTW_LNK ? XATTR_NOFOLLOW : 0; + int options = ftwbuf->type == BFTW_LNK ? XATTR_NOFOLLOW : 0; len = listxattr(path, NULL, 0, options); #else - if (ftwbuf->typeflag == BFTW_LNK) { + if (ftwbuf->type == BFTW_LNK) { len = llistxattr(path, NULL, 0); } else { len = listxattr(path, NULL, 0); diff --git a/opt.c b/opt.c index 65520dd..458106f 100644 --- a/opt.c +++ b/opt.c @@ -226,9 +226,9 @@ struct opt_facts { enum known_pred preds[PRED_TYPES]; /** Bitmask of possible file types. */ - enum bftw_typeflag types; + unsigned int types; /** Bitmask of possible link target types. */ - enum bftw_typeflag xtypes; + unsigned int xtypes; }; /** Initialize some data flow facts. */ diff --git a/parse.c b/parse.c index f990a69..3e54ef6 100644 --- a/parse.c +++ b/parse.c @@ -2388,12 +2388,12 @@ static struct expr *parse_type(struct parser_state *state, int x, int arg2) { return NULL; } - enum bftw_typeflag types = 0; + unsigned int types = 0; double probability = 0.0; const char *c = expr->sdata; while (true) { - enum bftw_typeflag type; + enum bftw_type type; double type_prob; switch (*c) { @@ -2444,8 +2444,9 @@ static struct expr *parse_type(struct parser_state *state, int x, int arg2) { goto fail; } - if (!(types & type)) { - types |= type; + unsigned int flag = 1 << type; + if (!(types & flag)) { + types |= flag; probability += type_prob; } diff --git a/printf.c b/printf.c index 18ea5ff..b9149f3 100644 --- a/printf.c +++ b/printf.c @@ -306,7 +306,7 @@ static int bfs_printf_k(FILE *file, const struct bfs_printf *directive, const st /** %l: link target */ static int bfs_printf_l(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) { - if (ftwbuf->typeflag != BFTW_LNK) { + if (ftwbuf->type != BFTW_LNK) { return 0; } @@ -421,8 +421,8 @@ static int bfs_printf_u(FILE *file, const struct bfs_printf *directive, const st return fprintf(file, directive->str, pwd->pw_name); } -static const char *bfs_printf_type(enum bftw_typeflag typeflag) { - switch (typeflag) { +static const char *bfs_printf_type(enum bftw_type type) { + switch (type) { case BFTW_BLK: return "b"; case BFTW_CHR: @@ -446,7 +446,7 @@ static const char *bfs_printf_type(enum bftw_typeflag typeflag) { /** %y: type */ static int bfs_printf_y(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) { - const char *type = bfs_printf_type(ftwbuf->typeflag); + const char *type = bfs_printf_type(ftwbuf->type); return fprintf(file, directive->str, type); } @@ -454,7 +454,7 @@ static int bfs_printf_y(FILE *file, const struct bfs_printf *directive, const st static int bfs_printf_Y(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) { int error = 0; - if (ftwbuf->typeflag != BFTW_LNK) { + if (ftwbuf->type != BFTW_LNK) { return bfs_printf_y(file, directive, ftwbuf); } @@ -462,7 +462,7 @@ static int bfs_printf_Y(FILE *file, const struct bfs_printf *directive, const st const struct bfs_stat *statbuf = bftw_stat(ftwbuf, BFS_STAT_FOLLOW); if (statbuf) { - type = bfs_printf_type(bftw_mode_typeflag(statbuf->mode)); + type = bfs_printf_type(bftw_mode_to_type(statbuf->mode)); } else { switch (errno) { case ELOOP: diff --git a/util.c b/util.c index ec019ce..0ac1f7a 100644 --- a/util.c +++ b/util.c @@ -166,7 +166,7 @@ char *xregerror(int err, const regex_t *regex) { void format_mode(mode_t mode, char str[11]) { strcpy(str, "----------"); - switch (bftw_mode_typeflag(mode)) { + switch (bftw_mode_to_type(mode)) { case BFTW_REG: break; case BFTW_BLK: -- cgit v1.2.3