Linux-在linux 程序创建文件读写权限
我用一个普通用户,运行一个C语言程序,尝试打开一个文件,如果打开失败就创建文件。但是创建出来的文件没有可写权限,我是用O_RDWR | O_BINARY | O_CREAT 去打开的,请问我想要有读写权限该怎么解决呢?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我用一个普通用户,运行一个C语言程序,尝试打开一个文件,如果打开失败就创建文件。但是创建出来的文件没有可写权限,我是用O_RDWR | O_BINARY | O_CREAT 去打开的,请问我想要有读写权限该怎么解决呢?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
创建的文件权限 由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