When is umask() useful?

后端 未结 4 1658
星月不相逢
星月不相逢 2021-01-04 21:57
umask(0);

fd = open(\"/dev/null\", O_RDWR);

Here\'s man 2 umask:

umask() sets the calling process’s file mode creatio         


        
4条回答
  •  暖寄归人
    2021-01-04 22:39

    The umask is applied to all modes used in file system operations. From the manual open(2):

    The permissions of the created file are (mode & ~umask)

    So with a single call to umask, you can influence the mode of all create files.

    This is usually used when a program wants the user to allow to overrule the default grants for files/directories it creates. A paranoid user (or root) can set the umask to 0077 which means that even if you specify 0777 in open(2), only the current user will have access.

提交回复
热议问题