annotate termhelper.c @ 989:d70000fdff0b

Implemented IR and undefined bits of info word for address error exception frames
author Michael Pavone <pavone@retrodev.com>
date Wed, 27 Apr 2016 21:39:17 -0700
parents 792be135d3af
children
rev   line source
pavone@794 1 #include <sys/types.h>
pavone@794 2 #include <sys/stat.h>
pavone@794 3 #include <fcntl.h>
pavone@794 4 #include <unistd.h>
pavone@794 5 #include <stdlib.h>
pavone@794 6 #include "terminal.h"
pavone@794 7
pavone@794 8 char buf[4096];
pavone@794 9
pavone@794 10 void copy_data(int to, int from)
pavone@794 11 {
pavone@794 12 ssize_t bytes = read(from, buf, sizeof(buf));
pavone@794 13 while (bytes > 0)
pavone@794 14 {
pavone@794 15 ssize_t written = write(to, buf, bytes);
pavone@794 16 if (written == -1) {
pavone@794 17 exit(1);
pavone@794 18 }
pavone@794 19 bytes -= written;
pavone@794 20 }
pavone@794 21 }
pavone@794 22
pavone@794 23 int main(int argc, char **argv)
pavone@794 24 {
pavone@794 25 //these will block so order is important
pavone@794 26 int input_fd = open(INPUT_PATH, O_WRONLY);
pavone@794 27 int output_fd = open(OUTPUT_PATH, O_RDONLY);
pavone@794 28 fd_set read_fds;
pavone@794 29 FD_ZERO(&read_fds);
pavone@794 30 for (;;)
pavone@794 31 {
pavone@794 32 FD_SET(STDIN_FILENO, &read_fds);
pavone@794 33 FD_SET(output_fd, &read_fds);
pavone@794 34 select(output_fd+1, &read_fds, NULL, NULL, NULL);
pavone@794 35
pavone@794 36 if (FD_ISSET(STDIN_FILENO, &read_fds)) {
pavone@794 37 copy_data(input_fd, STDIN_FILENO);
pavone@794 38 }
pavone@794 39 if (FD_ISSET(output_fd, &read_fds)) {
pavone@794 40 copy_data(STDOUT_FILENO, output_fd);
pavone@794 41 }
pavone@794 42 }
pavone@794 43 return 0;
pavone@794 44 }