解决方法
尝试调用truncate(2):
truncate("/my/file",my_size);
欲获得更多信息,
man 2 truncate
The truncate() and ftruncate() functions cause the regular file named by path or referenced by fd to be truncated to a size of precisely length bytes.
If the file prevIoUsly was larger than this size,the extra data is lost. If the file prevIoUsly was shorter,it is extended,and the extended part reads as null bytes (‘\0’).
如果您正在寻找Windows本机功能,请查看SetEndOfFile,它的功能大致相同.