函数原型
#include <fcntl.h>
int open(const char *path, int oflag, ...);
int openat(int fd, const char *path, int oflag, ...);
用法
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
int fd;
fd = open("./dict.cpp", O_RDONLY | O_CREAT, 0644); // rw-r--r--
printf("fd=%d\n", fd);
close(fd);
return 0;
}
ssize_t read(int fd, void *buf, size_t count);
参数:
返回值
off_t lseek(int fd, off_t offset, int whence);
参数:
返回值
应用场景:
文件的“读”,“写”使用同一偏移位置
使用lseek获取文件大小
使用lseek拓展文件的大小:要想使文件大小真正的拓展,必须要进行IO操作
可以使用truncate直接进行文件的拓展
原文:https://www.cnblogs.com/fandx/p/12518441.html