summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIto Kazumitsu <kaz@maczuka.gcd.org>2007-05-24 22:15:20 +0000
committerIto Kazumitsu <kaz@maczuka.gcd.org>2007-05-24 22:15:20 +0000
commit108e3d9bf97764ffd12e9f9b701d50d69b75b90a (patch)
tree109156b0eb70fdeb16377c89fe25490a0c744bd4
parent4038e1edf3cc3ad4eb53f873ecf6a2fd1565c695 (diff)
downloadclasspath-108e3d9bf97764ffd12e9f9b701d50d69b75b90a.tar.gz
2007-05-24 Ito Kazumitsu <kaz@maczuka.gcd.org>
* 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.
-rw-r--r--ChangeLog7
-rw-r--r--native/jni/java-nio/gnu_java_nio_VMChannel.c49
-rw-r--r--native/jni/native-lib/cpio.c6
3 files changed, 59 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 28678c36d..fbd23e525 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-05-24 Ito Kazumitsu <kaz@maczuka.gcd.org>
+
+ * 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.
+
2007-05-24 Roman Kennke <roman@kennke.org>
* gnu/java/math/Fixed.java
diff --git a/native/jni/java-nio/gnu_java_nio_VMChannel.c b/native/jni/java-nio/gnu_java_nio_VMChannel.c
index c8df841a1..786b0026e 100644
--- a/native/jni/java-nio/gnu_java_nio_VMChannel.c
+++ b/native/jni/java-nio/gnu_java_nio_VMChannel.c
@@ -1582,6 +1582,8 @@ Java_gnu_java_nio_VMChannel_available (JNIEnv *env,
jclass c __attribute__((unused)),
jint fd)
{
+#if defined (FIONREAD)
+
jint avail = 0;
/* NIODBG("fd: %d", fd); */
@@ -1590,6 +1592,53 @@ Java_gnu_java_nio_VMChannel_available (JNIEnv *env,
/* 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
}
diff --git a/native/jni/native-lib/cpio.c b/native/jni/native-lib/cpio.c
index ac3c0b5e7..743968bd3 100644
--- a/native/jni/native-lib/cpio.c
+++ b/native/jni/native-lib/cpio.c
@@ -158,14 +158,14 @@ JNIEXPORT int cpio_availableBytes (int fd, jlong *bytes_available)
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 @@ JNIEXPORT int cpio_availableBytes (int fd, jlong *bytes_available)
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;