Permissions are modified by the process' umask. Effective permissions are (mode & ~umask)
.
You should change permissions after creating the file, using fchmod()
. fchmod()
avoids race conditions you could have if you used chmod()
and the underlying file changed to point to other inode between the open()
and the chmod()
(google for TOCTOU races).