reenabled swaptest. quake should now load data and start on big endian architectures...
[AROS-Contrib.git] / gnu / abc-shell / tty.c
bloba59d309cfa41cff756684248a2c57c7143c0f075
1 #include <sys/stat.h>
2 #include "sh.h"
3 #define EXTERN
4 #include "tty.h"
5 #undef EXTERN
7 #ifdef AMIGA
8 #define TIOCGETP 1
9 #define TIOCGETC 2
10 #define TIOCSETN 3
11 #define TIOCSETC 4
12 #endif
14 /* Initialize tty_fd. Used for saving/reseting tty modes upon
15 * foreground job completion and for setting up tty process group.
17 void
18 tty_init(int init_ttystate)
20 int do_close = 1;
21 int tfd;
23 if (tty_fd >= 0) {
24 close(tty_fd);
25 tty_fd = -1;
27 tty_devtty = 1;
29 #ifdef AMIGA
30 if ((tfd = open("CONSOLE:", O_RDWR, 0)) < 0) {
31 #else
32 if ((tfd = open("/dev/tty", O_RDWR, 0)) < 0) {
33 #endif
34 tty_devtty = 0;
35 warningf(false, "No controlling tty (open /dev/tty: %s)",
36 strerror(errno));
39 if (tfd < 0) {
40 do_close = 0;
41 if (isatty(0))
42 tfd = 0;
43 else if (isatty(2))
44 tfd = 2;
45 else {
46 warningf(false, "Can't find tty file descriptor");
47 return;
50 if ((tty_fd = fcntl(tfd, F_DUPFD, FDBASE)) < 0) {
51 warningf(false, "j_ttyinit: dup of tty fd failed: %s",
52 strerror(errno));
53 #ifndef __amigaos4__
54 } else if (fcntl(tty_fd, F_SETFD, FD_CLOEXEC) < 0) {
55 warningf(false, "j_ttyinit: can't set close-on-exec flag: %s",
56 strerror(errno));
57 close(tty_fd);
58 tty_fd = -1;
59 #endif
60 } else if (init_ttystate)
61 //tcgetattr(tty_fd, &tty_state);
62 if (do_close)
63 close(tfd);
66 void
67 tty_close(void)
69 if (tty_fd >= 0) {
70 close(tty_fd);
71 tty_fd = -1;