[PATCH] commands: truncate: fix multiple file handling with relative sizes
Alexander Shiyan
eagle.alexander923 at gmail.com
Wed Nov 19 10:53:07 PST 2025
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>
---
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
More information about the barebox
mailing list