From e734d9bc0e758c59d7c404af8586f16310f1848d Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 28 Apr 2017 16:11:31 +0200 Subject: [PATCH] Fix openpty support for jna and jansi --- .../terminal/impl/jansi/freebsd/FreeBsdNativePty.java | 4 ++-- .../terminal/impl/jansi/linux/LinuxNativePty.java | 4 ++-- .../org/jline/terminal/impl/jna/freebsd/CLibrary.java | 4 ---- .../terminal/impl/jna/freebsd/FreeBsdNativePty.java | 10 +++++++++- .../org/jline/terminal/impl/jna/linux/CLibrary.java | 4 ---- .../jline/terminal/impl/jna/linux/LinuxNativePty.java | 10 +++++++++- .../java/org/jline/terminal/impl/jna/osx/CLibrary.java | 2 -- 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/terminal-jansi/src/main/java/org/jline/terminal/impl/jansi/freebsd/FreeBsdNativePty.java b/terminal-jansi/src/main/java/org/jline/terminal/impl/jansi/freebsd/FreeBsdNativePty.java index 04cb27243..63f4a8772 100644 --- a/terminal-jansi/src/main/java/org/jline/terminal/impl/jansi/freebsd/FreeBsdNativePty.java +++ b/terminal-jansi/src/main/java/org/jline/terminal/impl/jansi/freebsd/FreeBsdNativePty.java @@ -30,7 +30,7 @@ public static FreeBsdNativePty current() throws IOException { } } - public static OsXNativePty open(Attributes attr, Size size) throws IOException { + public static FreeBsdNativePty open(Attributes attr, Size size) throws IOException { int[] master = new int[1]; int[] slave = new int[1]; byte[] buf = new byte[64]; @@ -42,7 +42,7 @@ public static OsXNativePty open(Attributes attr, Size size) throws IOException { len++; } String name = new String(buf, 0, len); - return new OsXNativePty(master[0], newDescriptor(master[0]), slave[0], newDescriptor(slave[0]), name); + return new FreeBsdNativePty(master[0], newDescriptor(master[0]), slave[0], newDescriptor(slave[0]), name); } public FreeBsdNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, String name) { diff --git a/terminal-jansi/src/main/java/org/jline/terminal/impl/jansi/linux/LinuxNativePty.java b/terminal-jansi/src/main/java/org/jline/terminal/impl/jansi/linux/LinuxNativePty.java index f3fd05d04..d0f942699 100644 --- a/terminal-jansi/src/main/java/org/jline/terminal/impl/jansi/linux/LinuxNativePty.java +++ b/terminal-jansi/src/main/java/org/jline/terminal/impl/jansi/linux/LinuxNativePty.java @@ -30,7 +30,7 @@ public static LinuxNativePty current() throws IOException { } } - public static OsXNativePty open(Attributes attr, Size size) throws IOException { + public static LinuxNativePty open(Attributes attr, Size size) throws IOException { int[] master = new int[1]; int[] slave = new int[1]; byte[] buf = new byte[64]; @@ -42,7 +42,7 @@ public static OsXNativePty open(Attributes attr, Size size) throws IOException { len++; } String name = new String(buf, 0, len); - return new OsXNativePty(master[0], newDescriptor(master[0]), slave[0], newDescriptor(slave[0]), name); + return new LinuxNativePty(master[0], newDescriptor(master[0]), slave[0], newDescriptor(slave[0]), name); } public LinuxNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, String name) { diff --git a/terminal-jna/src/main/java/org/jline/terminal/impl/jna/freebsd/CLibrary.java b/terminal-jna/src/main/java/org/jline/terminal/impl/jna/freebsd/CLibrary.java index da7f20fd2..79bd429e1 100644 --- a/terminal-jna/src/main/java/org/jline/terminal/impl/jna/freebsd/CLibrary.java +++ b/terminal-jna/src/main/java/org/jline/terminal/impl/jna/freebsd/CLibrary.java @@ -31,12 +31,8 @@ public interface CLibrary extends com.sun.jna.Library { void ioctl(int fd, long cmd, winsize data) throws LastErrorException; -// int isatty(int fd); - void ttyname_r(int fd, byte[] buf, int len) throws LastErrorException; - void openpty(int[] master, int[] slave, byte[] name, termios t, winsize s) throws LastErrorException; - class winsize extends Structure { public short ws_row; public short ws_col; diff --git a/terminal-jna/src/main/java/org/jline/terminal/impl/jna/freebsd/FreeBsdNativePty.java b/terminal-jna/src/main/java/org/jline/terminal/impl/jna/freebsd/FreeBsdNativePty.java index 0fff952d4..bccb10f61 100644 --- a/terminal-jna/src/main/java/org/jline/terminal/impl/jna/freebsd/FreeBsdNativePty.java +++ b/terminal-jna/src/main/java/org/jline/terminal/impl/jna/freebsd/FreeBsdNativePty.java @@ -11,6 +11,7 @@ import java.io.FileDescriptor; import java.io.IOException; +import com.sun.jna.LastErrorException; import com.sun.jna.Native; import com.sun.jna.Platform; import org.jline.terminal.Attributes; @@ -27,6 +28,13 @@ public class FreeBsdNativePty extends JnaNativePty { private static final CLibrary C_LIBRARY = (CLibrary) Native.loadLibrary(Platform.C_LIBRARY_NAME, CLibrary.class); + public interface UtilLibrary extends com.sun.jna.Library { + + void openpty(int[] master, int[] slave, byte[] name, CLibrary.termios t, CLibrary.winsize s) throws LastErrorException; + + UtilLibrary INSTANCE = (UtilLibrary) Native.loadLibrary("util", UtilLibrary.class); + } + public static FreeBsdNativePty current() throws IOException { int slave = 0; byte[] buf = new byte[64]; @@ -43,7 +51,7 @@ public static FreeBsdNativePty open(Attributes attr, Size size) throws IOExcepti int[] master = new int[1]; int[] slave = new int[1]; byte[] buf = new byte[64]; - C_LIBRARY.openpty(master, slave, buf, + UtilLibrary.INSTANCE.openpty(master, slave, buf, attr != null ? new termios(attr) : null, size != null ? new winsize(size) : null); int len = 0; diff --git a/terminal-jna/src/main/java/org/jline/terminal/impl/jna/linux/CLibrary.java b/terminal-jna/src/main/java/org/jline/terminal/impl/jna/linux/CLibrary.java index ee6584a41..08fc74283 100644 --- a/terminal-jna/src/main/java/org/jline/terminal/impl/jna/linux/CLibrary.java +++ b/terminal-jna/src/main/java/org/jline/terminal/impl/jna/linux/CLibrary.java @@ -31,12 +31,8 @@ public interface CLibrary extends com.sun.jna.Library { void ioctl(int fd, int cmd, winsize data) throws LastErrorException; -// int isatty(int fd); - void ttyname_r(int fd, byte[] buf, int len) throws LastErrorException; - void openpty(int[] master, int[] slave, byte[] name, termios t, winsize s) throws LastErrorException; - class winsize extends Structure { public short ws_row; public short ws_col; diff --git a/terminal-jna/src/main/java/org/jline/terminal/impl/jna/linux/LinuxNativePty.java b/terminal-jna/src/main/java/org/jline/terminal/impl/jna/linux/LinuxNativePty.java index b30440139..d049aa65b 100644 --- a/terminal-jna/src/main/java/org/jline/terminal/impl/jna/linux/LinuxNativePty.java +++ b/terminal-jna/src/main/java/org/jline/terminal/impl/jna/linux/LinuxNativePty.java @@ -11,6 +11,7 @@ import java.io.FileDescriptor; import java.io.IOException; +import com.sun.jna.LastErrorException; import com.sun.jna.Native; import com.sun.jna.Platform; import org.jline.terminal.Attributes; @@ -27,6 +28,13 @@ public class LinuxNativePty extends JnaNativePty { private static final CLibrary C_LIBRARY = (CLibrary) Native.loadLibrary(Platform.C_LIBRARY_NAME, CLibrary.class); + public interface UtilLibrary extends com.sun.jna.Library { + + void openpty(int[] master, int[] slave, byte[] name, CLibrary.termios t, CLibrary.winsize s) throws LastErrorException; + + UtilLibrary INSTANCE = (UtilLibrary) Native.loadLibrary("util", UtilLibrary.class); + } + public static LinuxNativePty current() throws IOException { int slave = 0; byte[] buf = new byte[64]; @@ -43,7 +51,7 @@ public static LinuxNativePty open(Attributes attr, Size size) throws IOException int[] master = new int[1]; int[] slave = new int[1]; byte[] buf = new byte[64]; - C_LIBRARY.openpty(master, slave, buf, + UtilLibrary.INSTANCE.openpty(master, slave, buf, attr != null ? new termios(attr) : null, size != null ? new winsize(size) : null); int len = 0; diff --git a/terminal-jna/src/main/java/org/jline/terminal/impl/jna/osx/CLibrary.java b/terminal-jna/src/main/java/org/jline/terminal/impl/jna/osx/CLibrary.java index e935ba045..260335b15 100644 --- a/terminal-jna/src/main/java/org/jline/terminal/impl/jna/osx/CLibrary.java +++ b/terminal-jna/src/main/java/org/jline/terminal/impl/jna/osx/CLibrary.java @@ -32,8 +32,6 @@ public interface CLibrary extends com.sun.jna.Library { void ioctl(int fd, NativeLong cmd, winsize data) throws LastErrorException; -// int isatty(int fd); - void ttyname_r(int fd, byte[] buf, int len) throws LastErrorException; void openpty(int[] master, int[] slave, byte[] name, termios t, winsize s) throws LastErrorException;