java.io.IOException bug SOLVED!
Robert S. Thau
rst at ai.mit.edu
Sat Jul 18 05:20:43 PDT 1998
Jake Hamby writes:
> Okay, I figured out the cause of this bug. In the native methods for
> FileInputStream, the available() method uses the FIONREAD ioctl() to
> figure out the number of bytes available to read. Apparently this works
> in at least BSD and Linux, but not in Solaris (and maybe other SVR4's?).
> The solution is to use fstat() to check if the file descriptor is a
> regular file, and if so, use lseek() to determine how many bytes are
> remaining, otherwise use FIONREAD (or select()) as before.
Hmmmm... rather than getting the file size with an lseek out and an
lseek back, as in your patch, it might be better to simply get the
file size out of the fstat() result. (In your patch as written,
suppose some other thread runs between the second and third lseeks.
Any reads of the same file done by the other thread will falsely
return EOF. Besides, it saves a system call).
> + /*
> + * We can always get the remaining bytes in a regular file.
> + */
> + if(buf.st_mode & S_IFREG) {
> + int cur = lseek(fd, 0, SEEK_SET);
> + nr = lseek(fd, 0, SEEK_END);
> + lseek(fd, cur, SEEK_SET);
> + return nr;
> + }
One last thing... should the last line read "return nr - cur"?
rst
More information about the kaffe
mailing list