annotate lib/openpty.c @ 15972:167933697036

openpty: Update comments. * lib/openpty.c: Add comments about Minix.
author Bruno Haible <bruno@clisp.org>
date Thu, 20 Oct 2011 11:44:11 +0200
parents 97fc9a21a8fb
children ca99be30d00b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13032
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
1 /* Open a pseudo-terminal.
14079
97fc9a21a8fb maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents: 13042
diff changeset
2 Copyright (C) 2010-2011 Free Software Foundation, Inc.
13006
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
3
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
7 (at your option) any later version.
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
8
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
12 GNU General Public License for more details.
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
13
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
16
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
17 #include <config.h>
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
18
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
19 /* Specification. */
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
20 #include <pty.h>
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
21
13032
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
22 #if HAVE_OPENPTY
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
23
13042
80d3dab738c0 Fix comments.
Bruno Haible <bruno@clisp.org>
parents: 13032
diff changeset
24 /* Provide a wrapper with the prototype of glibc-2.8 and newer. */
13006
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
25 # undef openpty
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
26 int
13032
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
27 rpl_openpty (int *amaster, int *aslave, char *name,
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
28 struct termios const *termp, struct winsize const *winp)
13006
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
29 {
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
30 /* Cast away const, for implementations with weaker prototypes. */
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
31 return openpty (amaster, aslave, name, (struct termios *) termp,
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
32 (struct winsize *) winp);
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
33 }
13032
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
34
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
35 #else /* AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, mingw */
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
36
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
37 # include <fcntl.h>
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
38 # include <string.h>
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
39 # include <sys/ioctl.h>
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
40 # include <termios.h>
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
41 # include <unistd.h>
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
42 # if defined __sun || defined __hpux /* Solaris, HP-UX */
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
43 # include <stropts.h>
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
44 # endif
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
45
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
46 int
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
47 openpty (int *amaster, int *aslave, char *name,
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
48 struct termios const *termp, struct winsize const *winp)
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
49 {
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
50 int master;
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
51 char *slave_name;
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
52 int slave;
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
53
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
54 # if HAVE__GETPTY /* IRIX */
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
55
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
56 slave_name = _getpty (&master, O_RDWR, 0622, 0);
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
57 if (slave_name == NULL)
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
58 return -1;
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
59
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
60 # else /* AIX 5.1, HP-UX 11, Solaris 10, mingw */
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
61
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
62 # if HAVE_POSIX_OPENPT /* Solaris 10 */
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
63
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
64 master = posix_openpt (O_RDWR | O_NOCTTY);
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
65 if (master < 0)
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
66 return -1;
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
67
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
68 # else /* AIX 5.1, HP-UX 11, Solaris 9, mingw */
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
69
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
70 # ifdef _AIX /* AIX */
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
71
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
72 master = open ("/dev/ptc", O_RDWR | O_NOCTTY);
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
73 if (master < 0)
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
74 return -1;
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
75
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
76 # else /* HP-UX 11, Solaris 9, mingw */
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
77
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
78 /* HP-UX, Solaris have /dev/ptmx.
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
79 HP-UX also has /dev/ptym/clone, but this should not be needed.
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
80 Linux also has /dev/ptmx, but Linux already has openpty().
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
81 MacOS X also has /dev/ptmx, but MacOS X already has openpty().
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
82 OSF/1 also has /dev/ptmx and /dev/ptmx_bsd, but OSF/1 already has
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
83 openpty(). */
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
84 master = open ("/dev/ptmx", O_RDWR | O_NOCTTY);
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
85 if (master < 0)
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
86 return -1;
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
87
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
88 # endif
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
89
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
90 # endif
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
91
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
92 /* If all this does not work, we could try to open, one by one:
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
93 - On MacOS X: /dev/pty[p-w][0-9a-f]
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
94 - On *BSD: /dev/pty[p-sP-S][0-9a-v]
15972
167933697036 openpty: Update comments.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
95 - On Minix: /dev/pty[p-q][0-9a-f]
13032
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
96 - On AIX: /dev/ptyp[0-9a-f]
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
97 - On HP-UX: /dev/pty[p-r][0-9a-f]
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
98 - On OSF/1: /dev/pty[p-q][0-9a-f]
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
99 - On Solaris: /dev/pty[p-r][0-9a-f]
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
100 */
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
101 # endif
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
102
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
103 /* This call does not require a dependency to the 'grantpt' module,
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
104 because AIX, HP-UX, IRIX, Solaris all have the grantpt() function. */
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
105 if (grantpt (master))
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
106 goto fail;
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
107
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
108 /* This call does not require a dependency to the 'unlockpt' module,
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
109 because AIX, HP-UX, IRIX, Solaris all have the unlockpt() function. */
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
110 if (unlockpt (master))
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
111 goto fail;
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
112
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
113 # if !HAVE__GETPTY /* !IRIX */
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
114 slave_name = ptsname (master);
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
115 if (slave_name == NULL)
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
116 goto fail;
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
117 # endif
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
118
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
119 slave = open (slave_name, O_RDWR | O_NOCTTY);
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
120 if (slave == -1)
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
121 goto fail;
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
122
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
123 # if defined __sun || defined __hpux /* Solaris, HP-UX */
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
124 if (ioctl (slave, I_PUSH, "ptem") < 0
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
125 || ioctl (slave, I_PUSH, "ldterm") < 0
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
126 # if defined __sun
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
127 || ioctl (slave, I_PUSH, "ttcompat") < 0
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
128 # endif
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
129 )
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
130 {
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
131 close (slave);
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
132 goto fail;
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
133 }
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
134 # endif
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
135
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
136 /* XXX Should we ignore errors here? */
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
137 if (termp)
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
138 tcsetattr (slave, TCSAFLUSH, termp);
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
139 if (winp)
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
140 ioctl (slave, TIOCSWINSZ, winp);
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
141
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
142 *amaster = master;
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
143 *aslave = slave;
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
144 if (name != NULL)
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
145 strcpy (name, slave_name);
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
146
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
147 return 0;
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
148
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
149 fail:
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
150 close (master);
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
151 return -1;
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
152 }
64faceabf217 openpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents: 13006
diff changeset
153
13006
b89998923de3 forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff changeset
154 #endif