diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index b8b7256bdd..a241aa1644 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -41,6 +41,7 @@ # include # include # include +# include # include # include # include @@ -49,6 +50,7 @@ # define CLOSE close # define READ read # define WRITE write +# define FSTAT fstat # define LSEEK lseek #endif // not PLATFORM_WINDOWS @@ -2372,6 +2374,18 @@ JVM_Write(jint fd, char* src, jint length) extern "C" JNIEXPORT jint JNICALL JVM_Available(jint fd, jlong* result) { + struct stat buffer; + int n; + if (FSTAT(fd, &buffer) >= 0 + and (S_ISCHR(buffer.st_mode) + or S_ISFIFO(buffer.st_mode) + or S_ISSOCK(buffer.st_mode)) + and ioctl(fd, FIONREAD, &n) >= 0) + { + *result = n; + return 1; + } + int current = LSEEK(fd, 0, SEEK_CUR); if (current == -1) return 0;