C++ linux上的ftruncate提供无效参数错误

C++ linux上的ftruncate提供无效参数错误,c++,linux,C++,Linux,我已经查看了来自的ftruncate文档,以及。在ibmlink的例子中,我相应地实现了ftruncate,但它给了我无效的参数错误。代码如下: char const *path = "mozunit.txt"; int file_ = open(path, O_RDONLY, 0600); int ftrunc_ = ftruncate(file_, 1); cout<<strerror(errno)<<endl; 为什么?我尝试更改ftruncate中的第二个参数,

我已经查看了来自的ftruncate文档,以及。在ibmlink的例子中,我相应地实现了ftruncate,但它给了我无效的参数错误。代码如下:

char const *path = "mozunit.txt";
int file_ = open(path, O_RDONLY, 0600);
int ftrunc_ = ftruncate(file_, 1);
cout<<strerror(errno)<<endl;
为什么?我尝试更改ftruncate中的第二个参数,但没有成功。

从ftruncate2手册页:


看看您是如何以只读方式打开文件的…

该变量称为errno,而不是errno。请发布真实代码。@interjay谢谢,这是真实代码。我必须在这里输入,因为emacs不为我工作。
  EBADF or EINVAL
          fd is not open for writing.