1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Changes to source to fix 119618, binaries to be compiled.

This commit is contained in:
Markus Schorn 2006-04-27 16:16:09 +00:00
parent 488356be7d
commit 8272805b36
3 changed files with 53 additions and 0 deletions

View file

@ -14,6 +14,10 @@
#include <SpawnerOutputStream.h>
#include <unistd.h>
#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

View file

@ -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

View file

@ -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$
}
}