如果是的umask()有用吗? [英] When is umask() useful?

查看:185
本文介绍了如果是的umask()有用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

umask(0);

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

下面的 2人的umask

umask() sets the calling process’s file mode creation mask (umask) to mask & 0777.

但它没有任何意义对我来说,当我们调用打开,我们也将提供一个模式参数。

But it doesn't make sense for me,as when we call open ,we will also provide a mode parameter.

那么,什么是的umask

推荐答案

的umask是适用于文件系统操作使用的所有模式。从手动开放(2)

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

创建的文件的权限是(模式&安培;〜的umask)

因此​​,与一个调用的umask,你可以影响所有创建文件的模式。

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

这是通常用于当一个程序希望用户允许否决默认赠款的文件/目录它创建。一个偏执的用户(或root)可以设置umask为 0077 这意味着,即使您指定 0777 开放(2),只有当前用户将有机会获得。

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.

这篇关于如果是的umask()有用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆