在 Windows 中,有 SetEndOfFile() API 可以在最后剪切一些数据。
我该如何在 Linux 中执行此操作?
我正在寻找的伪代码示例(特定于 Linux):
int fd = open("/path/to/file",O_RDWR);
// file contents: "0123456789ABCDEF", 16 bytes
lseek(fd,10,SEEK_CUR);
// what's in the next line? (imaginary code)
syscall(what,fd,FD_SET_EOF);
close(fd);
//sync();
// now file on disk looks like "0123456789", 10 bytes
ftruncate(fd, 10);
(The lseek
不需要打电话。)
man 2 ftruncate http://linux.die.net/man/2/ftruncate
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)