Reputation: 173
So, I just write:
int fdes = open(path, O_WRONLY | O_CREAT | O_TRUNC);
And if the file that the path
referred to doesn't exist, this code works. But if it does, the code returns with errno
13 : Permission Denied. I never use the O_EXCL
mode at all.
I have searched for the solution to this problem a long time and I am really confused. Can you explain the problem?
I use the GCC for windows(4.5.2). Your answer will be appreciated.
Upvotes: 5
Views: 5339
Reputation: 753665
O_CREAT
, you should supply a mode as the third argument to open()
.Note that (on Unix at least) you can create a file for writing with mode 0444
(or even 0
); the permissions affect everyone else, but not the process that created the file while it uses the file descriptor that created the file.
Upvotes: 5