NO

Author Topic: fseek() - no long-int overflow indication  (Read 13378 times)

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: fseek() - no long-int overflow indication
« Reply #15 on: April 07, 2012, 03:29:26 PM »
Indeed PellesC doesn't actually have _ftell64 and _fseek64  :'(
Worst _ftello use 64 bits offset only for programs compiled for 64 bits, so you can't have large file handling with 32 bits programs.
The only workaround is to use the WinAPI SetFilePointer (http://msdn.microsoft.com/en-us/library/windows/desktop/aa365541(v=vs.85).aspx), but this is definitly not standard (M$ extension).
Anyway if you use the more standard border _ftello and _fseeko the program is limited in the 32 bits compile, but fully working in the 64 bit version.
This problem comes from the necessity to mantain standard compatibility, if the type used by fseek/ftell wuld be changed to long long types old pieces of sotware would not compile or not be compatible. Even if the problem should be limited becouse the compiler would convert between the returned long long to the coded long variables showing a warning of possible conversion overflow.
Now is clear why GCC create an explicit switch to extend file pointers to 64 bits  ::)

EDIT:
I was wrong. PellesC provide _lseek64 and _ltell64 using file handle. These routines should be available also on other compilers  :D
It sounded strange that Pelle have not considered the issue....
« Last Edit: April 07, 2012, 03:48:34 PM by frankie »
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

czerny

  • Guest
Re: fseek() - no long-int overflow indication
« Reply #16 on: April 07, 2012, 04:58:28 PM »
Quote
I was wrong. PellesC provide _lseek64 and _ltell64 using file handle.

It is named _tell64.

czerny

CommonTater

  • Guest
Re: fseek() - no long-int overflow indication
« Reply #17 on: April 07, 2012, 06:09:33 PM »
Indeed PellesC doesn't actually have _ftell64 and _fseek64  :'(

Indeed it doesn't... but as I just discovered and czerny points out... it does have _tell64() ....

But watch what you use with what...
The functions in io.h use integer file handles...
The ones in stdio.h use FILE structs.

(And _this_ is why I generally prefer OS API calls...)
 
@migf1...
To rebuild the database ...  Tools -> Options -> Folders -> Browse Info -> Build

(Sorry about all the edits.... Definately need my second cuppa caffine this morning!)
 
« Last Edit: April 07, 2012, 06:24:06 PM by CommonTater »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: fseek() - no long-int overflow indication
« Reply #18 on: April 07, 2012, 08:45:08 PM »
To use them with streams (FILE *) use _fileno function:
Code: [Select]
    offset64 = _tell64(_fileno(fp));
    _lseek64(_fileno(fp), offset64, SEEK_SET);

It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

CommonTater

  • Guest
Re: fseek() - no long-int overflow indication
« Reply #19 on: April 07, 2012, 08:50:51 PM »
Hey thanks for that frankie...  :D .... learn something new every day, ya?


migf1

  • Guest
Re: fseek() - no long-int overflow indication
« Reply #20 on: April 08, 2012, 09:04:32 AM »
Thanks for all the info guys!