用fstream写入的文件有什么权限?

发布于 2024-09-08 23:07:54 字数 272 浏览 2 评论 0原文

假设我创建一个这样的文件用于写入:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

平定天下 2024-09-15 23:07:54

这取决于 umask

It depends on the umask.

权谋诡计 2024-09-15 23:07:54

默认属性是使用 umask 命令设置的。它没有解释您的文件属性更改,但仍然可能对您有用

default attrs are set with umask command. it not explains your files attrs changes, but still may be useful for you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文