The key point is to add the-d_file_offset_bits = 64 Macro during compilation,ProgramIn, replace fseek and ftell with fseeko and ftello respectively.
-----------------------------------------------------
Man fseeko
Description
TheFseeko ()AndFtello ()Functions are identicalFseek ()AndFtell ()(SeeFseek(3), respectively, doesn't thatOffsetArgumentFseeko ()And the return valueFtello ()Is of TypeOff_tInsteadLong.
On ubuntures bothOff_tAndLongAre 32-bit types, but compilation
-
# DEFINE _ file_offset_bits 64
Will turnOff_tInto a 64-bit type.
-----------------------------------------------------
Compilation Method:
#! /Bin/sh
Arm-mv5sft-linux-gnueabi-gcc-d_file_offset_bits = 64 main. C-o Test
Gcc-d_file_offset_bits = 64 main. C-o x86test
Source program:
# Include <stdio. h>
# Include <sys/STAT. h>
# Include <sys/types. h>
# Include <unistd. h>
# Include <assert. h>
# Define FILENAME "10g. IMG"
# Define readbufsize 100
Int main ()
{
Printf ("sizeof (size_t) % d, sizeof (off_t) % d \ n", sizeof (size_t), sizeof (off_t ));
Struct stat Buf;
If (STAT (filename, & BUF )! = 0)
{
Perror ("stat :");
Return-1;
}
Printf ("% LLD \ n", Buf. st_size );
File * stream = fopen (filename, "RW ");
If (! Stream)
{
Perror ("fopen :");
Return-1;
}
Char readbuf [readbufsize];
{
Size_t ret = fread (readbuf, readbufsize, 1, stream );
Printf ("fread: % u \ n", RET );
Assert (ret = 1 );
}
Printf ("% LLD \ n", ftello (Stream ));
If (fseeko (stream,-100, seek_end )! = 0)
{
Perror ("fseeko :");
Return-1;
}
{
Size_t ret = fread (readbuf, readbufsize, 1, stream );
Printf ("fread: % u \ n", RET );
Assert (ret = 1 );
}
Printf ("% LLD \ n", ftello (Stream ));
Return 0;
}
Running result:
/Mnt/diska/partition1 #./test
Sizeof (size_t) 4, sizeof (off_t) 8
10485760000
Fread: 1
100
Fread: 1
10485760000