diff options
author | Matthias-Christian Ott <ott@enolink.de> | 2008-06-10 17:30:15 +0200 |
---|---|---|
committer | Matthias-Christian Ott <ott@enolink.de> | 2008-06-10 17:30:15 +0200 |
commit | 47d8633f157156ef4701ce71ed7eff766206c107 (patch) | |
tree | 78190354f0b6784063f5434821b40bbe0ebd8d1e | |
parent | 0dedee5de8e35f4bab3d707d63be31943715264e (diff) | |
download | st-47d8633f157156ef4701ce71ed7eff766206c107.tar.gz st-47d8633f157156ef4701ce71ed7eff766206c107.zip |
source getpty() out to pty.c
-rw-r--r-- | pty.c | 41 | ||||
-rw-r--r-- | std.c | 35 |
2 files changed, 41 insertions, 35 deletions
@@ -0,0 +1,41 @@ | |||
1 | #include <sys/types.h> | ||
2 | #include <sys/stat.h> | ||
3 | #include <fcntl.h> | ||
4 | #include <stdlib.h> | ||
5 | #if !(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) | ||
6 | #include <pty.h> | ||
7 | #endif | ||
8 | |||
9 | extern int ptm, pts; | ||
10 | |||
11 | void | ||
12 | getpty(void) { | ||
13 | char *ptsdev; | ||
14 | |||
15 | #if defined(_GNU_SOURCE) | ||
16 | ptm = getpt(); | ||
17 | #elif _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 | ||
18 | ptm = posix_openpt(O_RDWR); | ||
19 | #else | ||
20 | ptm = open("/dev/ptmx", O_RDWR); | ||
21 | if(ptm == -1) | ||
22 | if(openpty(&ptm, &pts, NULL, NULL, NULL) == -1) | ||
23 | eprintn("error, cannot open pty"); | ||
24 | #endif | ||
25 | #if defined(_XOPEN_SOURCE) | ||
26 | if(ptm != -1) { | ||
27 | if(grantpt(ptm) == -1) | ||
28 | eprintn("error, cannot grant access to pty"); | ||
29 | if(unlockpt(ptm) == -1) | ||
30 | eprintn("error, cannot unlock pty"); | ||
31 | ptsdev = ptsname(ptm); | ||
32 | if(!ptsdev) | ||
33 | eprintn("error, slave pty name undefined"); | ||
34 | pts = open(ptsdev, O_RDWR); | ||
35 | if(pts == -1) | ||
36 | eprintn("error, cannot open slave pty"); | ||
37 | } | ||
38 | else | ||
39 | eprintn("error, cannot open pty"); | ||
40 | #endif | ||
41 | } | ||
@@ -6,9 +6,6 @@ | |||
6 | #include <ctype.h> | 6 | #include <ctype.h> |
7 | #include <errno.h> | 7 | #include <errno.h> |
8 | #include <fcntl.h> | 8 | #include <fcntl.h> |
9 | #if !(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) | ||
10 | #include <pty.h> | ||
11 | #endif | ||
12 | #include <signal.h> | 9 | #include <signal.h> |
13 | #include <stdarg.h> | 10 | #include <stdarg.h> |
14 | #include <stdio.h> | 11 | #include <stdio.h> |
@@ -101,38 +98,6 @@ eprintn(const char *errstr, ...) { | |||
101 | } | 98 | } |
102 | 99 | ||
103 | void | 100 | void |
104 | getpty(void) { | ||
105 | char *ptsdev; | ||
106 | |||
107 | #if defined(_GNU_SOURCE) | ||
108 | ptm = getpt(); | ||
109 | #elif _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 | ||
110 | ptm = posix_openpt(O_RDWR); | ||
111 | #else | ||
112 | ptm = open("/dev/ptmx", O_RDWR); | ||
113 | if(ptm == -1) | ||
114 | if(openpty(&ptm, &pts, NULL, NULL, NULL) == -1) | ||
115 | eprintn("error, cannot open pty"); | ||
116 | #endif | ||
117 | #if defined(_XOPEN_SOURCE) | ||
118 | if(ptm != -1) { | ||
119 | if(grantpt(ptm) == -1) | ||
120 | eprintn("error, cannot grant access to pty"); | ||
121 | if(unlockpt(ptm) == -1) | ||
122 | eprintn("error, cannot unlock pty"); | ||
123 | ptsdev = ptsname(ptm); | ||
124 | if(!ptsdev) | ||
125 | eprintn("error, slave pty name undefined"); | ||
126 | pts = open(ptsdev, O_RDWR); | ||
127 | if(pts == -1) | ||
128 | eprintn("error, cannot open slave pty"); | ||
129 | } | ||
130 | else | ||
131 | eprintn("error, cannot open pty"); | ||
132 | #endif | ||
133 | } | ||
134 | |||
135 | void | ||
136 | movea(int x, int y) { | 101 | movea(int x, int y) { |
137 | x = MAX(x, cols); | 102 | x = MAX(x, cols); |
138 | y = MAX(y, lines); | 103 | y = MAX(y, lines); |