使用open()系统调用 [英] Using the open() system call
本文介绍了使用open()系统调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个将输出写入文件的程序.如果该文件不存在,我要创建它.
I'm writing a program that writes output to a file. If this file doesn't exist, I want to create it.
当前,我在调用open时使用以下标志: O_WRONLY | O_CREATE
Currently, I'm using the following flags when calling open: O_WRONLY | O_CREATE
但是,当它创建文件时,它没有授予我写入该文件的任何权限...
However, when this creates the file, it doesn't give me any permissions to write to it...
我如何使用open来创建一个不存在的文件,但是在需要时会使用必要的权限来创建它?
How can I use open so that it creates a file if it doesn't exist, but will create it with necessary permissions when needed?
谢谢!
推荐答案
您可能需要第三个参数.例如:
You probably need the third argument. For example:
open('path',O_WRONLY|O_CREAT,0640);
这篇关于使用open()系统调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文