int open(char *pathname,int access[,int permiss])为读或写打开一个文件, 按后按access来确定是读文件还是写文件,access值见下表
access值 |
意义 |
O_RDONLY |
读文件 |
O_WRONLY |
写文件 |
O_RDWR |
即读也写 |
O_NDELAY |
没有使用;对UNIX系统兼容 |
O_APPEND |
即读也写,但每次写总是在文件尾添加 |
O_CREAT |
若文件存在,此标志无用;若不存在,建新文件 |
O_TRUNC |
若文件存在,则长度被截为0,属性不变 |
O_EXCL |
未用;对UNIX系统兼容 |
O_BINARY |
此标志可显示地给出以二进制方式打开文件 |
O_TEXT |
此标志可用于显示地给出以文本方式打开文件 |
permiss为文件属性,可为以下值:
S_IWRITE允许写 S_IREAD允许读 S_IREAD|S_IWRITE允许读、写
int creat(char *filename,int permiss) 建立一个新文件filename,并设定读写性。
permiss为文件读写性,可以为以下值
S_IWRITE允许写 S_IREAD允许读 S_IREAD|S_IWRITE允许读、写
int _creat(char *filename,int attrib) 建立一个新文件filename,并设定文件属性。
attrib为文件属性,可以为以下值
FA_RDONLY只读 FA_HIDDEN隐藏 FA_SYSTEM系统
int creatnew(char *filenamt,int attrib) 建立一个新文件filename,并设定文件属性。
attrib为文件属性,可以为以下值
FA_RDONLY只读 FA_HIDDEN隐藏 FA_SYSTEM系统
int creattemp(char *filenamt,int attrib) 建立一个新文件filename,并设定文件属性。
attrib为文件属性,可以为以下值
FA_RDONLY只读 FA_HIDDEN隐藏 FA_SYSTEM系统
int read(int handle,void *buf,int nbyte) 从文件号为handle的文件中读nbyte个字符存入buf中
int _read(int handle,void *buf,int nbyte) 从文件号为handle的文件中读nbyte个字符存入buf中,直接调用MSDOS进行操作.
int write(int handle,void *buf,int nbyte) 将buf中的nbyte个字符写入文件号为handle的文件中
int _write(int handle,void *buf,int nbyte) 将buf中的nbyte个字符写入文件号为handle的文件中
int dup(int handle) 复制一个文件处理指针handle,返回这个指针
int dup2(int handle,int newhandle) 复制一个文件处理指针handle到newhandle
int eof(int *handle) 检查文件是否结束,结束返回1,否则返回0
long filelength(int handle) 返回文件长度,handle为文件号
int setmode(int handle,unsigned mode)本函数用来设定文件号为handle的文件的打开方式
int getftime(int handle,struct ftime *ftime)
读取文件号为handle的文件的时间,并将文件时间存于ftime结构中,成功返回0, ftime结构如下:
struct ftime { unsigned ft_tsec:5; /*秒*/ unsigned ft_min:6; /*分*/ unsigned ft_hour:5; /*时*/ unsigned ft_day:5; /*日*/ unsigned ft_month:4;/*月*/ unsigned ft_year:1; /*年-1980*/ }
int setftime(int handle,struct ftime *ftime) 重写文件号为handle的文件时间,
新时间在结构ftime中.成功返回0.结构ftime如下:
struct ftime { unsigned ft_tsec:5; /*秒*/ unsigned ft_min:6; /*分*/ unsigned ft_hour:5; /*时*/ unsigned ft_day:5; /*日*/ unsigned ft_month:4;/*月*/ unsigned ft_year:1; /*年-1980*/ }
long lseek(int handle,long offset,int fromwhere)
本函数将文件号为handle的文件的指针移到fromwhere后的第offset个字节处.
SEEK_SET文件开关 SEEK_CUR当前位置 SEEK_END文件尾
long tell(int handle) 本函数返回文件号为handle的文件指针,以字节表示
int isatty(int handle)本函数用来取设备handle的类型
int lock(int handle,long offset,long length) 对文件共享作封锁
int unlock(int handle,long offset,long length) 打开对文件共享的封锁
int close(int handle) 关闭handle所表示的文件处理,handle是从_creat、creat、
creatnew、creattemp、dup、dup2、_open、open中的一个处调用获得的文件处理
成功返回0否则返回-1,可用于UNIX系统
int _close(int handle) 关闭handle所表示的文件处理,handle是从_creat、creat、
creatnew、creattemp、dup、dup2、_open、open中的一个处调用获得的文件处理
成功返回0否则返回-1,只能用于MSDOS系统