termux-packages/x11-packages/qemu-common/android-5/0013-implement-openpty.patch
2022-04-18 14:35:52 +05:30

40 lines
1.1 KiB
Diff

diff -uNr qemu-3.1.0/util/qemu-openpty.c qemu-3.1.0.mod/util/qemu-openpty.c
--- qemu-3.1.0/util/qemu-openpty.c 2018-12-11 19:44:35.000000000 +0200
+++ qemu-3.1.0.mod/util/qemu-openpty.c 2019-05-27 15:04:41.083303559 +0300
@@ -108,6 +108,35 @@
}
#endif
+#ifdef __ANDROID__
+#ifdef __ANDROID_API__ < 24
+static int openpty(int* amaster, int* aslave, char* name, const struct termios* termp, const struct winsize* winp)
+{
+ char buf[512];
+
+ int master = open("/dev/ptmx", O_RDWR);
+ if (master == -1) return -1;
+ if (grantpt(master) || unlockpt(master) || ptsname_r(master, buf, sizeof buf)) goto fail;
+
+ int slave = open(buf, O_RDWR | O_NOCTTY);
+ if (slave == -1) goto fail;
+
+ /* XXX Should we ignore errors here? */
+ if (termp) tcsetattr(slave, TCSANOW, termp);
+ if (winp) ioctl(slave, TIOCSWINSZ, winp);
+
+ *amaster = master;
+ *aslave = slave;
+ if (name != NULL) strcpy(name, buf);
+ return 0;
+
+fail:
+ close(master);
+ return -1;
+}
+#endif
+#endif
+
int qemu_openpty_raw(int *aslave, char *pty_name)
{
int amaster;