Reputation: 2141
I have looked at ftruncate
documentation from here, as well as well from here. In the case of IBM link, I implemented my ftruncate
accordingly but it gives me Invalid Arguments
error. Here is the code:
char const *path = "mozunit.txt";
int file_ = open(path, O_RDONLY, 0600);
int ftrunc_ = ftruncate(file_, 1);
cout<<strerror(errno)<<endl;
Why is it? I tried changing the second parameter in ftruncate
but to no avail.
Upvotes: 0
Views: 5140
Reputation: 799230
From the ftruncate(2)
man page:
EBADF or EINVAL fd is not open for writing.
Seeing as how you've opened the file as read-only...
Upvotes: 10