On Jun 20, 2007, at 3:32 PM, Ito Kazumitsu wrote:
Hi,
Hi Ito,
FreeBSD needs both ioctl and fstat, The former for character devices
and the latter for files.
This looks fine to me; I admit I haven't tried it, but nothing
obviously wrong jumps out at me.
Thanks.
ChangeLog:
2007-06-21 Ito Kazumitsu <[EMAIL PROTECTED]>
Fixes bug #30377
* native/jni/java-nio/gnu_java_nio_VMChannel.c
(Java_gnu_java_nio_VMChannel_available): Retry using fstat if ioctl
fails with ENOTTY.
Index: classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/java-nio/
gnu_java_nio_VMChannel.c,v
retrieving revision 1.19
diff -u -r1.19 gnu_java_nio_VMChannel.c
--- classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c 30 May
2007 09:56:57 -0000 1.19
+++ classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c 20 Jun
2007 22:22:14 -0000
@@ -1586,9 +1586,30 @@
jint avail = 0;
+#if defined(ENOTTY) && defined(HAVE_FSTAT)
+ struct stat statBuffer;
+ off_t n;
+#endif
+
/* NIODBG("fd: %d", fd); */
if (ioctl (fd, FIONREAD, &avail) == -1)
- JCL_ThrowException (env, IO_EXCEPTION, strerror (errno));
+ {
Not sure why you have this block...
+#if defined(ENOTTY) && defined(HAVE_FSTAT)
+ if (errno == ENOTTY)
+ {
+ if ((fstat (fd, &statBuffer) == 0) && S_ISREG
(statBuffer.st_mode))
+ {
+ n = lseek (fd, 0, SEEK_CUR);
+ if (n != -1)
+ {
+ avail = statBuffer.st_size - n;
+ return avail;
+ }
+ }
+ }
+#endif
+ JCL_ThrowException (env, IO_EXCEPTION, strerror (errno));
...surrounding it, though.
+ }
/* NIODBG("avail: %d", avail); */
return avail;