一、open
1、函数原型
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int open(const char *pathname, int flags);
根据pathname,按flag所指的方式,打开一个文件,返回fd
int fd;
fd = open ("/home/username/file.ext", O_WRONLY | O_TRUNC);
2、 flag
3、打开存在和不存在的文件
对于一个不存在的文件,函数原型应该多一个参数:
int open(const char *pathname, int flags,mode_t mode);
其中mode表示创建的这个文件的权限,权限可以用预先定义的宏来表示(下标第一列),也可以用数字来表示(下标第二列):
如果要用数字表示,应该怎么计算数字呢