一、open
函数使用时要用到三个头文件:sys/types.h,sys/stat.h,fcntl.h
#include<fcntl.h>
#include<types.h>
#include<sys/stat.h>/此头文件里面定义了mode标志/
open函数:int open(const char path *name, int oflag,…);
返回:若成功为只写打开的文件描述符,若错误为-1。
进行文件I/O操作时,要先调用open()函数打开文件,它返回的文件描述符fd就代表了所打开的文件,后续的其他操作均通过引用该文件描述符fd进行。
二、creat
open()函数的参数flags,当设置了O_CREAT标志时,可以创建一个新文件,也可以用另外一个函数creat()创建新文件.
creat函数:int creat(const char *pathname, mode_t mode);
返回:若成功为只写打开的文件描述符,若出错为-1
该函数等效于:open(pathname,O_WRONLY|O_CREAT|O_TRUNC,mode);
注意: