2018-07-18 10:12:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013, Tan Chee Eng (@tan-ce)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2020-03-09 08:50:30 +00:00
|
|
|
* pts.hpp
|
2018-07-18 10:12:47 +00:00
|
|
|
*
|
|
|
|
* Manages the pseudo-terminal driver on Linux/Android and provides some
|
|
|
|
* helper functions to handle raw input mode and terminal window resizing
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _PTS_H_
|
|
|
|
#define _PTS_H_
|
|
|
|
|
2017-04-14 19:21:31 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2018-07-18 10:12:47 +00:00
|
|
|
/**
|
|
|
|
* pts_open
|
|
|
|
*
|
|
|
|
* Opens a pts device and returns the name of the slave tty device.
|
|
|
|
*
|
|
|
|
* Arguments
|
|
|
|
* slave_name the name of the slave device
|
|
|
|
* slave_name_size the size of the buffer passed via slave_name
|
|
|
|
*
|
|
|
|
* Return Values
|
|
|
|
* on failure either -2 or -1 (errno set) is returned.
|
|
|
|
* on success, the file descriptor of the master device is returned.
|
|
|
|
*/
|
|
|
|
int pts_open(char *slave_name, size_t slave_name_size);
|
|
|
|
|
2021-07-22 15:35:14 +00:00
|
|
|
|
|
|
|
int get_pty_num(int fd);
|
|
|
|
|
2018-07-18 10:12:47 +00:00
|
|
|
/**
|
|
|
|
* set_stdin_raw
|
|
|
|
*
|
2021-07-22 15:35:14 +00:00
|
|
|
* Changes stdin to raw unbuffered mode, disables echo,
|
2018-07-18 10:12:47 +00:00
|
|
|
* auto carriage return, etc.
|
|
|
|
*
|
|
|
|
* Return Value
|
|
|
|
* on failure -1, and errno is set
|
|
|
|
* on success 0
|
|
|
|
*/
|
|
|
|
int set_stdin_raw(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* restore_stdin
|
|
|
|
*
|
|
|
|
* Restore termios on stdin to the state it was before
|
|
|
|
* set_stdin_raw() was called. If set_stdin_raw() was
|
|
|
|
* never called, does nothing and doesn't return an error.
|
|
|
|
*
|
|
|
|
* This function is async-safe.
|
|
|
|
*
|
|
|
|
* Return Value
|
|
|
|
* on failure, -1 and errno is set
|
|
|
|
* on success, 0
|
|
|
|
*/
|
|
|
|
int restore_stdin(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* watch_sigwinch_async
|
|
|
|
*
|
|
|
|
* After calling this function, if the application receives
|
2021-07-22 15:35:14 +00:00
|
|
|
* SIGWINCH, the terminal window size will be read from
|
2018-07-18 10:12:47 +00:00
|
|
|
* "input" and set on "output".
|
|
|
|
*
|
|
|
|
* NOTE: This function blocks SIGWINCH and spawns a thread.
|
|
|
|
*
|
|
|
|
* Arguments
|
|
|
|
* master A file descriptor of the TTY window size to follow
|
|
|
|
* slave A file descriptor of the TTY window size which is
|
|
|
|
* to be set on SIGWINCH
|
|
|
|
*
|
|
|
|
* Return Value
|
|
|
|
* on failure, -1 and errno will be set. In this case, no
|
2021-07-22 15:35:14 +00:00
|
|
|
* thread has been spawned and SIGWINCH will not be
|
2018-07-18 10:12:47 +00:00
|
|
|
* blocked.
|
|
|
|
* on success, 0
|
|
|
|
*/
|
|
|
|
int watch_sigwinch_async(int master, int slave);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pump_stdin_async
|
|
|
|
*
|
|
|
|
* Forward data from STDIN to the given FD
|
|
|
|
* in a seperate thread
|
|
|
|
*/
|
|
|
|
void pump_stdin_async(int outfd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pump_stdout_blocking
|
|
|
|
*
|
|
|
|
* Forward data from the FD to STDOUT.
|
|
|
|
* Returns when the remote end of the FD closes.
|
|
|
|
*
|
|
|
|
* Before returning, restores stdin settings.
|
|
|
|
*/
|
|
|
|
void pump_stdout_blocking(int infd);
|
|
|
|
|
|
|
|
#endif
|