c++ - Linux 上的 ftruncate 给出无效参数错误

标签 c++ linux

我查看了来自 hereftruncate 文档,以及来自 here .对于 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.

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

关于c++ - Linux 上的 ftruncate 给出无效参数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19935395/

相关文章:

c++ - 删除 vector 中的特定值

c++ - 如何测试是否可以无错加载 DLL

c++ - 浮点对象和它的值之间的区别

c++ - 如何定义指向函数指针的指针以及如何在 C++ 中使用它?

c - 当 fd 之前未关闭时解压文件失败

c - tcp socket hungry 程序是否会干扰文件系统 I/O

linux - 如何检测当前是否对 linux 上的文件进行了文件操作

linux - 如何在 Ubuntu 上设置 GOPATH 环境变量?我必须编辑什么文件?

linux - 使用 ssh 启用无密码身份验证

c++ - C++ 有没有像 getdelim 这样的函数?