Hi,

This patch helps fix bug #31927.

Although it does not directly fix #31927, FreeBSD users may
change the line

#if defined (FIONREAD)

to

#if defined (FIONREAD) && 0

as a workaround of this bug.

ChangeLog:
2007-05-21  Ito Kazumitsu  <[EMAIL PROTECTED]>

        * native/jni/java-nio/gnu_java_nio_VMChannel.c
        (Java_gnu_java_nio_VMChannel_available): Use fstat or select as an
        alternative to ioctl.
        * native/jni/native-lib/cpio.c(cpio_availableBytes): Corrected typo.

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.17
diff -u -r1.17 gnu_java_nio_VMChannel.c
--- classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c      17 Apr 2007 
21:46:27 -0000      1.17
+++ classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c      21 May 2007 
22:48:34 -0000
@@ -1582,6 +1582,8 @@
                                        jclass c __attribute__((unused)),
                                        jint fd)
 {
+#if defined (FIONREAD)
+
   jint avail = 0;
 
 /*   NIODBG("fd: %d", fd); */
@@ -1590,6 +1592,53 @@
 /*   NIODBG("avail: %d", avail); */
 
   return avail;
+
+#elif defined(HAVE_FSTAT)
+
+  jint avail = 0;
+
+  struct stat statBuffer;
+  off_t n;
+
+  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;
+        } 
+    }
+  JCL_ThrowException (env, IO_EXCEPTION, strerror (errno));
+
+#elif defined(HAVE_SELECT)
+
+  jint avail = 0;
+  fd_set filedescriptset;
+  struct timeval tv;
+
+  FD_ZERO (&filedescriptset);
+  FD_SET (fd,&filedescriptset);
+  memset (&tv, 0, sizeof(tv));
+
+  switch (select (fd+1, &filedescriptset, NULL, NULL, &tv))
+    {
+      case -1:
+        break;
+      case  0:
+        avail = 0;
+       return avail;
+      default:
+        avail = 1;
+       return avail;
+    }
+  JCL_ThrowException (env, IO_EXCEPTION, strerror (errno));
+
+#else
+
+  JCL_ThrowException (env, IO_EXCEPTION, "No native method for available");
+
+#endif
 }
 
 
Index: classpath/native/jni/native-lib/cpio.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/native-lib/cpio.c,v
retrieving revision 1.7
diff -u -r1.7 cpio.c
--- classpath/native/jni/native-lib/cpio.c      9 Feb 2007 19:51:07 -0000       
1.7
+++ classpath/native/jni/native-lib/cpio.c      21 May 2007 22:48:34 -0000
@@ -158,14 +158,14 @@
   off_t n;
   int result;
 
-  *bytes_available = 0
+  *bytes_available = 0;
   if ((fstat (fd, &statBuffer) == 0) && S_ISREG (statBuffer.st_mode))
     {
       n = lseek (fd, 0, SEEK_CUR);
       if (n != -1) 
        { 
          *bytes_available = statBuffer.st_size - n; 
-         result = 0;
+         result = CPNATIVE_OK;
        } 
       else 
        { 
@@ -189,7 +189,7 @@
   FD_SET (fd,&filedescriptset);
   memset (&tv, 0, sizeof(tv));
 
-  switch (select (fd+1, &filedescriptset, NULL, NULL, &timeval)) \
+  switch (select (fd+1, &filedescriptset, NULL, NULL, &tv))
     {
     case -1: 
       result=errno; 

Reply via email to