There's a value maintained by the system called the umask
; it is a property of the process, just like the PID (process ID) or EUID (effective user ID) is. It will be set to 022
(octal), which indicates that the system should remove the group and other write permission from files that are created.
You can call umask(0);
before using open()
so that the mode you specify in open()
won't be altered. You should certainly do this to demonstrate that umask
is the issue. However, it is generally best to let the user's choice of umask
prevail — I for one get very stroppy if a program doesn't obey my umask setting; it tends not to be used again after I spot and verify the problem.
The shell also has a (built-in) command umask
which you can use. The 022
value is a sensible default; most of the time, you do not want just anybody writing to your files.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…