使用open函数创建一个权限为0777的文件
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<stdio.h>
#include<stdlib.h>
int main(int argc, const char *argv[])
{
int ft=open("./open5.txt", O_RDWR | O_CREAT | O_TRUNC,S_IRWXU |S_IRWXG|S_IRWXO);
if(ft<0)
{
perror("chomd 777 open3.txt");
return -1;
}
printf("%d\n",ft);
system("chmod 777 open5.txt");
return 0;
}
![](https://img-blog.csdnimg.cn/img_convert/37d18d05ef04a7756ddc44ea3c104348.png)