Hi,
FreeBSD needs both ioctl and fstat, The former for character devices
and the latter for files.
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));
+ {
+#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));
+ }
/* NIODBG("avail: %d", avail); */
return avail;