文件截断

将一个文件的长度截断为0是一个特例,可以在open的时候使用O_TRUC来实现,为了截断文件可以调用函数truncate和ftruncate.

#include <unistd.h>
int truncate(const char *pathname, off_set len);
int ftruncate(int fd, off_st len);

执行成功返回0,出错返回-1

将一个现有文件的长度截断为len。

如果以前文件长度大于len,超过len的部分将不能再访问。

如果长度小于len,文件长度将增加,在以前文件的尾端到新文件的尾端的数据将读作0.

猜你喜欢

转载自blog.csdn.net/aabb7012086/article/details/80956833
今日推荐