_fseeki64/_ftelli64 cross platform?

Emulation of old PCs, PC hardware, or PC peripherals.

_fseeki64/_ftelli64 cross platform?

Postby superfury » 2019-2-01 @ 14:48

I'm trying to get my 64-bit file I/O in UniPCemu to be cross-platform completely. The reads and writes to files have no complications(since they use the internal number to keep track of the current file position), but _fseeki64 and _ftelli64 seems to have problems with e.g. MinGW builds?

Code: Select all
#if defined(VISUALC) || (defined(_fseeki64) && defined(_ftelli64))
   if (!(result = _fseeki64(b->f, pos, direction))) //Direction is constant itself!
   {
      b->position = _ftelli64(b->f); //Use our own position indicator!
   }
#elif defined(fseeki64) && defined(ftelli64)
   if (!(result = fseeki64(b->f, pos, direction))) //Direction is constant itself!
   {
      b->position = ftelli64(b->f); //Use our own position indicator!
   }
#elif defined(_fseeko64) && defined(_ftello64)
   if (!(result = _fseeko64(b->f, pos, direction))) //Direction is constant itself!
   {
      b->position = _ftello64(b->f); //Use our own position indicator!
   }
#elif defined(fseeko64) && defined(ftello64)
   if (!(result = fseeko64(b->f, pos, direction))) //Direction is constant itself!
   {
      b->position = ftello64(b->f); //Use our own position indicator!
   }
#elif defined(_fseeko) && defined(_ftello)
   if (!(result = _fseeko(b->f, pos, direction))) //Direction is constant itself!
   {
      b->position = _ftello(b->f); //Use our own position indicator!
   }
#elif defined(fseeko) && defined(ftello)
   if (!(result = fseeko(b->f, pos, direction))) //Direction is constant itself!
   {
      b->position = ftello(b->f); //Use our own position indicator!
   }
#else
   if (!(result = fseek(b->f, pos, direction))) //Direction is constant itself!
   {
      b->position = ftell(b->f); //Use our own position indicator!
   }
#endif


For some reason, it ends up at the normal fseek and ftell when using MinGW?

Anyone?
superfury
l33t
 
Posts: 3228
Joined: 2014-3-08 @ 11:25
Location: Netherlands

Re: _fseeki64/_ftelli64 cross platform?

Postby superfury » 2019-2-01 @ 16:23

Having revised this code to:
Code: Select all
#ifdef IS_WINDOWS
   if (!(result = _fseeki64(b->f, pos, direction))) //Direction is constant itself!
   {
      b->position = _ftelli64(b->f); //Use our own position indicator!
   }
#elif defined(IS_LINUX)
   if (!(result = fseeko(b->f, pos, direction))) //Direction is constant itself!
   {
      b->position = ftello(b->f); //Use our own position indicator!
   }
#else
   if (!(result = fseek(b->f, pos, direction))) //Direction is constant itself!
   {
      b->position = ftell(b->f); //Use our own position indicator!
   }
#endif


This should have fixed any portability issues(with both Android and Windows having improved behaviour on this(Android builds define IS_LINUX in the UniPCemu(common emulator framework) headers)).
superfury
l33t
 
Posts: 3228
Joined: 2014-3-08 @ 11:25
Location: Netherlands


Return to PC Emulation

Who is online

Users browsing this forum: No registered users and 2 guests