Linux标准库不支持大文件操作,但是系统支持。需要操作大文件时,需要在编译时加-D _FILE_OFFSET_BITS=64或在#include<unistd.h>前加#define _FILE_OFFSET_BITS 64.。
方法一:
/**
大文件支持宏定义
*/
#ifndef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64
#endif
/**
常用头文件声明
*/
#include <unistd.h>
#include <sys/tpyes.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>
/**
程序实现过程
1、lseek,read,write无需改变
2、偏移量使用off_t类型
3、printf("%lld\n", (long long) off_t的变量)
*/
int fd = open("test", O_LARGEFILE|O_RDWR|O_APPEND, 0666);
方法二:
使用标准c库函数中除宏定义和头文件声明中#include <sys/types.h>已经偏移量使用off_t相同外,还需做如下改变:
fseek( )->fseeko( )
ftell( )->ftello( )