summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2019-05-05 15:46:55 -0400
committerTavian Barnes <tavianator@tavianator.com>2019-05-05 22:56:27 -0400
commitdf7d960b0d7e1f9bd8aa58654760e41b6282f78a (patch)
tree9fc241b2fd0924cacc61c91eed8cb69b6874d764
parent690d0467d1cb98247b72ee570dc49b225d63a5ec (diff)
downloadbfs-df7d960b0d7e1f9bd8aa58654760e41b6282f78a.tar.xz
bftw: Pass a const struct BFTW * to the callback
-rw-r--r--bftw.c61
-rw-r--r--bftw.h6
-rw-r--r--color.c12
-rw-r--r--color.h4
-rw-r--r--eval.c24
-rw-r--r--printf.c58
-rw-r--r--printf.h2
7 files changed, 84 insertions, 83 deletions
diff --git a/bftw.c b/bftw.c
index 98ed341..2313fec 100644
--- a/bftw.c
+++ b/bftw.c
@@ -764,26 +764,27 @@ static const struct bfs_stat *bftw_stat_impl(struct BFTW *ftwbuf, struct bftw_st
return cache->buf;
}
-const struct bfs_stat *bftw_stat(struct BFTW *ftwbuf, enum bfs_stat_flag flags) {
+const struct bfs_stat *bftw_stat(const struct BFTW *ftwbuf, enum bfs_stat_flag flags) {
+ struct BFTW *mutbuf = (struct BFTW *)ftwbuf;
const struct bfs_stat *ret;
if (flags & BFS_STAT_NOFOLLOW) {
- ret = bftw_stat_impl(ftwbuf, &ftwbuf->lstat_cache, BFS_STAT_NOFOLLOW);
- if (ret && !S_ISLNK(ret->mode) && !ftwbuf->stat_cache.buf) {
+ ret = bftw_stat_impl(mutbuf, &mutbuf->lstat_cache, BFS_STAT_NOFOLLOW);
+ if (ret && !S_ISLNK(ret->mode) && !mutbuf->stat_cache.buf) {
// Non-link, so share stat info
- ftwbuf->stat_cache.buf = ret;
+ mutbuf->stat_cache.buf = ret;
}
} else {
- ret = bftw_stat_impl(ftwbuf, &ftwbuf->stat_cache, BFS_STAT_FOLLOW);
+ ret = bftw_stat_impl(mutbuf, &mutbuf->stat_cache, BFS_STAT_FOLLOW);
if (!ret && (flags & BFS_STAT_TRYFOLLOW) && is_nonexistence_error(errno)) {
- ret = bftw_stat_impl(ftwbuf, &ftwbuf->lstat_cache, BFS_STAT_NOFOLLOW);
+ ret = bftw_stat_impl(mutbuf, &mutbuf->lstat_cache, BFS_STAT_NOFOLLOW);
}
}
return ret;
}
-enum bftw_typeflag bftw_typeflag(struct BFTW *ftwbuf, enum bfs_stat_flag flags) {
+enum bftw_typeflag bftw_typeflag(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;
@@ -911,7 +912,7 @@ static bool bftw_need_stat(struct bftw_state *state) {
return true;
}
- struct BFTW *ftwbuf = &state->ftwbuf;
+ const struct BFTW *ftwbuf = &state->ftwbuf;
if (ftwbuf->typeflag == BFTW_UNKNOWN) {
return true;
}
@@ -1036,7 +1037,8 @@ static void bftw_prepare_visit(struct bftw_state *state) {
* Invoke the callback.
*/
static enum bftw_action bftw_visit_path(struct bftw_state *state) {
- if (state->reader.dir) {
+ const struct bftw_dir *dir = state->reader.dir;
+ if (dir) {
if (bftw_update_path(state) != 0) {
state->error = errno;
return BFTW_STOP;
@@ -1045,18 +1047,19 @@ static enum bftw_action bftw_visit_path(struct bftw_state *state) {
bftw_prepare_visit(state);
+ const struct BFTW *ftwbuf = &state->ftwbuf;
+
// Never give the callback BFTW_ERROR unless BFTW_RECOVER is specified
- if (state->ftwbuf.typeflag == BFTW_ERROR && !(state->flags & BFTW_RECOVER)) {
- state->error = state->ftwbuf.error;
+ if (ftwbuf->typeflag == BFTW_ERROR && !(state->flags & BFTW_RECOVER)) {
+ state->error = ftwbuf->error;
return BFTW_STOP;
}
- // Defensive copy
- struct BFTW ftwbuf = state->ftwbuf;
-
- enum bftw_action action = state->callback(&ftwbuf, state->ptr);
+ enum bftw_action action = state->callback(ftwbuf, state->ptr);
switch (action) {
case BFTW_CONTINUE:
+ break;
+
case BFTW_SKIP_SIBLINGS:
case BFTW_SKIP_SUBTREE:
case BFTW_STOP:
@@ -1066,6 +1069,19 @@ static enum bftw_action bftw_visit_path(struct bftw_state *state) {
state->error = EINVAL;
return BFTW_STOP;
}
+
+ if (state->visit != BFTW_PRE || ftwbuf->typeflag != BFTW_DIR) {
+ return BFTW_SKIP_SUBTREE;
+ }
+
+ if (state->flags & BFTW_XDEV) {
+ const struct bfs_stat *statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags);
+ if (statbuf && dir && statbuf->dev != dir->dev) {
+ return BFTW_SKIP_SUBTREE;
+ }
+ }
+
+ return BFTW_CONTINUE;
}
/**
@@ -1214,10 +1230,6 @@ int bftw(const char *path, const struct bftw_args *args) {
break;
}
- if (state.ftwbuf.typeflag != BFTW_DIR) {
- goto done;
- }
-
// Now start the breadth-first search
if (bftw_push(&state, path) != 0) {
@@ -1247,17 +1259,6 @@ int bftw(const char *path, const struct bftw_args *args) {
goto done;
}
- if (state.ftwbuf.typeflag != BFTW_DIR) {
- goto read;
- }
-
- if (args->flags & BFTW_XDEV) {
- const struct bfs_stat *statbuf = bftw_stat(&state.ftwbuf, state.ftwbuf.stat_flags);
- if (statbuf && statbuf->dev != reader->dir->dev) {
- goto read;
- }
- }
-
if (bftw_push(&state, name) != 0) {
goto done;
}
diff --git a/bftw.h b/bftw.h
index 626a6d8..568db9a 100644
--- a/bftw.h
+++ b/bftw.h
@@ -127,7 +127,7 @@ struct BFTW {
* @return
* A pointer to a bfs_stat() buffer, or NULL if the call failed.
*/
-const struct bfs_stat *bftw_stat(struct BFTW *ftwbuf, enum bfs_stat_flag flags);
+const struct bfs_stat *bftw_stat(const struct BFTW *ftwbuf, enum bfs_stat_flag flags);
/**
* Get the type of a file encountered during bftw(), with flags controlling
@@ -141,7 +141,7 @@ const struct bfs_stat *bftw_stat(struct BFTW *ftwbuf, enum bfs_stat_flag flags);
* @return
* The type of the file, or BFTW_ERROR if an error occurred.
*/
-enum bftw_typeflag bftw_typeflag(struct BFTW *ftwbuf, enum bfs_stat_flag flags);
+enum bftw_typeflag bftw_typeflag(const struct BFTW *ftwbuf, enum bfs_stat_flag flags);
/**
* Walk actions returned by the bftw() callback.
@@ -167,7 +167,7 @@ enum bftw_action {
* @return
* An action value.
*/
-typedef enum bftw_action bftw_callback(struct BFTW *ftwbuf, void *ptr);
+typedef enum bftw_action bftw_callback(const struct BFTW *ftwbuf, void *ptr);
/**
* Flags that control bftw() behavior.
diff --git a/color.c b/color.c
index 188e7ed..cf507fd 100644
--- a/color.c
+++ b/color.c
@@ -550,7 +550,7 @@ 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, struct BFTW *ftwbuf, enum bfs_stat_flag flags) {
+static const char *file_color(const struct colors *colors, const char *filename, const struct BFTW *ftwbuf, enum bfs_stat_flag flags) {
const struct bfs_stat *sb = bftw_stat(ftwbuf, flags);
if (!sb) {
if (colors->missing) {
@@ -692,7 +692,7 @@ static int print_colored(const struct colors *colors, const char *esc, const cha
}
/** Print a path with colors. */
-static int print_path_colored(CFILE *cfile, const char *path, struct BFTW *ftwbuf, enum bfs_stat_flag flags) {
+static int print_path_colored(CFILE *cfile, const char *path, const struct BFTW *ftwbuf, enum bfs_stat_flag flags) {
const struct colors *colors = cfile->colors;
FILE *file = cfile->file;
@@ -715,7 +715,7 @@ static int print_path_colored(CFILE *cfile, const char *path, struct BFTW *ftwbu
}
/** Print the path to a file with the appropriate colors. */
-static int print_path(CFILE *cfile, struct BFTW *ftwbuf) {
+static int print_path(CFILE *cfile, const struct BFTW *ftwbuf) {
const struct colors *colors = cfile->colors;
if (!colors) {
return fputs(ftwbuf->path, cfile->file) == EOF ? -1 : 0;
@@ -730,7 +730,7 @@ static int print_path(CFILE *cfile, struct BFTW *ftwbuf) {
}
/** Print a link target with the appropriate colors. */
-static int print_link_target(CFILE *cfile, struct BFTW *ftwbuf) {
+static int print_link_target(CFILE *cfile, const struct BFTW *ftwbuf) {
int ret = -1;
size_t len = 0;
@@ -828,13 +828,13 @@ int cvfprintf(CFILE *cfile, const char *format, va_list args) {
case 'p':
switch (*++i) {
case 'P':
- if (print_path(cfile, va_arg(args, struct BFTW *)) != 0) {
+ if (print_path(cfile, va_arg(args, const struct BFTW *)) != 0) {
return -1;
}
break;
case 'L':
- if (print_link_target(cfile, va_arg(args, struct BFTW *)) != 0) {
+ if (print_link_target(cfile, va_arg(args, const struct BFTW *)) != 0) {
return -1;
}
break;
diff --git a/color.h b/color.h
index 946358a..7df3785 100644
--- a/color.h
+++ b/color.h
@@ -106,8 +106,8 @@ int cfclose(CFILE *cfile);
* %s: A string
* %zu: A size_t
* %m: strerror(errno)
- * %pP: A colored file path, from a struct BFTW * argument
- * %pL: A colored link target, from a struct BFTW * argument
+ * %pP: A colored file path, from a const struct BFTW * argument
+ * %pL: A colored link target, from a const struct BFTW * argument
* %%: A literal '%'
* ${cc}: Change the color to 'cc'
* $$: A literal '$'
diff --git a/eval.c b/eval.c
index 3bcdfeb..0c4f9a9 100644
--- a/eval.c
+++ b/eval.c
@@ -50,7 +50,7 @@
struct eval_state {
/** Data about the current file. */
- struct BFTW *ftwbuf;
+ const struct BFTW *ftwbuf;
/** The parsed command line. */
const struct cmdline *cmdline;
/** The bftw() callback return value. */
@@ -102,7 +102,7 @@ static void eval_report_error(struct eval_state *state) {
* Perform a bfs_stat() call if necessary.
*/
static const struct bfs_stat *eval_stat(struct eval_state *state) {
- struct BFTW *ftwbuf = state->ftwbuf;
+ const struct BFTW *ftwbuf = state->ftwbuf;
const struct bfs_stat *ret = bftw_stat(ftwbuf, ftwbuf->stat_flags);
if (!ret) {
eval_report_error(state);
@@ -152,7 +152,7 @@ bool eval_false(const struct expr *expr, struct eval_state *state) {
* -executable, -readable, -writable tests.
*/
bool eval_access(const struct expr *expr, struct eval_state *state) {
- struct BFTW *ftwbuf = state->ftwbuf;
+ const struct BFTW *ftwbuf = state->ftwbuf;
return xfaccessat(ftwbuf->at_fd, ftwbuf->at_path, expr->idata) == 0;
}
@@ -317,7 +317,7 @@ bool eval_nouser(const struct expr *expr, struct eval_state *state) {
* -delete action.
*/
bool eval_delete(const struct expr *expr, struct eval_state *state) {
- struct BFTW *ftwbuf = state->ftwbuf;
+ const struct BFTW *ftwbuf = state->ftwbuf;
// Don't try to delete the current directory
if (strcmp(ftwbuf->path, ".") == 0) {
@@ -395,7 +395,7 @@ bool eval_depth(const struct expr *expr, struct eval_state *state) {
*/
bool eval_empty(const struct expr *expr, struct eval_state *state) {
bool ret = false;
- struct BFTW *ftwbuf = state->ftwbuf;
+ const struct BFTW *ftwbuf = state->ftwbuf;
if (ftwbuf->typeflag == BFTW_DIR) {
int dfd = openat(ftwbuf->at_fd, ftwbuf->at_path, O_RDONLY | O_CLOEXEC | O_DIRECTORY);
@@ -459,7 +459,7 @@ bool eval_fstype(const struct expr *expr, struct eval_state *state) {
* -hidden test.
*/
bool eval_hidden(const struct expr *expr, struct eval_state *state) {
- struct BFTW *ftwbuf = state->ftwbuf;
+ const struct BFTW *ftwbuf = state->ftwbuf;
return ftwbuf->nameoff > 0 && ftwbuf->path[ftwbuf->nameoff] == '.';
}
@@ -506,7 +506,7 @@ bool eval_lname(const struct expr *expr, struct eval_state *state) {
bool ret = false;
char *name = NULL;
- struct BFTW *ftwbuf = state->ftwbuf;
+ const struct BFTW *ftwbuf = state->ftwbuf;
if (ftwbuf->typeflag != BFTW_LNK) {
goto done;
}
@@ -533,7 +533,7 @@ done:
* -i?name test.
*/
bool eval_name(const struct expr *expr, struct eval_state *state) {
- struct BFTW *ftwbuf = state->ftwbuf;
+ const struct BFTW *ftwbuf = state->ftwbuf;
const char *name = ftwbuf->path + ftwbuf->nameoff;
char *copy = NULL;
@@ -560,7 +560,7 @@ bool eval_name(const struct expr *expr, struct eval_state *state) {
* -i?path test.
*/
bool eval_path(const struct expr *expr, struct eval_state *state) {
- struct BFTW *ftwbuf = state->ftwbuf;
+ const struct BFTW *ftwbuf = state->ftwbuf;
return fnmatch(expr->sdata, ftwbuf->path, expr->idata) == 0;
}
@@ -601,7 +601,7 @@ bool eval_perm(const struct expr *expr, struct eval_state *state) {
bool eval_fls(const struct expr *expr, struct eval_state *state) {
CFILE *cfile = expr->cfile;
FILE *file = cfile->file;
- struct BFTW *ftwbuf = state->ftwbuf;
+ const struct BFTW *ftwbuf = state->ftwbuf;
const struct bfs_stat *statbuf = eval_stat(state);
if (!statbuf) {
goto done;
@@ -884,7 +884,7 @@ bool eval_type(const struct expr *expr, struct eval_state *state) {
* -xtype test.
*/
bool eval_xtype(const struct expr *expr, struct eval_state *state) {
- struct BFTW *ftwbuf = state->ftwbuf;
+ 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);
if (type == BFTW_ERROR) {
@@ -1168,7 +1168,7 @@ struct callback_args {
/**
* bftw() callback.
*/
-static enum bftw_action cmdline_callback(struct BFTW *ftwbuf, void *ptr) {
+static enum bftw_action cmdline_callback(const struct BFTW *ftwbuf, void *ptr) {
struct callback_args *args = ptr;
const struct cmdline *cmdline = args->cmdline;
diff --git a/printf.c b/printf.c
index f77ff92..80f54c9 100644
--- a/printf.c
+++ b/printf.c
@@ -33,7 +33,7 @@
#include <string.h>
#include <time.h>
-typedef int bfs_printf_fn(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf);
+typedef int bfs_printf_fn(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf);
struct bfs_printf {
/** The printing function to invoke. */
@@ -51,7 +51,7 @@ struct bfs_printf {
};
/** Print some text as-is. */
-static int bfs_printf_literal(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_literal(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
size_t len = dstrlen(directive->str);
if (fwrite(directive->str, 1, len, file) == len) {
return 0;
@@ -61,7 +61,7 @@ static int bfs_printf_literal(FILE *file, const struct bfs_printf *directive, st
}
/** \c: flush */
-static int bfs_printf_flush(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_flush(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
return fflush(file);
}
@@ -75,7 +75,7 @@ static int bfs_printf_flush(FILE *file, const struct bfs_printf *directive, stru
(void)ret
/** %a, %c, %t: ctime() */
-static int bfs_printf_ctime(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_ctime(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
// Not using ctime() itself because GNU find adds nanoseconds
static const char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
static const char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
@@ -109,7 +109,7 @@ static int bfs_printf_ctime(FILE *file, const struct bfs_printf *directive, stru
}
/** %A, %B/%W, %C, %T: strftime() */
-static int bfs_printf_strftime(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_strftime(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
const struct bfs_stat *statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags);
if (!statbuf) {
return -1;
@@ -177,7 +177,7 @@ static int bfs_printf_strftime(FILE *file, const struct bfs_printf *directive, s
}
/** %b: blocks */
-static int bfs_printf_b(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_b(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
const struct bfs_stat *statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags);
if (!statbuf) {
return -1;
@@ -189,12 +189,12 @@ static int bfs_printf_b(FILE *file, const struct bfs_printf *directive, struct B
}
/** %d: depth */
-static int bfs_printf_d(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_d(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
return fprintf(file, directive->str, (intmax_t)ftwbuf->depth);
}
/** %D: device */
-static int bfs_printf_D(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_D(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
const struct bfs_stat *statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags);
if (!statbuf) {
return -1;
@@ -205,12 +205,12 @@ static int bfs_printf_D(FILE *file, const struct bfs_printf *directive, struct B
}
/** %f: file name */
-static int bfs_printf_f(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_f(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
return fprintf(file, directive->str, ftwbuf->path + ftwbuf->nameoff);
}
/** %F: file system type */
-static int bfs_printf_F(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_F(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
const struct bfs_stat *statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags);
if (!statbuf) {
return -1;
@@ -221,7 +221,7 @@ static int bfs_printf_F(FILE *file, const struct bfs_printf *directive, struct B
}
/** %G: gid */
-static int bfs_printf_G(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_G(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
const struct bfs_stat *statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags);
if (!statbuf) {
return -1;
@@ -232,7 +232,7 @@ static int bfs_printf_G(FILE *file, const struct bfs_printf *directive, struct B
}
/** %g: group name */
-static int bfs_printf_g(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_g(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
const struct bfs_stat *statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags);
if (!statbuf) {
return -1;
@@ -247,7 +247,7 @@ static int bfs_printf_g(FILE *file, const struct bfs_printf *directive, struct B
}
/** %h: leading directories */
-static int bfs_printf_h(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_h(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
char *copy = NULL;
const char *buf;
@@ -274,12 +274,12 @@ static int bfs_printf_h(FILE *file, const struct bfs_printf *directive, struct B
}
/** %H: current root */
-static int bfs_printf_H(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_H(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
return fprintf(file, directive->str, ftwbuf->root);
}
/** %i: inode */
-static int bfs_printf_i(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_i(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
const struct bfs_stat *statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags);
if (!statbuf) {
return -1;
@@ -290,7 +290,7 @@ static int bfs_printf_i(FILE *file, const struct bfs_printf *directive, struct B
}
/** %k: 1K blocks */
-static int bfs_printf_k(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_k(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
const struct bfs_stat *statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags);
if (!statbuf) {
return -1;
@@ -302,7 +302,7 @@ static int bfs_printf_k(FILE *file, const struct bfs_printf *directive, struct B
}
/** %l: link target */
-static int bfs_printf_l(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_l(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
if (ftwbuf->typeflag != BFTW_LNK) {
return 0;
}
@@ -318,7 +318,7 @@ static int bfs_printf_l(FILE *file, const struct bfs_printf *directive, struct B
}
/** %m: mode */
-static int bfs_printf_m(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_m(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
const struct bfs_stat *statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags);
if (!statbuf) {
return -1;
@@ -328,7 +328,7 @@ static int bfs_printf_m(FILE *file, const struct bfs_printf *directive, struct B
}
/** %M: symbolic mode */
-static int bfs_printf_M(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_M(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
const struct bfs_stat *statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags);
if (!statbuf) {
return -1;
@@ -340,7 +340,7 @@ static int bfs_printf_M(FILE *file, const struct bfs_printf *directive, struct B
}
/** %n: link count */
-static int bfs_printf_n(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_n(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
const struct bfs_stat *statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags);
if (!statbuf) {
return -1;
@@ -351,12 +351,12 @@ static int bfs_printf_n(FILE *file, const struct bfs_printf *directive, struct B
}
/** %p: full path */
-static int bfs_printf_p(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_p(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
return fprintf(file, directive->str, ftwbuf->path);
}
/** %P: path after root */
-static int bfs_printf_P(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_P(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
const char *path = ftwbuf->path + strlen(ftwbuf->root);
if (path[0] == '/') {
++path;
@@ -365,7 +365,7 @@ static int bfs_printf_P(FILE *file, const struct bfs_printf *directive, struct B
}
/** %s: size */
-static int bfs_printf_s(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_s(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
const struct bfs_stat *statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags);
if (!statbuf) {
return -1;
@@ -376,7 +376,7 @@ static int bfs_printf_s(FILE *file, const struct bfs_printf *directive, struct B
}
/** %S: sparseness */
-static int bfs_printf_S(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_S(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
const struct bfs_stat *statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags);
if (!statbuf) {
return -1;
@@ -392,7 +392,7 @@ static int bfs_printf_S(FILE *file, const struct bfs_printf *directive, struct B
}
/** %U: uid */
-static int bfs_printf_U(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_U(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
const struct bfs_stat *statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags);
if (!statbuf) {
return -1;
@@ -403,7 +403,7 @@ static int bfs_printf_U(FILE *file, const struct bfs_printf *directive, struct B
}
/** %u: user name */
-static int bfs_printf_u(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_u(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
const struct bfs_stat *statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags);
if (!statbuf) {
return -1;
@@ -441,13 +441,13 @@ static const char *bfs_printf_type(enum bftw_typeflag typeflag) {
}
/** %y: type */
-static int bfs_printf_y(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_y(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
const char *type = bfs_printf_type(ftwbuf->typeflag);
return fprintf(file, directive->str, type);
}
/** %Y: target type */
-static int bfs_printf_Y(FILE *file, const struct bfs_printf *directive, struct BFTW *ftwbuf) {
+static int bfs_printf_Y(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) {
int error = 0;
if (ftwbuf->typeflag != BFTW_LNK) {
@@ -839,7 +839,7 @@ error:
return NULL;
}
-int bfs_printf(FILE *file, const struct bfs_printf *command, struct BFTW *ftwbuf) {
+int bfs_printf(FILE *file, const struct bfs_printf *command, const struct BFTW *ftwbuf) {
int ret = 0, error = 0;
for (const struct bfs_printf *directive = command; directive; directive = directive->next) {
diff --git a/printf.h b/printf.h
index d62770e..3bbbcd2 100644
--- a/printf.h
+++ b/printf.h
@@ -54,7 +54,7 @@ struct bfs_printf *parse_bfs_printf(const char *format, struct cmdline *cmdline)
* must be non-NULL.
* @return 0 on success, -1 on failure.
*/
-int bfs_printf(FILE *file, const struct bfs_printf *command, struct BFTW *ftwbuf);
+int bfs_printf(FILE *file, const struct bfs_printf *command, const struct BFTW *ftwbuf);
/**
* Free a parsed format string.