aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias-Christian Ott <ott@enolink.de>2008-07-21 10:34:02 +0200
committerMatthias-Christian Ott <ott@enolink.de>2008-07-21 10:34:02 +0200
commit082d8bb82bc478bdd0b1470232ba52976a0c035d (patch)
treee8dc2a779c5f53482e898f956b233df6accb2862
parent6c6b65ea6ec775cc02c25b8cf69cce32971f9fe8 (diff)
downloadst-082d8bb82bc478bdd0b1470232ba52976a0c035d.tar.gz
st-082d8bb82bc478bdd0b1470232ba52976a0c035d.zip
reunite pty.c with std.c
-rw-r--r--pty.c42
-rw-r--r--std.c40
2 files changed, 38 insertions, 44 deletions
diff --git a/pty.c b/pty.c
deleted file mode 100644
index 3efaa7f..0000000
--- a/pty.c
+++ /dev/null
@@ -1,42 +0,0 @@
1/* See LICENSE file for copyright and license details. */
2#include <sys/types.h>
3#include <sys/stat.h>
4#include <fcntl.h>
5#include <stdlib.h>
6#if !(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
7#include <pty.h>
8#endif
9
10extern int ptm, pts;
11
12void
13getpty(void) {
14 char *ptsdev;
15
16#if defined(_GNU_SOURCE)
17 ptm = getpt();
18#elif _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600
19 ptm = posix_openpt(O_RDWR);
20#else
21 ptm = open("/dev/ptmx", O_RDWR);
22 if(ptm == -1)
23 if(openpty(&ptm, &pts, NULL, NULL, NULL) == -1)
24 err(EXIT_FAILURE, "cannot open pty");
25#endif
26#if defined(_XOPEN_SOURCE)
27 if(ptm != -1) {
28 if(grantpt(ptm) == -1)
29 err(EXIT_FAILURE, "cannot grant access to pty");
30 if(unlockpt(ptm) == -1)
31 err(EXIT_FAILURE, "cannot unlock pty");
32 ptsdev = ptsname(ptm);
33 if(!ptsdev)
34 err(EXIT_FAILURE, "slave pty name undefined");
35 pts = open(ptsdev, O_RDWR);
36 if(pts == -1)
37 err(EXIT_FAILURE, "cannot open slave pty");
38 }
39 else
40 err(EXIT_FAILURE, "cannot open pty");
41#endif
42}
diff --git a/std.c b/std.c
index 2ce1722..ef9e57a 100644
--- a/std.c
+++ b/std.c
@@ -3,6 +3,10 @@
3#include <sys/wait.h> 3#include <sys/wait.h>
4#include <ctype.h> 4#include <ctype.h>
5#include <err.h> 5#include <err.h>
6#include <fcntl.h>
7#if !(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
8#include <pty.h>
9#endif
6#include <signal.h> 10#include <signal.h>
7#include <stdarg.h> 11#include <stdarg.h>
8#include <stdio.h> 12#include <stdio.h>
@@ -17,7 +21,7 @@
17static void buffer(char c); 21static void buffer(char c);
18static void cmd(const char *cmdstr, ...); 22static void cmd(const char *cmdstr, ...);
19static int getch(); 23static int getch();
20void getpty(void); 24static void getpty(void);
21static void movea(int x, int y); 25static void movea(int x, int y);
22static void mover(int x, int y); 26static void mover(int x, int y);
23static void parseesc(void); 27static void parseesc(void);
@@ -41,7 +45,7 @@ typedef struct {
41static int cols = 80, lines = 25; 45static int cols = 80, lines = 25;
42static int cx = 0, cy = 0; 46static int cx = 0, cy = 0;
43static int c; 47static int c;
44int ptm, pts; 48static int ptm, pts;
45static _Bool bold, digit, qmark; 49static _Bool bold, digit, qmark;
46static pid_t pid; 50static pid_t pid;
47static RingBuffer buf; 51static RingBuffer buf;
@@ -208,6 +212,38 @@ scroll(int l) {
208} 212}
209 213
210void 214void
215getpty(void) {
216 char *ptsdev;
217
218#if defined(_GNU_SOURCE)
219 ptm = getpt();
220#elif _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600
221 ptm = posix_openpt(O_RDWR);
222#else
223 ptm = open("/dev/ptmx", O_RDWR);
224 if(ptm == -1)
225 if(openpty(&ptm, &pts, NULL, NULL, NULL) == -1)
226 err(EXIT_FAILURE, "cannot open pty");
227#endif
228#if defined(_XOPEN_SOURCE)
229 if(ptm != -1) {
230 if(grantpt(ptm) == -1)
231 err(EXIT_FAILURE, "cannot grant access to pty");
232 if(unlockpt(ptm) == -1)
233 err(EXIT_FAILURE, "cannot unlock pty");
234 ptsdev = ptsname(ptm);
235 if(!ptsdev)
236 err(EXIT_FAILURE, "slave pty name undefined");
237 pts = open(ptsdev, O_RDWR);
238 if(pts == -1)
239 err(EXIT_FAILURE, "cannot open slave pty");
240 }
241 else
242 err(EXIT_FAILURE, "cannot open pty");
243#endif
244}
245
246void
211shell(void) { 247shell(void) {
212 static char *shell = NULL; 248 static char *shell = NULL;
213 249