#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
int main()
{
int fd;
fd = open("./file1",O_RDWR);
printf("fd = %d\n",fd);
return 0;
}
用open函数打开一个文件,如果成功打开fd=3,否则fd=-1。
open函数手册Linux指令:man 2 open