annotate src/pty.c @ 20814:f23c6543a54d v8.2.0959

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