commands: truncate: fix multiple file handling with relative sizes
PATCH 1/1 commands: truncate: fix multiple file handling with relative sizes
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 <[email protected]>
--- commands/truncate.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
commands/truncate.c +7 -4
@@ -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); }
Signature · 1 line
2.38.2
Sascha Hauer
AppliedQuoted 5 lines · 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.
Applied, thanks!
[1/1] commands: truncate: fix multiple file handling with relative sizes
https://git.pengutronix.de/cgit/barebox/commit/?id=6981db707661 (link may not be stable)
Best regards,
Signature · 1 line
Sascha Hauer <[email protected]>