This source file includes following definitions.
- rpl_openpty
- openpty
- openpty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <config.h>
18
19
20 #include <pty.h>
21
22 #if HAVE_OPENPTY
23
24
25 # undef openpty
26 int
27 rpl_openpty (int *amaster, int *aslave, char *name,
28 struct termios const *termp, struct winsize const *winp)
29 {
30
31 return openpty (amaster, aslave, name, (struct termios *) termp,
32 (struct winsize *) winp);
33 }
34
35 #elif defined _WIN32 && !defined __CYGWIN__
36
37 # include <errno.h>
38
39 int
40 openpty (_GL_UNUSED int *amaster, _GL_UNUSED int *aslave,
41 _GL_UNUSED char *name,
42 _GL_UNUSED struct termios const *termp,
43 _GL_UNUSED struct winsize const *winp)
44 {
45
46 errno = ENOSYS;
47 return -1;
48 }
49
50 #else
51
52 # include <fcntl.h>
53 # include <stdlib.h>
54 # include <string.h>
55 # include <sys/ioctl.h>
56 # include <termios.h>
57 # include <unistd.h>
58 # if defined __sun || defined __hpux
59 # include <stropts.h>
60 # endif
61
62 int
63 openpty (int *amaster, int *aslave, char *name,
64 struct termios const *termp, struct winsize const *winp)
65 {
66 int master;
67 char *slave_name;
68 int slave;
69
70 # if HAVE__GETPTY
71
72 slave_name = _getpty (&master, O_RDWR, 0622, 0);
73 if (slave_name == NULL)
74 return -1;
75
76 # else
77
78
79 master = posix_openpt (O_RDWR | O_NOCTTY);
80 if (master < 0)
81 return -1;
82
83 # endif
84
85
86
87 if (grantpt (master))
88 goto fail;
89
90
91
92 if (unlockpt (master))
93 goto fail;
94
95 # if !HAVE__GETPTY
96 slave_name = ptsname (master);
97 if (slave_name == NULL)
98 goto fail;
99 # endif
100
101 slave = open (slave_name, O_RDWR | O_NOCTTY);
102 if (slave == -1)
103 goto fail;
104
105 # if defined __sun || defined __hpux
106 if (ioctl (slave, I_PUSH, "ptem") < 0
107 || ioctl (slave, I_PUSH, "ldterm") < 0
108 # if defined __sun
109 || ioctl (slave, I_PUSH, "ttcompat") < 0
110 # endif
111 )
112 {
113 close (slave);
114 goto fail;
115 }
116 # endif
117
118
119 if (termp)
120 tcsetattr (slave, TCSAFLUSH, termp);
121 if (winp)
122 ioctl (slave, TIOCSWINSZ, winp);
123
124 *amaster = master;
125 *aslave = slave;
126 if (name != NULL)
127 strcpy (name, slave_name);
128
129 return 0;
130
131 fail:
132 close (master);
133 return -1;
134 }
135
136 #endif