Page 1 of 1

newlib ftello64/fseeko64 not working

Posted: Sun Oct 23, 2011 12:03 am
by chris
Maybe they are not implemented, but if so I'm surprised they are present in the includes. Here is an example I nicked from elsewhere (http://old.nabble.com/Re%3A-ftello64-re ... 03471.html):

Code: Select all

#include <stdio.h>  

int main()  
{  
     FILE * fp;  
     _off64_t pos;  

     fp = fopen("test.dat", "w+b");  
     fwrite("abcdefghijklmnopqrstuvwxyz", 1, 26, fp);  
     pos = ftello64(fp);  
     printf("ftello64 says our position is %d, it should be 26\n",  
(int)pos);  

     fseeko64(fp, 0, SEEK_END);  
     pos = ftello64(fp);  
     printf("now ftello64 says our position is %d, it should still be 26\n", (int)pos);  

     return 0;  
  }  
This returns:
ftello64 says our position is -1, it should be 26
now ftello64 says our position is -1, it should still be 26

I assume -1 is an error, but I have no documentation as to what this actually means.

Re: newlib ftello64/fseeko64 not working

Posted: Sun Oct 23, 2011 6:08 pm
by xenic
@chris
See what happens if you change fopen() to fopen64(). According to my C reference these functions are supposed to return -1 for an error but in newlib EOF is defined as -1 also. That seems like it could lead to some confusion.

Re: newlib ftello64/fseeko64 not working

Posted: Mon Oct 24, 2011 11:58 pm
by chris
xenic wrote:@chris
See what happens if you change fopen() to fopen64(). According to my C reference these functions are supposed to return -1 for an error but in newlib EOF is defined as -1 also. That seems like it could lead to some confusion.
Ah, that works, very interesting! - thanks