termux-packages/packages/neovim/forkpty-android.patch

80 lines
2.1 KiB
Diff

diff -N -u -r ../neovim-master/src/nvim/os/forkpty-android.h ./src/nvim/os/forkpty-android.h
--- ../neovim-master/src/nvim/os/forkpty-android.h 1969-12-31 19:00:00.000000000 -0500
+++ ./src/nvim/os/forkpty-android.h 2015-03-23 18:59:01.425165645 -0400
@@ -0,0 +1,63 @@
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <unistd.h>
+
+int login_tty(int fd)
+{
+ setsid();
+ if (ioctl(fd, TIOCSCTTY, NULL) == -1) return -1;
+ dup2(fd, 0);
+ dup2(fd, 1);
+ dup2(fd, 2);
+ if (fd > 2) close(fd);
+ return 0;
+}
+
+int openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize *winp)
+{
+ char buf[512];
+ int master, slave;
+
+ master = open("/dev/ptmx", O_RDWR);
+ if (master == -1) return -1;
+ if (grantpt(master) || unlockpt(master) || ptsname_r(master, buf, sizeof buf)) goto fail;
+
+ slave = open(buf, O_RDWR | O_NOCTTY);
+ if (slave == -1) goto fail;
+
+ /* XXX Should we ignore errors here? */
+ if (termp) tcsetattr(slave, TCSAFLUSH, termp);
+ if (winp) ioctl(slave, TIOCSWINSZ, winp);
+
+ *amaster = master;
+ *aslave = slave;
+ if (name != NULL) strcpy(name, buf);
+ return 0;
+
+fail:
+ close(master);
+ return -1;
+}
+
+
+int forkpty(int *amaster, char *name, struct termios *termp, struct winsize *winp)
+{
+ int master, slave, pid;
+ if (openpty(&master, &slave, name, termp, winp) == -1) return -1;
+ switch (pid = fork()) {
+ case -1:
+ return -1;
+ case 0:
+ close(master);
+ if (login_tty (slave)) _exit (1);
+ return 0;
+ default:
+ *amaster = master;
+ close (slave);
+ return pid;
+ }
+}
diff -N -u -r ../neovim-master/src/nvim/os/pty_process.c ./src/nvim/os/pty_process.c
--- ../neovim-master/src/nvim/os/pty_process.c 2015-03-21 08:21:51.000000000 -0400
+++ ./src/nvim/os/pty_process.c 2015-03-23 18:58:27.561165621 -0400
@@ -14,6 +14,8 @@
# include <libutil.h>
#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
# include <util.h>
+#elif defined(__ANDROID__)
+# include "forkpty-android.h"
#else
# include <pty.h>
#endif