int open(const char *pathname, int flags, mode_t mode);
功能:打开或创建文件
pathname:文件路径
flag:打开文件时的权限
O_RDONLY 只读
O_WRONLY 只写
O_RDWR 读写
O_CREAT 文件不存在时则创建
O_EXCL 配合创建使用,文件存在时出错
O_TRUNC 清空
O_APPEND 追加
mode:创建文件时的权限 mmm 与chmod的权限设置方式一致
返回值:
文件描述符
失败返回-1
fopen函数中的w,r,a,w+,r+,a+对应的flags。
w:O_WRONLY|O_CREAT|O_TRUNC
r:O_RDONLY
a:O_WRONLY|O_CREAT|O_APPEND
w+:O_RDWR|O_CREAT|O_TRUNC
r+:O_RDWR
a+: O_RDWR|O_CREAT|O_APPEND