aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias-Christian Ott <ott@enolink.de>2008-06-10 17:30:15 +0200
committerMatthias-Christian Ott <ott@enolink.de>2008-06-10 17:30:15 +0200
commit47d8633f157156ef4701ce71ed7eff766206c107 (patch)
tree78190354f0b6784063f5434821b40bbe0ebd8d1e
parent0dedee5de8e35f4bab3d707d63be31943715264e (diff)
downloadst-47d8633f157156ef4701ce71ed7eff766206c107.tar.gz
st-47d8633f157156ef4701ce71ed7eff766206c107.zip
source getpty() out to pty.c
-rw-r--r--pty.c41
-rw-r--r--std.c35
2 files changed, 41 insertions, 35 deletions
diff --git a/pty.c b/pty.c
new file mode 100644
index 0000000..a3e43b0
--- /dev/null
+++ b/pty.c
@@ -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
9extern int ptm, pts;
10
11void
12getpty(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}
diff --git a/std.c b/std.c
index fcfead9..1b918f5 100644
--- a/std.c
+++ b/std.c
@@ -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
103void 100void
104getpty(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
135void
136movea(int x, int y) { 101movea(int x, int y) {
137 x = MAX(x, cols); 102 x = MAX(x, cols);
138 y = MAX(y, lines); 103 y = MAX(y, lines);