Unix O_CREAT flag without mode specified

前端 未结 6 1006
孤独总比滥情好
孤独总比滥情好 2020-12-18 01:23

The definition of the UNIX open() function when used with the O_CREAT flag is that it requires a third argument named mode in order to set the files\' priv

6条回答
  •  时光取名叫无心
    2020-12-18 01:57

    Good question. The mode value will be modified by the umask of the process. So if you don't pass a mode explicitly to open in an O_CREAT operation, and if this results in random bits being used for the mode, those random bits will be modified by the umask.

    Wish I could be more definitive and precise, but I agree with cdonner that "random" values are being used, along with the umask.

    Edit: One thing you could try is to use dtruss or truss or some other facility to trace system calls, and look at the value of mode at run-time to see if something sensible is used, or if it's just random bits modified by the umask, for example.

提交回复
热议问题