chiark / gitweb /
Initial push
[termux-packages] / packages / neovim / forkpty-android.patch
1 diff -N -u -r ../neovim-master/src/nvim/os/forkpty-android.h ./src/nvim/os/forkpty-android.h
2 --- ../neovim-master/src/nvim/os/forkpty-android.h      1969-12-31 19:00:00.000000000 -0500
3 +++ ./src/nvim/os/forkpty-android.h     2015-03-23 18:59:01.425165645 -0400
4 @@ -0,0 +1,63 @@
5 +#include <fcntl.h>
6 +#include <sys/ioctl.h>
7 +#include <sys/param.h>
8 +#include <sys/types.h>
9 +#include <stdlib.h>
10 +#include <termios.h>
11 +#include <unistd.h>
12 +
13 +int login_tty(int fd)
14 +{
15 +       setsid();
16 +       if (ioctl(fd, TIOCSCTTY, NULL) == -1) return -1;
17 +       dup2(fd, 0);
18 +       dup2(fd, 1);
19 +       dup2(fd, 2);
20 +       if (fd > 2) close(fd);
21 +       return 0;
22 +}
23 +
24 +int openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize *winp)
25 +{
26 +       char buf[512];
27 +       int master, slave;
28 +
29 +       master = open("/dev/ptmx", O_RDWR);
30 +       if (master == -1) return -1;
31 +       if (grantpt(master) || unlockpt(master) || ptsname_r(master, buf, sizeof buf)) goto fail;
32 +
33 +       slave = open(buf, O_RDWR | O_NOCTTY);
34 +       if (slave == -1) goto fail;
35 +
36 +       /* XXX Should we ignore errors here?  */
37 +       if (termp) tcsetattr(slave, TCSAFLUSH, termp);
38 +       if (winp) ioctl(slave, TIOCSWINSZ, winp);
39 +
40 +       *amaster = master;
41 +       *aslave = slave;
42 +       if (name != NULL) strcpy(name, buf);
43 +       return 0;
44 +
45 +fail:
46 +       close(master);
47 +       return -1;
48 +}
49 +
50 +
51 +int forkpty(int *amaster, char *name, struct termios *termp, struct winsize *winp)
52 +{
53 +       int master, slave, pid;
54 +       if (openpty(&master, &slave, name, termp, winp) == -1) return -1;
55 +       switch (pid = fork()) {
56 +               case -1:
57 +                       return -1;
58 +               case 0:
59 +                       close(master);
60 +                       if (login_tty (slave)) _exit (1);
61 +                       return 0;
62 +               default:
63 +                       *amaster = master;
64 +                       close (slave);
65 +                       return pid;
66 +       }
67 +}
68 diff -N -u -r ../neovim-master/src/nvim/os/pty_process.c ./src/nvim/os/pty_process.c
69 --- ../neovim-master/src/nvim/os/pty_process.c  2015-03-21 08:21:51.000000000 -0400
70 +++ ./src/nvim/os/pty_process.c 2015-03-23 18:58:27.561165621 -0400
71 @@ -14,6 +14,8 @@
72  # include <libutil.h>
73  #elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
74  # include <util.h>
75 +#elif defined(__ANDROID__)
76 +# include "forkpty-android.h"
77  #else
78  # include <pty.h>
79  #endif