newlib ftello64/fseeko64 not working

A forum for general AmigaOS 4.x support questions that are not platform-specific
Post Reply
chris
Posts: 562
Joined: Sat Jun 18, 2011 11:05 am
Contact:

newlib ftello64/fseeko64 not working

Post 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.
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Re: newlib ftello64/fseeko64 not working

Post 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.
AmigaOne X1000 with 2GB memory - OS4.1 FE
chris
Posts: 562
Joined: Sat Jun 18, 2011 11:05 am
Contact:

Re: newlib ftello64/fseeko64 not working

Post 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
Post Reply