Linux平台的文件I/O操作
以下函数为不带缓存的I/O(unbuffered I/O)函数
对于内核而言,所有打开的文件都由一个非负整数描述(称为文件描述符)。
下面介绍下文件I/O函数:
(1)open
此函数为打开或创建一个文件。成功则返回文件描述符;失败则返回-1。
格式:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int open(const char *name, int oflag[|optional parameter][,mode]);
(2)creat
此函数为创建一个新文件。成功则返回文件描述符;失败则返回-1。
格式:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int creat(const char *name, mode_t mode);
(3)close
此函数为关闭一个已经打来的文件。
格式:
#include <unistd.h>
int close(int file);
成功返回0,否则返回-1。
(4)lseek
此函数为制定一个当前文件位移量。这个位移量是一个非负整数,用来说明从文件开始处计算的字节数。
格式:
#include <unistd.h>
#include <sys/types.h>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: