openexr: make architecture independent
[oi-userland.git] / components / library / vte-291 / patches / 04-pty-packet-mode.patch
blobfd32dd203e6d30035c02a2f2a8def0a15c5240a2
1 Provide PTY packet mode support for vte in OI.
3 Backported from upstream.
5 See https://gitlab.gnome.org/GNOME/vte/-/commit/8586e4292e76943a100a8039f5ce9e33e5984bb3
8 --- vte-0.54.5/configure.ac.~1~ 2019-10-11 11:54:58.000000000 +0000
9 +++ vte-0.54.5/configure.ac 2020-12-03 11:47:45.207001347 +0000
10 @@ -278,7 +276,7 @@
11 AC_DEFINE_UNQUOTED(VTE_DEFAULT_TERM,"$VTE_DEFAULT_TERM",[The default value $TERM is set to.])
13 # Check for headers.
14 -AC_CHECK_HEADERS([sys/select.h sys/syslimits.h sys/termios.h sys/wait.h stropts.h termios.h util.h wchar.h pty.h])
15 +AC_CHECK_HEADERS([sys/select.h sys/stream.h sys/syslimits.h sys/termios.h sys/wait.h stropts.h termios.h util.h wchar.h pty.h])
16 AC_HEADER_TIOCGWINSZ
18 # Check for how to open a new PTY. We support posix_openpt and BSDs openpty
19 --- vte-0.54.5/src/pty.cc.~1~ 2019-10-11 20:09:36.000000000 +0000
20 +++ vte-0.54.5/src/pty.cc 2020-12-03 17:50:14.681738503 +0000
21 @@ -582,10 +582,18 @@
22 static int
23 fd_set_cpkt(int fd)
25 + auto ret = 0;
26 +#if defined(TIOCPKT)
27 /* tty_ioctl(4) -> every read() gives an extra byte at the beginning
28 * notifying us of stop/start (^S/^Q) events. */
29 int one = 1;
30 - return ioctl(fd, TIOCPKT, &one);
31 + ret = ioctl(fd, TIOCPKT, &one);
32 +#elif defined(__sun) && defined(HAVE_STROPTS_H)
33 + if (isastream(fd) == 1 &&
34 + ioctl(fd, I_FIND, "pckt") == 0)
35 + ret = ioctl(fd, I_PUSH, "pckt");
36 +#endif
37 + return ret;
40 static int
41 @@ -608,7 +616,7 @@
42 if (fd_set_cpkt(fd) < 0) {
43 vte::util::restore_errno errsv;
44 _vte_debug_print(VTE_DEBUG_PTY,
45 - "%s failed: %s", "ioctl(TIOCPKT)", g_strerror(errsv));
46 + "%s failed: %s", "Setting packet mode", g_strerror(errsv));
47 return -1;
50 @@ -671,7 +679,7 @@
51 if (fd_set_cpkt(fd) < 0) {
52 vte::util::restore_errno errsv;
53 _vte_debug_print(VTE_DEBUG_PTY,
54 - "%s failed: %s", "ioctl(TIOCPKT)", g_strerror(errsv));
55 + "%s failed: %s", "Setting packet mode", g_strerror(errsv));
56 return -1;
59 --- vte-0.54.5/src/vte.cc.~1~ 2019-10-11 20:09:36.000000000 +0000
60 +++ vte-0.54.5/src/vte.cc 2020-12-03 17:50:14.686156151 +0000
61 @@ -31,6 +31,12 @@
62 #ifdef HAVE_SYS_TERMIOS_H
63 #include <sys/termios.h>
64 #endif
65 +#ifdef HAVE_STROPTS_H
66 +#include <stropts.h>
67 +#endif
68 +#ifdef HAVE_SYS_STREAM_H
69 +#include <sys/stream.h>
70 +#endif
72 #include <glib.h>
73 #include <glib/gi18n-lib.h>
74 @@ -3900,6 +3906,7 @@
75 bp = chunk->data + chunk->len;
76 len = 0;
77 do {
78 +#if defined(TIOCPKT)
79 /* We'd like to read (fd, bp, rem); but due to TIOCPKT mode
80 * there's an extra input byte returned at the beginning.
81 * We need to see what that byte is, but otherwise drop it
82 @@ -3944,6 +3951,66 @@
83 len += ret;
84 break;
86 +#elif defined(__sun) && defined(HAVE_STROPTS_H)
87 + static unsigned char ctl_s[128];
88 + struct strbuf ctlbuf, databuf;
89 + int ret, flags = 0;
90 + bool have_data = false;
92 + ctlbuf.buf = (caddr_t)ctl_s;
93 + ctlbuf.maxlen = sizeof(ctl_s);
94 + databuf.buf = (caddr_t)bp;
95 + databuf.maxlen = rem;
97 + ret = getmsg(fd, &ctlbuf, &databuf, &flags);
98 + if (ret == -1) {
99 + err = errno;
100 + goto out;
101 + } else if (ctlbuf.len == 1) {
102 + switch (ctl_s[0]) {
103 + case M_IOCTL:
104 + pty_termios_changed();
105 + break;
106 + case M_STOP:
107 + pty_scroll_lock_changed(true);
108 + break;
109 + case M_START:
110 + pty_scroll_lock_changed(false);
111 + break;
112 + case M_DATA:
113 + have_data = true;
114 + break;
116 + } else if (ctlbuf.len == -1 && databuf.len != -1) {
117 + // MOREDATA
118 + have_data = true;
121 + if (have_data) {
122 + if (databuf.len == 0) {
123 + eof = true;
124 + goto out;
126 + bp += databuf.len;
127 + rem -= databuf.len;
128 + len += databuf.len;
130 +#else /* no TIOCPKT && no STREAMS pty */
131 + int ret = read(fd, bp, rem);
132 + switch (ret) {
133 + case -1:
134 + err = errno;
135 + goto out;
136 + case 0:
137 + eof = true;
138 + goto out;
139 + default:
140 + bp += ret;
141 + rem -= ret;
142 + len += ret;
143 + break;
145 +#endif
146 } while (rem);
147 out:
148 chunk->len += len;