2 * Copyright 2013, Tan Chee Eng (@tan-ce)
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 * Manages the pseudo-terminal driver on Linux/Android and provides some
21 * helper functions to handle raw input mode and terminal window resizing
30 * Opens a pts device and returns the name of the slave tty device.
33 * slave_name the name of the slave device
34 * slave_name_size the size of the buffer passed via slave_name
37 * on failure either -2 or -1 (errno set) is returned.
38 * on success, the file descriptor of the master device is returned.
40 int pts_open(char *slave_name, size_t slave_name_size);
45 * Changes stdin to raw unbuffered mode, disables echo,
46 * auto carriage return, etc.
49 * on failure -1, and errno is set
52 int set_stdin_raw(void);
57 * Restore termios on stdin to the state it was before
58 * set_stdin_raw() was called. If set_stdin_raw() was
59 * never called, does nothing and doesn't return an error.
61 * This function is async-safe.
64 * on failure, -1 and errno is set
67 int restore_stdin(void);
70 * watch_sigwinch_async
72 * After calling this function, if the application receives
73 * SIGWINCH, the terminal window size will be read from
74 * "input" and set on "output".
76 * NOTE: This function blocks SIGWINCH and spawns a thread.
79 * master A file descriptor of the TTY window size to follow
80 * slave A file descriptor of the TTY window size which is
81 * to be set on SIGWINCH
84 * on failure, -1 and errno will be set. In this case, no
85 * thread has been spawned and SIGWINCH will not be
89 int watch_sigwinch_async(int master, int slave);
92 * watch_sigwinch_cleanup
94 * Cause the SIGWINCH watcher thread to terminate
96 void watch_sigwinch_cleanup(void);
101 * Forward data from STDIN to the given FD
102 * in a seperate thread
104 void pump_stdin_async(int outfd);
107 * pump_stdout_blocking
109 * Forward data from the FD to STDOUT.
110 * Returns when the remote end of the FD closes.
112 * Before returning, restores stdin settings.
114 void pump_stdout_blocking(int infd);