Make library work with Bionic API level 4 again.

This commit is contained in:
Jack Palevich 2015-03-29 11:06:04 -07:00
parent 245138af59
commit 202248141a

View File

@ -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");
}