From 6b083345307aa1fdbc48eaf247c80b4c4982b2ee Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 2 Sep 2021 14:57:18 -0400 Subject: eval: Use 512-byte blocks for -ls when POSIXLY_CORRECT is set This matches the behaviour of GNU find, and allows bfs to match the output of BSD find as well. Fixes #77. --- ctx.c | 3 ++- ctx.h | 4 +++- eval.c | 3 ++- parse.c | 4 +++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ctx.c b/ctx.c index b17d148..5c9c9bf 100644 --- a/ctx.c +++ b/ctx.c @@ -1,6 +1,6 @@ /**************************************************************************** * bfs * - * Copyright (C) 2015-2020 Tavian Barnes * + * Copyright (C) 2015-2021 Tavian Barnes * * * * Permission to use, copy, modify, and/or distribute this software for any * * purpose with or without fee is hereby granted. * @@ -72,6 +72,7 @@ struct bfs_ctx *bfs_ctx_new(void) { ctx->optlevel = 3; ctx->debug = 0; ctx->ignore_races = false; + ctx->posixly_correct = false; ctx->status = false; ctx->unique = false; ctx->warn = false; diff --git a/ctx.h b/ctx.h index 7af4060..f089b84 100644 --- a/ctx.h +++ b/ctx.h @@ -1,6 +1,6 @@ /**************************************************************************** * bfs * - * Copyright (C) 2015-2020 Tavian Barnes * + * Copyright (C) 2015-2021 Tavian Barnes * * * * Permission to use, copy, modify, and/or distribute this software for any * * purpose with or without fee is hereby granted. * @@ -82,6 +82,8 @@ struct bfs_ctx { enum debug_flags debug; /** Whether to ignore deletions that race with bfs (-ignore_readdir_race). */ bool ignore_races; + /** Whether to follow POSIXisms more closely ($POSIXLY_CORRECT). */ + bool posixly_correct; /** Whether to show a status bar (-status). */ bool status; /** Whether to only return unique files (-unique). */ diff --git a/eval.c b/eval.c index 51b621b..55cd812 100644 --- a/eval.c +++ b/eval.c @@ -644,7 +644,8 @@ bool eval_fls(const struct expr *expr, struct eval_state *state) { } uintmax_t ino = statbuf->ino; - uintmax_t blocks = ((uintmax_t)statbuf->blocks*BFS_STAT_BLKSIZE + 1023)/1024; + uintmax_t block_size = state->ctx->posixly_correct ? 512 : 1024; + uintmax_t blocks = ((uintmax_t)statbuf->blocks*BFS_STAT_BLKSIZE + block_size - 1)/block_size; char mode[11]; xstrmode(statbuf->mode, mode); char acl = bfs_check_acl(ftwbuf) > 0 ? '+' : ' '; diff --git a/parse.c b/parse.c index 8f34c08..1129ebd 100644 --- a/parse.c +++ b/parse.c @@ -3614,7 +3614,9 @@ struct bfs_ctx *bfs_parse_cmdline(int argc, char *argv[]) { bool stdout_tty = isatty(STDOUT_FILENO); bool stderr_tty = isatty(STDERR_FILENO); - if (!getenv("POSIXLY_CORRECT")) { + if (getenv("POSIXLY_CORRECT")) { + ctx->posixly_correct = true; + } else { ctx->warn = stdin_tty; } -- cgit v1.2.3