From: Alexander Shiyan <eagle.alexander923@gmail.com>
To: barebox@lists.infradead.org
Cc: Alexander Shiyan <eagle.alexander923@gmail.com>
Subject: [PATCH] commands: truncate: fix multiple file handling with relative sizes
Date: Wed, 19 Nov 2025 21:53:07 +0300 [thread overview]
Message-ID: <20251119185307.931800-1-eagle.alexander923@gmail.com> (raw)
Fix bug where processing multiple files with -s +SIZE option
would use incorrect sizes for files after the first one, because the
size variable was being overwritten.
Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
commands/truncate.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/commands/truncate.c b/commands/truncate.c
index 5c6d74257d..83661fbaf6 100644
--- a/commands/truncate.c
+++ b/commands/truncate.c
@@ -59,23 +59,26 @@ static int do_truncate(int argc, char *argv[])
continue;
}
+ off_t target_size = size;
+
if (modify) {
struct stat st;
if (fstat(fd, &st) == -1) {
perror("fstat");
ret = 1;
- goto close;
+ close(fd);
+ continue;
}
- size = st.st_size + modify * size;
+ target_size = st.st_size + size;
}
- if (ftruncate(fd, size) == -1) {
+ if (ftruncate(fd, target_size) == -1) {
perror("truncate");
ret = 1;
}
-close:
+
close(fd);
}
--
2.38.2
next reply other threads:[~2025-11-19 18:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-19 18:53 Alexander Shiyan [this message]
2025-11-20 7:32 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251119185307.931800-1-eagle.alexander923@gmail.com \
--to=eagle.alexander923@gmail.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox