Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'native/org.eclipse.cdt.native.serial/jni/serial.c')
-rw-r--r--native/org.eclipse.cdt.native.serial/jni/serial.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/native/org.eclipse.cdt.native.serial/jni/serial.c b/native/org.eclipse.cdt.native.serial/jni/serial.c
index be6c549b1e..5e783b61c7 100644
--- a/native/org.eclipse.cdt.native.serial/jni/serial.c
+++ b/native/org.eclipse.cdt.native.serial/jni/serial.c
@@ -26,6 +26,7 @@
#include <string.h>
#include <strings.h>
#include <errno.h>
+#include <sys/ioctl.h>
#else
#define WIN32_LEAN_AND_MEAN
#define UNICODE
@@ -251,6 +252,32 @@ JNIEXPORT void JNICALL FUNC(close0)(JNIEnv *env, jobject jobj, jlong handle)
#endif
}
+JNIEXPORT jint JNICALL FUNC(available0)(JNIEnv * env, jobject jobj, jlong jhandle)
+{
+#ifndef __MINGW32__
+ int result = 0;
+ if (ioctl(jhandle, FIONREAD, &result ) < 0) {
+ throwIOException(env, "Error calling ioctl");
+ return 0;
+ }
+ return result;
+#else
+ COMSTAT stat;
+ DWORD errCode;
+#ifdef _WIN64
+ HANDLE handle = (HANDLE)jhandle;
+#else
+ HANDLE handle = (HANDLE)(unsigned)jhandle;
+#endif
+
+ if (ClearCommError(handle, &errCode, &stat) == 0) {
+ throwIOException(env, "Error calling ClearCommError");
+ return -1;
+ }
+ return (int)stat.cbInQue;
+#endif
+}
+
JNIEXPORT jint JNICALL FUNC(read1)(JNIEnv * env, jobject jobj, jlong jhandle, jbyteArray bytes, jint offset, jint size)
{
#ifndef __MINGW32__

Back to the top