Comment 3 for bug 521164

Revision history for this message
Kamal Mostafa (kamalmostafa) wrote :

Hi Stefan-

The "mode" argument for open() with O_CREAT does not directly set the permissions of the file being created -- it just specifies the mode bits before modification by the process umask setting (see the open(2) man page). So enabling the read and write bits for all three 'classes' (user, group, and other) in the open() call allows the umask setting to control the permissions. The normal default umask (0022) will "strip away" the two permissions bits you questioned (group-write and other-write), so newly created files actually *will* get created with the permissions "-rw-r--r--" you're expecting... Unless, that is, the user has explicitly set their umask to something else, (say 0002, to allow other members of their group write-access to their files) in which case that same open() call will create a file with "-rw-rw-r--" which is just what the use wanted.

Specifying all six of the read/write user/group/other mode bits is the standard way to address source code which omits it.