aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Palevich <jack.palevich@gmail.com>2015-03-29 11:06:04 -0700
committerJack Palevich <jack.palevich@gmail.com>2015-03-29 11:06:04 -0700
commit202248141ade1210080bed6bd7549ea73ebd1582 (patch)
treec12d9baf124605a5a2b6e81fa7cc8195d94d2224
parent245138af598ab08a5e33a0e2c4fa5d49b20f3d9b (diff)
downloadAndroidTerm-202248141ade1210080bed6bd7549ea73ebd1582.tar.gz
Make library work with Bionic API level 4 again.
-rw-r--r--term/src/main/jni/termExec.cpp16
1 files 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");
}