mIRC Home    About    Download    Register    News    Help

Print Thread
#232900 29/06/11 01:24 PM
Joined: Jul 2006
Posts: 4,145
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
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
}



#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #232901 29/06/11 01:35 PM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Confirmed here. Ran into this problem when using sockets and thought I was doing something wrong.


I am SReject
My Stuff
Wims #232907 29/06/11 05:37 PM
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
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.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
argv0 #232914 29/06/11 07:18 PM
Joined: Jul 2006
Posts: 4,145
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
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


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #232915 29/06/11 07:35 PM
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Yes, mIRC should probably return 0 on subsequent calls to $fread when the eof bit is set, not $null.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
argv0 #232916 29/06/11 07:48 PM
Joined: Jul 2006
Posts: 4,145
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
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


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard