用fstream写入的文件有什么权限?
假设我创建一个这样的文件用于写入:
std::ofstream my_file("filename", std::ios_base::out | std::ios_base::trunc);
这个文件的权限是如何确定的?我有一个程序在一夜之间运行,大约每分钟生成一次文件 - 有些是 0644,但其他是 0660,并且我的代码中没有任何内容可以更改它。 (我已经看到一些实现允许第三个参数来设置文件权限 - 我正在使用 gcc 4.1.2,它似乎不支持这一点)。
Suppose I create a file for writing like this:
std::ofstream my_file("filename", std::ios_base::out | std::ios_base::trunc);
How are the permissions of this file determined? I've had a program running overnight generating files about once a minute - some are 0644 but others are 0660, and there's nothing in my code that should make it change. (I've seen that some implementations allow a third argument to set the file permissions - I'm using gcc 4.1.2 which doesn't appear to support this).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于 umask。
It depends on the umask.
默认属性是使用
umask
命令设置的。它没有解释您的文件属性更改,但仍然可能对您有用default attrs are set with
umask
command. it not explains your files attrs changes, but still may be useful for you