1. open函数
-
包含头文件
#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); -
函数功能
打开一个文件,并返回文件描述符。
-
函数参数
- pathname:文件名
- flags:
- 必选参数(下面三个必须要有一个)
- O_RDONLY :只读
- O_WRONLY :只写
- O_RDWR :可读可写
- 可选参数(仅列出常用参数)
- O_APPEND :追加的方式打开,The file is opened in append mode.
- O_CREAT :如果文件不存在则创建,If the file does not exist it will be created.
- O_EXCL :和O_CREAT一块使用,如果文件存在则报错,if this flag is specified in conjunction with O_CREAT, and pathname already exists, then open() will fail.
- O_NONBLOCK :非阻塞的方式打开文件
- 必选参数(下面三个必须要有一个)