// 打开open函数的帮助文档
man 2 open
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
C语言中没有重载,此处为可变参数
int open(const char *pathname, int flags);
参数
pathname
:需要打开的文件路径flag
:一个位掩膜,记录文件的操作权限等设置
O_RDONLY
(只读)、O_WRONLY
(只写)、O_RDWR
(读写)返回值
打开失败时返回-1(大部分系统函数调用失败都会返回-1)
errno:属于Linux系统函数库,库里面的一个全局变量,记录的是最近的错误号
perror:用于打印errno对应的错误描述(传递的参数是用户提供的)
打印的内容:“open: 错误的具体信息”
int open(const char *pathname, int flags, mode_t mode);
参数
pathname
:需要打开的文件路径flag
:文件的操作权限等设置
O_RDONLY
、O_WRONLY
、O_RDWR
O_CREAT
(文件不存在时创建文件)