1 /* tty.h: shared tty info for cygwin
3 Copyright 2000, 2001 Red Hat, Inc.
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
14 #define INP_BUFFER_SIZE 256
15 #define OUT_BUFFER_SIZE 256
17 #define real_tty_attached(p) ((p)->ctty >= 0 && (p)->ctty != TTY_CONSOLE)
19 /* Input/Output/ioctl events */
21 #define OUTPUT_DONE_EVENT "cygtty%d.output.done"
22 #define IOCTL_REQUEST_EVENT "cygtty%d.ioctl.request"
23 #define IOCTL_DONE_EVENT "cygtty%d.ioctl.done"
24 #define RESTART_OUTPUT_EVENT "cygtty%d.output.restart"
25 #define INPUT_AVAILABLE_EVENT "cygtty%d.input.avail"
26 #define OUTPUT_MUTEX "cygtty%d.output.mutex"
27 #define INPUT_MUTEX "cygtty%d.input.mutex"
28 #define TTY_SLAVE_ALIVE "cygtty%x.slave_alive"
29 #define TTY_MASTER_ALIVE "cygtty%x.master_alive"
31 #include <sys/termios.h>
35 TTY_INITIALIZED = 1, /* Set if tty is initialized */
36 TTY_RSTCONS = 2 /* Set if console needs to be set to "non-cooked" */
39 #define TTYISSETF(x) __ISSETF (tc, x, TTY)
40 #define TTYSETF(x) __SETF (tc, x, TTY)
41 #define TTYCLEARF(x) __CLEARF (tc, x, TTY)
42 #define TTYCONDSETF(n, x) __CONDSETF(n, tc, x, TTY)
44 #ifndef MIN_CTRL_C_SLOP
45 #define MIN_CTRL_C_SLOP 50
50 pid_t sid; /* Session ID of tty */
56 DWORD last_ctrl_c; // tick count of last ctrl-c
58 tty_min (int t = -1, pid_t s = -1) : sid (s), ntty (t) {}
59 void setntty (int n) {ntty = n;}
60 pid_t getpgid () {return pgid;}
61 void setpgid (int pid) {pgid = pid;}
62 int getsid () {return sid;}
63 void setsid (pid_t tsid) {sid = tsid;}
64 void set_ctty (int ttynum, int flags);
65 void kill_pgrp (int sig);
67 struct winsize winsize;
69 /* ioctl requests buffer */
73 struct termios termios;
74 struct winsize winsize;
78 /* XXX_retval variables holds master's completion codes. Error are stored as
86 class fhandler_pty_master;
88 class tty: public tty_min
90 HANDLE get_event (const char *fmt, BOOL manual_reset = FALSE)
91 __attribute__ ((regparm (2)));
93 HWND hwnd; /* Console window handle tty belongs to */
95 DWORD master_pid; /* Win32 PID of tty master process */
97 HANDLE from_master, to_slave;
98 HANDLE from_slave, to_master;
101 BOOL was_opened; /* True if opened at least once. */
104 HANDLE create_inuse (const char *);
105 BOOL common_init (fhandler_pty_master *);
106 BOOL alive (const char *fmt);
108 BOOL master_alive ();
109 HWND gethwnd () {return hwnd;}
110 void sethwnd (HWND wnd) {hwnd = wnd;}
111 int make_pipes (fhandler_pty_master *ptym);
112 HANDLE open_output_mutex ()
115 __small_sprintf (buf, OUTPUT_MUTEX, ntty);
116 return OpenMutex (MUTEX_ALL_ACCESS, TRUE, buf);
118 HANDLE open_input_mutex ()
121 __small_sprintf (buf, INPUT_MUTEX, ntty);
122 return OpenMutex (MUTEX_ALL_ACCESS, TRUE, buf);
126 HANDLE h = open_output_mutex ();
132 return slave_alive ();
141 tty * operator [](int n) {return ttys + n;}
142 int allocate_tty (int n); /* n non zero if allocate a tty, pty otherwise */
143 int connect_tty (int);
146 tty_min *get_tty (int n);
149 void __stdcall tty_init ();
150 void __stdcall tty_terminate ();
151 int __stdcall attach_tty (int);
152 void __stdcall create_tty_master (int);
153 extern "C" int ttyslot (void);