summaryrefslogtreecommitdiffstats
path: root/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2019-02-12 17:36:31 -0500
committerTavian Barnes <tavianator@tavianator.com>2019-03-06 22:28:25 -0800
commit7fc960a23eab7fce9f5e0666b1a9b3f5eae832af (patch)
tree440adf2f92ab6e7dbd0540afab05b6e4c0d6810f /bftw.c
parentb1d0e0e97ce747534a945a6fe0c3a15ccd8dbf00 (diff)
downloadbfs-7fc960a23eab7fce9f5e0666b1a9b3f5eae832af.tar.xz
bftw: Switch from taking separate parameters to a parameters struct
Diffstat (limited to 'bftw.c')
-rw-r--r--bftw.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/bftw.c b/bftw.c
index 118a441..6795bd0 100644
--- a/bftw.c
+++ b/bftw.c
@@ -764,11 +764,11 @@ static int bftw_stat(struct BFTW *ftwbuf, struct bfs_stat *sb) {
*/
struct bftw_state {
/** bftw() callback. */
- bftw_fn *fn;
- /** bftw() flags. */
- int flags;
+ bftw_callback *callback;
/** bftw() callback data. */
void *ptr;
+ /** bftw() flags. */
+ enum bftw_flags flags;
/** The appropriate errno value, if any. */
int error;
@@ -795,21 +795,21 @@ struct bftw_state {
/**
* Initialize the bftw() state.
*/
-static int bftw_state_init(struct bftw_state *state, const char *root, bftw_fn *fn, int nopenfd, int flags, void *ptr) {
+static int bftw_state_init(struct bftw_state *state, const char *root, const struct bftw_args *args) {
state->root = root;
- state->fn = fn;
- state->flags = flags;
- state->ptr = ptr;
+ state->callback = args->callback;
+ state->ptr = args->ptr;
+ state->flags = args->flags;
state->error = 0;
- if (nopenfd < 2) {
+ if (args->nopenfd < 2) {
errno = EMFILE;
goto err;
}
// -1 to account for dup()
- if (bftw_cache_init(&state->cache, nopenfd - 1) != 0) {
+ if (bftw_cache_init(&state->cache, args->nopenfd - 1) != 0) {
goto err;
}
@@ -972,7 +972,7 @@ static enum bftw_action bftw_visit_path(struct bftw_state *state) {
// Defensive copy
struct BFTW ftwbuf = state->ftwbuf;
- enum bftw_action action = state->fn(&ftwbuf, state->ptr);
+ enum bftw_action action = state->callback(&ftwbuf, state->ptr);
switch (action) {
case BFTW_CONTINUE:
case BFTW_SKIP_SIBLINGS:
@@ -1113,9 +1113,9 @@ static int bftw_state_destroy(struct bftw_state *state) {
}
}
-int bftw(const char *path, bftw_fn *fn, int nopenfd, enum bftw_flags flags, void *ptr) {
+int bftw(const char *path, const struct bftw_args *args) {
struct bftw_state state;
- if (bftw_state_init(&state, path, fn, nopenfd, flags, ptr) != 0) {
+ if (bftw_state_init(&state, path, args) != 0) {
return -1;
}
@@ -1163,7 +1163,7 @@ int bftw(const char *path, bftw_fn *fn, int nopenfd, enum bftw_flags flags, void
if (state.ftwbuf.typeflag == BFTW_DIR) {
const struct bfs_stat *statbuf = state.ftwbuf.statbuf;
- if ((flags & BFTW_XDEV)
+ if ((args->flags & BFTW_XDEV)
&& statbuf
&& statbuf->dev != reader->dir->dev) {
goto read;