[PATCH v2025.09.y 22/49] commands: truncate: fix multiple file handling with relative sizes
Ahmad Fatoum
a.fatoum at pengutronix.de
Fri Dec 19 01:20:58 PST 2025
From: Alexander Shiyan <eagle.alexander923 at gmail.com>
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 at gmail.com>
Link: https://lore.barebox.org/20251119185307.931800-1-eagle.alexander923@gmail.com
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
(cherry picked from commit 6981db707661f68a1aea4f0969360cb0af7fd530)
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
commands/truncate.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/commands/truncate.c b/commands/truncate.c
index 5c6d74257da1..83661fbaf63b 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.47.3
More information about the barebox
mailing list