diff options
Diffstat (limited to 'std.c')
| -rw-r--r-- | std.c | 40 |
1 files changed, 38 insertions, 2 deletions
| @@ -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 | ||
