Mercurial > vim
annotate src/pty.c @ 17506:74b6674b99fd v8.1.1751
patch 8.1.1751: when redrawing popups plines_win() may be called often
commit https://github.com/vim/vim/commit/9d5ffceb3fea247a88d4d3936e97b7f488aab6ff
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jul 26 21:01:29 2019 +0200
patch 8.1.1751: when redrawing popups plines_win() may be called often
Problem: When redrawing popups plines_win() may be called often.
Solution: Pass a cache to mouse_comp_pos().
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 26 Jul 2019 21:15:06 +0200 |
parents | fd57da82dd5d |
children | d1e77015f60b |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 /* | |
10 * The stuff in this file mostly comes from the "screen" program. | |
11 * Included with permission from Juergen Weigert. | |
12 * Copied from "pty.c". "putenv.c" was used for putenv() in misc2.c. | |
13 * | |
14 * It has been modified to work better with Vim. | |
15 * The parts that are not used in Vim have been deleted. | |
16 * See the "screen" sources for the complete stuff. | |
3282 | 17 * |
18 * This specific version is distibuted under the Vim license (attribution by | |
19 * Juergen Weigert), the GPL applies to the original version, see the | |
20 * copyright notice below. | |
7 | 21 */ |
22 | |
23 /* Copyright (c) 1993 | |
24 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de) | |
25 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de) | |
26 * Copyright (c) 1987 Oliver Laumann | |
27 * | |
28 * This program is free software; you can redistribute it and/or modify | |
29 * it under the terms of the GNU General Public License as published by | |
30 * the Free Software Foundation; either version 2, or (at your option) | |
31 * any later version. | |
32 * | |
33 * This program is distributed in the hope that it will be useful, | |
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
36 * GNU General Public License for more details. | |
37 * | |
38 * You should have received a copy of the GNU General Public License | |
39 * along with this program (see the file COPYING); if not, write to the | |
40 * Free Software Foundation, Inc., | |
41 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | |
42 */ | |
43 | |
44 #include "vim.h" | |
45 | |
11737
7791a15353dc
patch 8.0.0751: OpenPTY missing with some combination of features
Christian Brabandt <cb@256bit.org>
parents:
11735
diff
changeset
|
46 #if defined(FEAT_GUI) || defined(FEAT_JOB_CHANNEL) |
11735
21354977aa7b
patch 8.0.0750: OpenPTY missing in non-GUI build
Christian Brabandt <cb@256bit.org>
parents:
10460
diff
changeset
|
47 |
7 | 48 #include <signal.h> |
49 | |
50 #ifdef __CYGWIN32__ | |
51 # include <sys/termios.h> | |
52 #endif | |
53 | |
1030 | 54 #ifdef HAVE_SYS_IOCTL_H |
7 | 55 # include <sys/ioctl.h> |
56 #endif | |
57 | |
58 #if HAVE_STROPTS_H | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
59 # include <sys/types.h> |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
60 # ifdef sinix |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
61 # define buf_T __system_buf_t__ |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
62 # endif |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
63 # include <stropts.h> |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
64 # ifdef sinix |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
65 # undef buf_T |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
66 # endif |
10460
7fd589f46801
commit https://github.com/vim/vim/commit/a899e6ecc4523c7e411eaf6fbaa4197d70f6f39e
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
67 # ifdef SUN_SYSTEM |
7 | 68 # include <sys/conf.h> |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
69 # if defined(HAVE_SYS_PTMS_H) && defined(HAVE_SVR4_PTYS) |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
70 # include <sys/ptms.h> |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
71 # endif |
7 | 72 # endif |
73 #endif | |
74 | |
1030 | 75 #ifdef HAVE_UNISTD_H |
7 | 76 # include <unistd.h> |
77 #endif | |
78 | |
79 #if HAVE_TERMIO_H | |
80 # include <termio.h> | |
81 #else | |
1030 | 82 # ifdef HAVE_TERMIOS_H |
7 | 83 # include <termios.h> |
84 # endif | |
85 #endif | |
86 | |
87 #if HAVE_SYS_STREAM_H | |
88 # include <sys/stream.h> | |
89 #endif | |
90 | |
91 #if HAVE_SYS_PTEM_H | |
92 # include <sys/ptem.h> | |
93 #endif | |
94 | |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12576
diff
changeset
|
95 #if !defined(SUN_SYSTEM) && !defined(VMS) |
7 | 96 # include <sys/ioctl.h> |
97 #endif | |
98 | |
10460
7fd589f46801
commit https://github.com/vim/vim/commit/a899e6ecc4523c7e411eaf6fbaa4197d70f6f39e
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
99 #if defined(SUN_SYSTEM) && defined(LOCKPTY) && !defined(TIOCEXCL) |
7 | 100 # include <sys/ttold.h> |
101 #endif | |
102 | |
103 #ifdef ISC | |
104 # include <sys/tty.h> | |
105 # include <sys/sioctl.h> | |
106 # include <sys/pty.h> | |
107 #endif | |
108 | |
109 #ifdef sgi | |
110 # include <sys/sysmacros.h> | |
111 #endif | |
112 | |
113 #if defined(_INCLUDE_HPUX_SOURCE) && !defined(hpux) | |
114 # define hpux | |
115 #endif | |
116 | |
117 /* | |
118 * if no PTYRANGE[01] is in the config file, we pick a default | |
119 */ | |
120 #ifndef PTYRANGE0 | |
121 # define PTYRANGE0 "qprs" | |
122 #endif | |
123 #ifndef PTYRANGE1 | |
124 # define PTYRANGE1 "0123456789abcdef" | |
125 #endif | |
126 | |
127 /* SVR4 pseudo ttys don't seem to work with SCO-5 */ | |
128 #ifdef M_UNIX | |
129 # undef HAVE_SVR4_PTYS | |
130 #endif | |
131 | |
132 /* | |
2834 | 133 * Open all ptys with O_NOCTTY, just to be on the safe side. |
7 | 134 */ |
135 #ifndef O_NOCTTY | |
136 # define O_NOCTTY 0 | |
137 #endif | |
138 | |
16441
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
139 #if defined(HAVE_SVR4_PTYS) || defined(HAVE_POSIX_OPENPT) |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
140 // These should be in stdlib.h, but it depends on _XOPEN_SOURCE. |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
141 char *ptsname(int); |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
142 int unlockpt(int); |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
143 int grantpt(int); |
16449
fd57da82dd5d
patch 8.1.1229: warning for posix_openpt() not declared
Bram Moolenaar <Bram@vim.org>
parents:
16441
diff
changeset
|
144 int posix_openpt(int flags); |
16441
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
145 #endif |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
146 |
7 | 147 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
148 initmaster(int f UNUSED) |
7 | 149 { |
150 #ifndef VMS | |
151 # ifdef POSIX | |
152 tcflush(f, TCIOFLUSH); | |
153 # else | |
154 # ifdef TIOCFLUSH | |
155 (void)ioctl(f, TIOCFLUSH, (char *) 0); | |
156 # endif | |
157 # endif | |
158 # ifdef LOCKPTY | |
159 (void)ioctl(f, TIOCEXCL, (char *) 0); | |
160 # endif | |
161 #endif | |
162 } | |
163 | |
164 /* | |
165 * This causes a hang on some systems, but is required for a properly working | |
166 * pty on others. Needs to be tuned... | |
167 */ | |
168 int | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
169 setup_slavepty(int fd) |
7 | 170 { |
171 if (fd < 0) | |
172 return 0; | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
173 #if defined(I_PUSH) && defined(HAVE_SVR4_PTYS) && !defined(sgi) \ |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
174 && !defined(linux) && !defined(__osf__) && !defined(M_UNIX) |
7 | 175 # if defined(HAVE_SYS_PTEM_H) || defined(hpux) |
176 if (ioctl(fd, I_PUSH, "ptem") != 0) | |
177 return -1; | |
178 # endif | |
179 if (ioctl(fd, I_PUSH, "ldterm") != 0) | |
180 return -1; | |
10460
7fd589f46801
commit https://github.com/vim/vim/commit/a899e6ecc4523c7e411eaf6fbaa4197d70f6f39e
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
181 # ifdef SUN_SYSTEM |
7 | 182 if (ioctl(fd, I_PUSH, "ttcompat") != 0) |
183 return -1; | |
184 # endif | |
185 #endif | |
186 return 0; | |
187 } | |
188 | |
16441
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
189 #if defined(HAVE_POSIX_OPENPT) && !defined(PTY_DONE) |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
190 #define PTY_DONE |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
191 int |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
192 mch_openpty(char **ttyn) |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
193 { |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
194 int f; |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
195 char *m; |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
196 RETSIGTYPE (*sigcld) SIGPROTOARG; |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
197 static char TtyName[32]; // used for opening a new pty-pair |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
198 |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
199 if ((f = posix_openpt(O_RDWR | O_NOCTTY | O_EXTRA)) == -1) |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
200 return -1; |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
201 |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
202 // SIGCHLD set to SIG_DFL for grantpt() because it fork()s and |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
203 // exec()s pt_chmod |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
204 sigcld = signal(SIGCHLD, SIG_DFL); |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
205 if ((m = ptsname(f)) == NULL || grantpt(f) || unlockpt(f)) |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
206 { |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
207 signal(SIGCHLD, sigcld); |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
208 close(f); |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
209 return -1; |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
210 } |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
211 signal(SIGCHLD, sigcld); |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
212 vim_strncpy((char_u *)TtyName, (char_u *)m, sizeof(TtyName) - 1); |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
213 initmaster(f); |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
214 *ttyn = TtyName; |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
215 return f; |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
216 } |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
217 #endif |
7 | 218 |
219 #if defined(OSX) && !defined(PTY_DONE) | |
220 #define PTY_DONE | |
221 int | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
222 mch_openpty(char **ttyn) |
7 | 223 { |
224 int f; | |
225 static char TtyName[32]; | |
226 | |
227 if ((f = open_controlling_pty(TtyName)) < 0) | |
228 return -1; | |
229 initmaster(f); | |
230 *ttyn = TtyName; | |
231 return f; | |
232 } | |
233 #endif | |
234 | |
235 #if (defined(sequent) || defined(_SEQUENT_)) && defined(HAVE_GETPSEUDOTTY) \ | |
236 && !defined(PTY_DONE) | |
237 #define PTY_DONE | |
238 int | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
239 mch_openpty(char **ttyn) |
7 | 240 { |
241 char *m, *s; | |
242 int f; | |
243 /* used for opening a new pty-pair: */ | |
244 static char PtyName[32]; | |
245 static char TtyName[32]; | |
246 | |
247 if ((f = getpseudotty(&s, &m)) < 0) | |
248 return -1; | |
249 #ifdef _SEQUENT_ | |
250 fvhangup(s); | |
251 #endif | |
2760 | 252 vim_strncpy((char_u *)PtyName, (char_u *)m, sizeof(PtyName) - 1); |
253 vim_strncpy((char_u *)TtyName, (char_u *)s, sizeof(TtyName) - 1); | |
7 | 254 initmaster(f); |
255 *ttyn = TtyName; | |
256 return f; | |
257 } | |
258 #endif | |
259 | |
260 #if defined(__sgi) && !defined(PTY_DONE) | |
261 #define PTY_DONE | |
262 int | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
263 mch_openpty(char **ttyn) |
7 | 264 { |
265 int f; | |
266 char *name; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
267 RETSIGTYPE (*sigcld) SIGPROTOARG; |
7 | 268 |
269 /* | |
270 * SIGCHLD set to SIG_DFL for _getpty() because it may fork() and | |
271 * exec() /usr/adm/mkpts | |
272 */ | |
273 sigcld = signal(SIGCHLD, SIG_DFL); | |
274 name = _getpty(&f, O_RDWR | O_NONBLOCK | O_EXTRA, 0600, 0); | |
275 signal(SIGCHLD, sigcld); | |
276 | |
277 if (name == 0) | |
278 return -1; | |
279 initmaster(f); | |
280 *ttyn = name; | |
281 return f; | |
282 } | |
283 #endif | |
284 | |
285 #if defined(MIPS) && defined(HAVE_DEV_PTC) && !defined(PTY_DONE) | |
286 #define PTY_DONE | |
287 int | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
288 mch_openpty(char **ttyn) |
7 | 289 { |
290 int f; | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
291 stat_T buf; |
7 | 292 /* used for opening a new pty-pair: */ |
293 static char TtyName[32]; | |
294 | |
295 if ((f = open("/dev/ptc", O_RDWR | O_NOCTTY | O_NONBLOCK | O_EXTRA, 0)) < 0) | |
296 return -1; | |
297 if (mch_fstat(f, &buf) < 0) | |
298 { | |
299 close(f); | |
300 return -1; | |
301 } | |
302 sprintf(TtyName, "/dev/ttyq%d", minor(buf.st_rdev)); | |
303 initmaster(f); | |
304 *ttyn = TtyName; | |
305 return f; | |
306 } | |
307 #endif | |
308 | |
12576
b74f5036a434
patch 8.0.1166: :terminal doesn't work on Mac High Sierra
Christian Brabandt <cb@256bit.org>
parents:
11737
diff
changeset
|
309 #if defined(HAVE_SVR4_PTYS) && !defined(PTY_DONE) && !defined(hpux) \ |
13353
8412df1479a3
patch 8.0.1550: various small problems in source files
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
310 && !(defined(MACOS_X) && !defined(MAC_OS_X_VERSION_10_6)) |
7 | 311 |
1703 | 312 /* NOTE: Even though HPUX can have /dev/ptmx, the code below doesn't work! |
12576
b74f5036a434
patch 8.0.1166: :terminal doesn't work on Mac High Sierra
Christian Brabandt <cb@256bit.org>
parents:
11737
diff
changeset
|
313 * Same for Mac OS X Leopard (10.5). */ |
7 | 314 #define PTY_DONE |
315 int | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
316 mch_openpty(char **ttyn) |
7 | 317 { |
318 int f; | |
2397
d5976fe4349d
Fix for compiler warning about function prototype in pty.c.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
319 char *m; |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
3282
diff
changeset
|
320 RETSIGTYPE (*sigcld) SIGPROTOARG; |
7 | 321 /* used for opening a new pty-pair: */ |
322 static char TtyName[32]; | |
323 | |
324 if ((f = open("/dev/ptmx", O_RDWR | O_NOCTTY | O_EXTRA, 0)) == -1) | |
325 return -1; | |
326 | |
327 /* | |
328 * SIGCHLD set to SIG_DFL for grantpt() because it fork()s and | |
329 * exec()s pt_chmod | |
330 */ | |
331 sigcld = signal(SIGCHLD, SIG_DFL); | |
332 if ((m = ptsname(f)) == NULL || grantpt(f) || unlockpt(f)) | |
333 { | |
334 signal(SIGCHLD, sigcld); | |
335 close(f); | |
336 return -1; | |
337 } | |
338 signal(SIGCHLD, sigcld); | |
2760 | 339 vim_strncpy((char_u *)TtyName, (char_u *)m, sizeof(TtyName) - 1); |
7 | 340 initmaster(f); |
341 *ttyn = TtyName; | |
342 return f; | |
343 } | |
344 #endif | |
345 | |
346 #if defined(_AIX) && defined(HAVE_DEV_PTC) && !defined(PTY_DONE) | |
347 #define PTY_DONE | |
348 | |
349 #ifdef _IBMR2 | |
350 int aixhack = -1; | |
351 #endif | |
352 | |
353 int | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
354 mch_openpty(char **ttyn) |
7 | 355 { |
356 int f; | |
357 /* used for opening a new pty-pair: */ | |
358 static char TtyName[32]; | |
359 | |
360 /* a dumb looking loop replaced by mycrofts code: */ | |
361 if ((f = open("/dev/ptc", O_RDWR | O_NOCTTY | O_EXTRA)) < 0) | |
362 return -1; | |
2760 | 363 vim_strncpy((char_u *)TtyName, (char_u *)ttyname(f), sizeof(TtyName) - 1); |
1076 | 364 if (geteuid() != ROOT_UID && mch_access(TtyName, R_OK | W_OK)) |
7 | 365 { |
366 close(f); | |
367 return -1; | |
368 } | |
369 initmaster(f); | |
370 # ifdef _IBMR2 | |
371 if (aixhack >= 0) | |
372 close(aixhack); | |
373 if ((aixhack = open(TtyName, O_RDWR | O_NOCTTY | O_EXTRA, 0)) < 0) | |
374 { | |
375 close(f); | |
376 return -1; | |
377 } | |
378 # endif | |
379 *ttyn = TtyName; | |
380 return f; | |
381 } | |
382 #endif | |
383 | |
384 #ifndef PTY_DONE | |
385 | |
386 # ifdef hpux | |
387 static char PtyProto[] = "/dev/ptym/ptyXY"; | |
388 static char TtyProto[] = "/dev/pty/ttyXY"; | |
389 # else | |
390 # ifdef __BEOS__ | |
391 static char PtyProto[] = "/dev/pt/XY"; | |
392 static char TtyProto[] = "/dev/tt/XY"; | |
393 # else | |
394 static char PtyProto[] = "/dev/ptyXY"; | |
395 static char TtyProto[] = "/dev/ttyXY"; | |
396 # endif | |
397 # endif | |
398 | |
399 int | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
400 mch_openpty(char **ttyn) |
7 | 401 { |
402 char *p, *q, *l, *d; | |
403 int f; | |
404 /* used for opening a new pty-pair: */ | |
405 static char PtyName[32]; | |
406 static char TtyName[32]; | |
407 | |
408 strcpy(PtyName, PtyProto); | |
409 strcpy(TtyName, TtyProto); | |
410 for (p = PtyName; *p != 'X'; p++) | |
411 ; | |
412 for (q = TtyName; *q != 'X'; q++) | |
413 ; | |
414 for (l = PTYRANGE0; (*p = *l) != '\0'; l++) | |
415 { | |
416 for (d = PTYRANGE1; (p[1] = *d) != '\0'; d++) | |
417 { | |
418 if ((f = open(PtyName, O_RDWR | O_NOCTTY | O_EXTRA, 0)) == -1) | |
419 continue; | |
420 q[0] = *l; | |
421 q[1] = *d; | |
1076 | 422 if (geteuid() != ROOT_UID && mch_access(TtyName, R_OK | W_OK)) |
7 | 423 { |
424 close(f); | |
425 continue; | |
426 } | |
10460
7fd589f46801
commit https://github.com/vim/vim/commit/a899e6ecc4523c7e411eaf6fbaa4197d70f6f39e
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
427 #if defined(SUN_SYSTEM) && defined(TIOCGPGRP) && !defined(SUNOS3) |
7 | 428 /* Hack to ensure that the slave side of the pty is |
429 * unused. May not work in anything other than SunOS4.1 | |
430 */ | |
431 { | |
432 int pgrp; | |
433 | |
434 /* tcgetpgrp does not work (uses TIOCGETPGRP)! */ | |
435 if (ioctl(f, TIOCGPGRP, (char *)&pgrp) != -1 || errno != EIO) | |
436 { | |
437 close(f); | |
438 continue; | |
439 } | |
440 } | |
441 #endif | |
442 initmaster(f); | |
443 *ttyn = TtyName; | |
444 return f; | |
445 } | |
446 } | |
447 return -1; | |
448 } | |
449 #endif | |
11735
21354977aa7b
patch 8.0.0750: OpenPTY missing in non-GUI build
Christian Brabandt <cb@256bit.org>
parents:
10460
diff
changeset
|
450 |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
451 /* |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
452 * Call isatty(fd), except for SunOS where it's done differently. |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
453 */ |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
454 int |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
455 mch_isatty(int fd) |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
456 { |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
457 # if defined(I_STR) && defined(HAVE_SYS_PTMS_H) && defined(HAVE_SVR4_PTYS) \ |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
458 && defined(SUN_SYSTEM) |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
459 // On SunOS, isatty() for /dev/ptmx returns false or sometimes can hang up |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
460 // in the inner ioctl(), and therefore first determine whether "fd" is a |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
461 // master device. |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
462 struct strioctl istr; |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
463 |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
464 istr.ic_cmd = ISPTM; |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
465 istr.ic_timout = 0; |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
466 istr.ic_dp = NULL; |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
467 istr.ic_len = 0; |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
468 |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
469 if (ioctl(fd, I_STR, &istr) == 0) |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
470 // Trick: return 2 in order to advice the caller that "fd" is a master |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
471 // device. cf. src/os_unix.c:get_tty_fd() |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
472 return 2; |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
473 # endif |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
474 return isatty(fd); |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
475 } |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
476 |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
477 #endif /* FEAT_GUI || FEAT_JOB_CHANNEL */ |