Add native method to set/clear UTF-8 input flag on tty

The Linux (>= 2.6.4) terminal driver uses the IUTF8 flag for
termios.c_iflag to implement correct character erase behavior in cooked
mode.  The flag has to be set from native code, so provide a method to
do it.
This commit is contained in:
Steven Luo 2012-04-29 02:22:04 -07:00
parent 337408e23a
commit f861544988
2 changed files with 30 additions and 0 deletions

View File

@ -267,6 +267,27 @@ static void android_os_Exec_setPtyWindowSize(JNIEnv *env, jobject clazz,
ioctl(fd, TIOCSWINSZ, &sz);
}
static void android_os_Exec_setPtyUTF8Mode(JNIEnv *env, jobject clazz,
jobject fileDescriptor, jboolean utf8Mode)
{
int fd;
struct termios tios;
fd = env->GetIntField(fileDescriptor, field_fileDescriptor_descriptor);
if (env->ExceptionOccurred() != NULL) {
return;
}
tcgetattr(fd, &tios);
if (utf8Mode) {
tios.c_iflag |= IUTF8;
} else {
tios.c_iflag &= ~IUTF8;
}
tcsetattr(fd, TCSANOW, &tios);
}
static int android_os_Exec_waitFor(JNIEnv *env, jobject clazz,
jint procId) {
int status;
@ -336,6 +357,8 @@ static JNINativeMethod method_table[] = {
(void*) android_os_Exec_createSubProcess },
{ "setPtyWindowSize", "(Ljava/io/FileDescriptor;IIII)V",
(void*) android_os_Exec_setPtyWindowSize},
{ "setPtyUTF8Mode", "(Ljava/io/FileDescriptor;Z)V",
(void*) android_os_Exec_setPtyUTF8Mode},
{ "waitFor", "(I)I",
(void*) android_os_Exec_waitFor},
{ "close", "(Ljava/io/FileDescriptor;)V",

View File

@ -59,6 +59,13 @@ public class Exec
public static native void setPtyWindowSize(FileDescriptor fd,
int row, int col, int xpixel, int ypixel);
/**
* Set or clear UTF-8 mode for a given pty. Used by the terminal driver
* to implement correct erase behavior in cooked mode (Linux >= 2.6.4).
*/
public static native void setPtyUTF8Mode(FileDescriptor fd,
boolean utf8Mode);
/**
* Causes the calling thread to wait for the process associated with the
* receiver to finish executing.