Re: File::Stat#blksize etc. should return nil instead of 0

From: matz@... (Yukihiro Matsumoto)
Date: 2002-08-07 10:26:17 UTC
List: ruby-core #306
Hi,

In message "File::Stat#blksize etc. should return nil instead of 0"
    on 02/08/07, Florian Frank <flori@nixe.ping.de> writes:

|On Sun, 2002-08-04 at 01:45, Yukihiro Matsumoto wrote:
|> I'd like to hear from others,
|> especially those who working on the platforms without these members in
|> struct stat.
|
|Ok, nobody seems to use those platforms (MS Windows, I guess) anyway. ;)
|
|But I can try to explain more clearly where I see a problem. If somebody
|writes some code like this
|
|File.open(File.join("anyfile") do |f|
|	until f.eof?
|		s = f.read(f.stat.blksize)
|		# do something
|	end
|end
|
|it will work ok, if the platform supports blksize. If it doesn't this
|will be an infinite loop because many reads of 0 bytes won't reach EOF.
|With nil it would be ok by accident.
|
|If f.read(8 * f.stat.blksize) is used, a type error will occur. But such
|an error is probably better than a semantic error which causes the
|program to get stuck in a loop.

Sounds reasonable.  If no one stands against the idea, I will apply
your patch in the near future.

							matz.

In This Thread