From 202248141ade1210080bed6bd7549ea73ebd1582 Mon Sep 17 00:00:00 2001 From: Jack Palevich Date: Sun, 29 Mar 2015 11:06:04 -0700 Subject: [PATCH] Make library work with Bionic API level 4 again. --- term/src/main/jni/termExec.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/term/src/main/jni/termExec.cpp b/term/src/main/jni/termExec.cpp index 7a84640..8859728 100644 --- a/term/src/main/jni/termExec.cpp +++ b/term/src/main/jni/termExec.cpp @@ -45,12 +45,24 @@ static void android_os_Exec_setPtyWindowSize(JNIEnv *env, jobject clazz, env->ThrowNew(env->FindClass("java/io/IOException"), "Failed to issue TIOCSWINSZ ioctl"); } +// tcgetattr /tcsetattr are not part of Bionic at API level 4. Here's a compatible version. + +static __inline__ int my_tcgetattr(int fd, struct termios *s) +{ + return ioctl(fd, TCGETS, s); +} + +static __inline__ int my_tcsetattr(int fd, int __opt, const struct termios *s) +{ + return ioctl(fd, __opt, (void *)s); +} + static void android_os_Exec_setPtyUTF8Mode(JNIEnv *env, jobject clazz, jint fd, jboolean utf8Mode) { struct termios tios; // TODO: handle the situation, when the file descriptor is incompatible with tcgetattr (e.g. not from /dev/ptmx) - if (tcgetattr(fd, &tios) < 0) + if (my_tcgetattr(fd, &tios) < 0) env->ThrowNew(env->FindClass("java/io/IOException"), "Failed to get terminal attributes"); if (utf8Mode) { @@ -59,7 +71,7 @@ static void android_os_Exec_setPtyUTF8Mode(JNIEnv *env, jobject clazz, jint fd, tios.c_iflag &= ~IUTF8; } - if (tcsetattr(fd, TCSANOW, &tios) < 0) + if (my_tcsetattr(fd, TCSANOW, &tios) < 0) env->ThrowNew(env->FindClass("java/io/IOException"), "Failed to change terminal UTF-8 mode"); }