Skip to content

Commit

Permalink
Fix openpty support for jna and jansi
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Apr 28, 2017
1 parent 3f255ae commit e734d9b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e734d9b

Please sign in to comment.