From 8272805b36b67b9ff569349292cb36493c207acc Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Thu, 27 Apr 2006 16:16:09 +0000 Subject: [PATCH] Changes to source to fix 119618, binaries to be compiled. --- core/org.eclipse.cdt.core.linux/library/io.c | 28 +++++++++++++++++++ .../library/iostream.c | 12 ++++++++ .../cdt/utils/spawner/SpawnerInputStream.java | 13 +++++++++ 3 files changed, 53 insertions(+) diff --git a/core/org.eclipse.cdt.core.linux/library/io.c b/core/org.eclipse.cdt.core.linux/library/io.c index 6070f33f29b..f63fca77104 100644 --- a/core/org.eclipse.cdt.core.linux/library/io.c +++ b/core/org.eclipse.cdt.core.linux/library/io.c @@ -14,6 +14,10 @@ #include #include +#define INT_MAX 2147483647 + +JNIEXPORT jint JNICALL JVM_Available(jint fd, jlong *pbytes); + /* Header for class _org_eclipse_cdt_utils_spawner_SpawnerInputStream */ /* Header for class _org_eclipse_cdt_utils_spawner_SpawnerOutputStream */ @@ -71,6 +75,30 @@ Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_close0(JNIEnv * env, return close(fd); } +JNIEXPORT jint JNICALL +Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_available0(JNIEnv * env, + jobject jobj, + jint fd) +{ + jlong ret; + + if (JVM_Available(fd, &ret)) { + if (ret > INT_MAX) { + ret = (jlong) INT_MAX; + } + return (jint)ret; + } + + /* Error, toss an exception */ + jclass exception = (*env)->FindClass(env, "java/io/IOException"); + if (exception == NULL) { + /* Give up. */ + return -1; + } + (*env)->ThrowNew(env, exception, NULL); + return 0; +} + /* * Class: org_eclipse_cdt_utils_spawner_SpawnerOutputStream * Method: write0 diff --git a/core/org.eclipse.cdt.core.win32/library/iostream.c b/core/org.eclipse.cdt.core.win32/library/iostream.c index 163a3a8b955..7beda1cdbc2 100644 --- a/core/org.eclipse.cdt.core.win32/library/iostream.c +++ b/core/org.eclipse.cdt.core.win32/library/iostream.c @@ -168,6 +168,18 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_clo return (rc ? GetLastError() : 0); } +JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_available0 + (JNIEnv * env, jobject proc, jint fd) +{ + int nAvail = 0; + + if (0 == PeekNamedPipe((HANDLE)fd, NULL, 0, NULL, &nAvail, NULL)) { + // error + return 0; + } + return nAvail; +} + /* * Class: SpawnerOutputStream * Method: write0 diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/SpawnerInputStream.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/SpawnerInputStream.java index 49a8fdda2a0..f19a4c52995 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/SpawnerInputStream.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/SpawnerInputStream.java @@ -43,6 +43,7 @@ class SpawnerInputStream extends InputStream { * @see InputStream#read(byte[], int, int) */ public int read(byte[] buf, int off, int len) throws IOException { + available(); if (buf == null) { throw new NullPointerException(); } else if ( @@ -78,11 +79,23 @@ class SpawnerInputStream extends InputStream { fd = -1; } + public int available() throws IOException { + try { + return available0(fd); + } + catch (UnsatisfiedLinkError e) { + // for those platforms that do not implement available0 + return super.available(); + } + } + private native int read0(int fileDesc, byte[] buf, int len) throws IOException; private native int close0(int fileDesc) throws IOException; + private native int available0(int fileDesc) throws IOException; static { System.loadLibrary("spawner"); //$NON-NLS-1$ } + }