Linux-在linux 程序创建文件读写权限

发布于 2016-12-27 19:20:18 字数 116 浏览 1409 评论 1

我用一个普通用户,运行一个C语言程序,尝试打开一个文件,如果打开失败就创建文件。但是创建出来的文件没有可写权限,我是用O_RDWR | O_BINARY | O_CREAT 去打开的,请问我想要有读写权限该怎么解决呢?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

泛泛之交 2017-05-02 16:21:52

创建的文件权限 由open的第三个参数控制:
"the access permission bits (see <sys/stat.h>) of the file mode are set to the value of the third argument taken as type mode_t modified as follows: a bitwise-AND is performed on the file-mode bits and the corresponding bits in the complement of the process' file mode creation mask."

读写权限即:
open("testfile",O_RDWR | O_CREAT,S_IRUSR | S_IWUSR );

更多权限见:
http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysstat.h.html

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