Public bug reported:
Hi,
I have a problem using ftello64 with a file larger than 2GB. Actually I do not
know whether the error is really in ftello64 or in the compiler or even in the
linked library.
I am using feisty 64bit.
This is the code I use to test the error:
/* code */
#include <stdio.h>
int main(int argc, char *argv[])
{
char *namefilein;
FILE *filein;
long long size_gp, size_tl;
namefilein = argv[1];
printf("Size of file %s retrieved in different ways\n", namefilein);
filein = fopen(namefilein, "rb");
if(NULL == filein) {
fprintf(stderr, "Error: Cannot open input file for reading.\n");
return 1;
}
if(fseeko64(filein, 0, SEEK_END)) { /* jump to the end */
fprintf(stderr, "Error: Cannot jump to end.\n");
return 2;
}
if(fgetpos64(filein, &size_gp)) {
fprintf(stderr, "Error: fgetpos64 returned nonzero value.\n");
return 3;
}
size_tl = ftello64(filein);
printf("fgetpos64 var(%db) %lld\nftello64 var(%db) %lld\nftello64 inline
%lld\n", 8*sizeof(size_gp), size_gp, 8*sizeof(size_tl), size_tl,
ftello64(filein));
fclose(filein);
return 0;
}
/* end code */
compiled with "gcc -O3 -o test_hugefiles test_hugefiles.c"
It works fine with small files but not with large ones, This is the output with
a large file:
/* output */
Size of file hugefile.hf retrieved in different ways
fgetpos64 var(64b) 4188865024
ftello64 var(64b) -106102272
ftello64 inline 4188865024
/* end output */
The weird thing is ftello64 probably returns the right value (as shown by the
fact that it works fine when used inline) but this value is not stored in the
proper way in size_tl even if size_tl is large enough (64bit) to contain it.
A possible issue could be in the way the returned values are passed (using
registers?).
I also attach the generated assembly code of the key point of the program
/* asm */
.L7:
movq %rbp, %rdi # filein, filein
xorl %eax, %eax #
call ftello64 #
movq %rbp, %rdi # filein, filein
movl %eax, %ebx #, D.2231
xorl %eax, %eax #
call ftello64 #
movq 16(%rsp), %rdx # size_gp, size_gp
movl %eax, %r9d # D.2232, D.2232
movslq %ebx,%r8 # D.2231, D.2231
movl $64, %ecx #,
movl $64, %esi #,
movl $.LC5, %edi #,
xorl %eax, %eax #
call printf #
movq %rbp, %rdi # filein, filein
call fclose #
xorl %eax, %eax # D.2228
jmp .L4 #
/* end asm */
I hope this bug could be fixed and I am also curious about what's wrong.
Cheers,
Luca
** Affects: glibc (Ubuntu)
Importance: Undecided
Status: Unconfirmed
--
ftello64 not working with large files
https://bugs.launchpad.net/bugs/113791
You received this bug notification because you are a member of Ubuntu
Bugs, which is the bug contact for Ubuntu.
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs