Linux上的ftruncate给出了无效参数错误

ftruncate on linux gives invalid arguments error

本文关键字:无效 参数 错误 上的 ftruncate Linux      更新时间:2023-10-16

我从这里以及这里查看了ftruncate文档。在 IBM 链接的情况下,我相应地实现了我的ftruncate,但它给了我Invalid Arguments错误。这是代码:

char const *path = "mozunit.txt";
int file_ = open(path, O_RDONLY, 0600);
int ftrunc_ = ftruncate(file_, 1);
cout<<strerror(errno)<<endl;

这是为什么呢?我尝试更改ftruncate中的第二个参数,但无济于事。

ftruncate(2)手册页:

  EBADF or EINVAL
          fd is not open for writing.

查看您如何以只读方式打开文件...