2

I am trying to replicate WIN32 code for MacOSX, however I am unable to replicate a part of code

Here is the code.

main_int64 pos;
  OP_ASSERT(sizeof(pos)==sizeof(fpos_t));
  /*Translate the seek to an absolute one.*/
  if(_whence==SEEK_CUR)
  {
    int ret;
    ret=fgetpos((FILE *)_stream,(fpos_t *)&pos);
    if(ret)return ret;
  }
  else if(_whence==SEEK_END)pos=_filelengthi64(_fileno((FILE *)_stream));
  else if(_whence==SEEK_SET)pos=0;
  else return -1;
  /*Check for errors or overflow.*/
  if(pos<0||_offset<-pos||_offset>OP_INT64_MAX-pos)return -1;
  pos+=_offset;

  int seeko = fsetpos((FILE *)_stream,(fpos_t *)&pos);
  fprintf("BaseTool", "SEEKO VALUE %d \n", seeko);
  return seeko;

I am stuck at

else if(_whence==SEEK_END)pos=_filelengthi64(_fileno((FILE *)_stream));

I am not sure how can I replace these functions in mac based system as these are WIN based functions

Muhammad Umar
  • 11,391
  • 21
  • 91
  • 193

1 Answers1

1

from the code I understand you are trying to get the length of the file, in linux you can do this way,

 int fp           = open("check5.c", O_RDONLY);
off_t lengthOfFile = lseek(fp, 0, SEEK_END);
close(fp);
printf("%d",lengthOfFile);

So replace it with "lseek(fileno,0, SEEK_END)" should give length of the file.