1.open函数的使用
调用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参数是要打开或创建的文件名,和fopen一样,pathname既可以是相对路径也可以是绝对路径.
flags参数用来说明此函数的多个选项。用下列一个或多个常量进行”或”运算构成flags参数。(常量在fcntl.h头文件中定义)
以下三个常数中必须指定一个,且仅允许指定一个。
- O_RDONLY 只读打开
- O_WRONLY 只写打开
- O_RDWR 可读可写打开
以下可