diff options
| author | Matthias-Christian Ott <ott@enolink.de> | 2008-07-21 10:34:02 +0200 |
|---|---|---|
| committer | Matthias-Christian Ott <ott@enolink.de> | 2008-07-21 10:34:02 +0200 |
| commit | 082d8bb82bc478bdd0b1470232ba52976a0c035d (patch) | |
| tree | e8dc2a779c5f53482e898f956b233df6accb2862 | |
| parent | 6c6b65ea6ec775cc02c25b8cf69cce32971f9fe8 (diff) | |
| download | st-082d8bb82bc478bdd0b1470232ba52976a0c035d.tar.gz st-082d8bb82bc478bdd0b1470232ba52976a0c035d.zip | |
reunite pty.c with std.c
| -rw-r--r-- | pty.c | 42 | ||||
| -rw-r--r-- | std.c | 40 |
2 files changed, 38 insertions, 44 deletions
| @@ -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 | |||
| 10 | extern int ptm, pts; | ||
| 11 | |||
| 12 | void | ||
| 13 | getpty(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 | } | ||
| @@ -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 @@ | |||
| 17 | static void buffer(char c); | 21 | static void buffer(char c); |
| 18 | static void cmd(const char *cmdstr, ...); | 22 | static void cmd(const char *cmdstr, ...); |
| 19 | static int getch(); | 23 | static int getch(); |
| 20 | void getpty(void); | 24 | static void getpty(void); |
| 21 | static void movea(int x, int y); | 25 | static void movea(int x, int y); |
| 22 | static void mover(int x, int y); | 26 | static void mover(int x, int y); |
| 23 | static void parseesc(void); | 27 | static void parseesc(void); |
| @@ -41,7 +45,7 @@ typedef struct { | |||
| 41 | static int cols = 80, lines = 25; | 45 | static int cols = 80, lines = 25; |
| 42 | static int cx = 0, cy = 0; | 46 | static int cx = 0, cy = 0; |
| 43 | static int c; | 47 | static int c; |
| 44 | int ptm, pts; | 48 | static int ptm, pts; |
| 45 | static _Bool bold, digit, qmark; | 49 | static _Bool bold, digit, qmark; |
| 46 | static pid_t pid; | 50 | static pid_t pid; |
| 47 | static RingBuffer buf; | 51 | static RingBuffer buf; |
| @@ -208,6 +212,38 @@ scroll(int l) { | |||
| 208 | } | 212 | } |
| 209 | 213 | ||
| 210 | void | 214 | void |
| 215 | getpty(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 | |||
| 246 | void | ||
| 211 | shell(void) { | 247 | shell(void) { |
| 212 | static char *shell = NULL; | 248 | static char *shell = NULL; |
| 213 | 249 | ||
