Reputation: 555
I try to create a file "foo" in current dir like this:
open("foo", O_CREAT | O_EXCL | O_RDWR);
I did not give it a 'mode' for the third parameter, so what will it be? On my ubuntu 14.04, the mode for the this new file seems to be a random value. Isn't there any default value for the 'mode'?
Upvotes: 0
Views: 759
Reputation: 98496
In the POSIX man 3p open
it is not said very clearly, but in the Linux man 2 open
:
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
mode
specifies the permissions to use in case a new file is created. This argument must be supplied whenO_CREAT
orO_TMPFILE
is specified in flags.
That is, if mode
is not supplied when it should, the results are undefined.
Upvotes: 2