Appearance
函数原型
打开或者创建一个文件。
c
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);参数
flags:
O_RDONLY只读 ,O_WRONLY只写 ,O_RDWR读写(三者必有一)O_APPEND追加,O_CREAT创建,O_TRUNC截断为 0(0个或多个)- 还有其他。。。
这些宏可以通过 | 来一起使用,它是通过位图 #TBD/QS 实现的。
对应标准 I/O:
r-->O_RDONLYr+-->O_RDWRw-->O_WRONLY | O_TRUNC | O_CREATw+-->O_RDWR | O_TRUNC | O_CREATa-->O_WRONLY | O_APPEND | O_CREAT
mode: 当 flags 中出现 O_CREAT 时,这个参数必须使用。
返回
其他
- fopen():标准IO打开文件,返回的是标准流