mIRC Homepage
Posted By: Wims file handling bug - 29/06/11 01:24 PM
After $freading a whole file, mIRC doesn't fill the 'end of file' propriety, though another call of $fread (returning $null and not even 0) fills the propriety.

Code:
alias fh_bug {
  bset &a 2000 1 
  bwrite test -1 -1 &a 
  .fopen test test
  echo -a file: $lof(test) bytes
  echo -a read $fread(test,2000,&r) bytes
  echo -a end of file or error ? $fopen(test).eof - $fopen(test).err 
  echo -a read $fread(test,2000,&r) bytes
  echo -a end of file or error ? $fopen(test).eof - $fopen(test).err
  .fclose test 
  .remove test
}

Posted By: FroggieDaFrog Re: file handling bug - 29/06/11 01:35 PM
Confirmed here. Ran into this problem when using sockets and thought I was doing something wrong.
Posted By: argv0 Re: file handling bug - 29/06/11 05:37 PM
This behaviour is expected and intentional.

.eof is toggled when the eof bit on the file handle is toggled, specifically by checking with the feof() function. mIRC does not check against the file size. In other words, mIRC does not know you've reached the end of the file until you've read *past* the end and toggled the eof bit. That's the only way feof() (and mIRC by extension) will know the EOF was reached.

If you don't want to use this .eof bit, you should check against the file length on your own. This is not what the .eof bit is meant for.
Posted By: Wims Re: file handling bug - 29/06/11 07:18 PM
Ah that's right, I already solved my problem anyway, I'm still using .eof but I also check $fread's value before doing anything, I thought $fread couldn't return something less than 1, but it should return 0 instead of $null when that case happens (you've read everything but you need another call to $fread to get the .eof proriety set) because $fread() return the number of byte read in that case
Posted By: argv0 Re: file handling bug - 29/06/11 07:35 PM
Yes, mIRC should probably return 0 on subsequent calls to $fread when the eof bit is set, not $null.
Posted By: Wims Re: file handling bug - 29/06/11 07:48 PM
Well here it returns $null before the eof bit is set, but yeah it should just return 0 whenever no byte is read and regardless of the eof bit
© mIRC Discussion Forums