在unix中打开系统调用
以下是开放系统调用的原型:
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
Run Code Online (Sandbox Code Playgroud)
pathname - >它用于提及文件的路径,如/home/mohan/a.txt
flags - >用于提示文件将以哪种模式打开,如Readonly,writeonly或readwrite.
模式 - >?
什么是模式的使用以及何时使用模式.有没有使用模式的例子.
提前致谢.
正如我们在open(2)手册页中看到的,该模式用于设置文件的访问权限(就像使用UNIX命令一样chmod
).
当你没有创建文件时它没用,但是当你使用标志时O_CREAT
,你必须使用它.
例如:在读+写模式下创建具有权限644的文件:
int fd = open("file", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);