diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | termvader.c | 31 |
2 files changed, 33 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..32cd0f5 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +CFLAGS = -O2 -march=native -std=c99 +termvader: diff --git a/termvader.c b/termvader.c new file mode 100644 index 0000000..474fe39 --- /dev/null +++ b/termvader.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <sys/ioctl.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> + +int main(int argc, char *argv[]) +{ + if (argc != 3) { + fprintf(stderr, "Usage: %s /dev/tty[0-9]+ COMMANDS ...\n", argv[0]); + fprintf(stderr, "You can obtain the tty device from a particular terminal via the 'tty' command.\n"); + fprintf(stderr, "Please note, you may have to run this program as root.\n"); + return 1; + } + int ttyfd; + if ((ttyfd = open(argv[1], O_WRONLY)) == -1) { + perror("open"); + return errno; + } + for (char *c = argv[2]; *c; ++c) { + if (ioctl(ttyfd, TIOCSTI, c) == -1) { + perror("ioctl"); + return errno; + } + } + if (ioctl(ttyfd, TIOCSTI, "\n") == -1) { + perror("ioctl"); + return errno; + } + return 0; +} |
