truncate: Clamp file size to 0 when using the -s option

When using the `-s` option to reduce the size of a file, the file size
is now set to zero if the argument given would result in a file
size less than zero.

This matches the behavior of truncate on Linux and FreeBSD.
This commit is contained in:
Tim Ledbetter 2023-07-22 15:49:22 +01:00 committed by Andreas Kling
parent 8e79afebb9
commit ea411774f0

View file

@ -99,7 +99,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
size = stat.st_size + size;
break;
case OP_Shrink:
size = stat.st_size - size;
size = max(stat.st_size - size, 0);
break;
}