open函数的问题,请教各位大神啊!!!!!!!!!!
在Linux RedHat中,为什用open函数以只读方式打开一个文件而是可以成功,并且还会创建文件??
不是应该加了O_CREAT之后才会创建文件的吗??请教各位大神帮助小弟解答
以下是代码
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
int main(int argc,char **argv)
{
int fd=0;
if(argc<2)
{
puts("please input the open file pathname!\n");
exit(1);
}
if((fd=open(argv[1],O_RDONLY))<0)
{
perror("open file failure!\n");
exit(1);
}
else
{
printf("open file %d success!\n",fd);
}
close(fd);
exit(0);
}
[解决办法]
不会啊。。我是centos的,运行打开失败,没看到创建文件啊
[解决办法]
不会吧!把文件删掉再运行试试!
The argument flags must include one of
the following access modes: O_RDONLY, O_WRONLY, or O_RDWR.
These request opening the file read-only, write-only, or read/write, respectively.