* [PATCH] commands: truncate: fix multiple file handling with relative sizes
@ 2025-11-19 18:53 Alexander Shiyan
2025-11-20 7:32 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Alexander Shiyan @ 2025-11-19 18:53 UTC (permalink / raw)
To: barebox; +Cc: Alexander Shiyan
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-11-20 7:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-19 18:53 [PATCH] commands: truncate: fix multiple file handling with relative sizes Alexander Shiyan
2025-11-20 7:32 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox