off_t lseek(int handle, off_t offset, int fromwhere);文件偏移量offset超过off_t 最大值

使用lseek设置文件指针的位置,当文件偏移量超过off_t类型的范围时,可以将offset分成几个最大值组合,示例代码如下:

fds[i] = creat(p->path, 0777);
if(fds[i] < 0) {printf("%s:%d error",__FILE__,__LINE__); return -1;}
count = (p->length-1) / (1024*1024*1024);
remainder = (p->length-1)%(1024*1024*1024);

while(count)
{
    printf("\ncount:%d\n", count);
    ret = lseek(fds[i], 1024*1024*1024, SEEK_CUR);
    count--;
}
if(remainder > 0)
{
    ret = lseek(fds[i], remainder, SEEK_CUR);
}
ret = write(fds[i],buff,1);
close(fds[i]);

 

你可能感兴趣的:(编程相关)