aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-14 09:49:06 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-14 09:49:06 +0200
commit1a41ae3e030c467416a075667dd404ea3e650bc0 (patch)
tree4313cf317c4625f3f42ba461edb77b2156bf348a
downloadrtty-1a41ae3e030c467416a075667dd404ea3e650bc0.tar.gz
Add rin.c
-rw-r--r--rin.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/rin.c b/rin.c
new file mode 100644
index 0000000..72463d8
--- /dev/null
+++ b/rin.c
@@ -0,0 +1,34 @@
+#include <err.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <termios.h>
+#include <unistd.h>
+
+int
+main()
+{
+ int c, n, o, t;
+ struct termios orig, term;
+
+ t = 0;
+
+ if((o = open("/var/tmp/r.in", O_RDWR)) == -1)
+ err(1, "/var/tmp/r.in");
+
+ /* Enter "raw" terminal mode. */
+ tcgetattr(t, &orig);
+ tcgetattr(t, &term);
+ term.c_lflag &= ~(ICANON|ECHO|ISIG);
+ tcsetattr(t, TCSANOW, &term);
+
+ while((n = read(t, &c, 1)) > 0){
+ if(c == 26) /* ^Z */
+ break;
+ if(c != '\n')
+ write(t, &c, 1);
+ write(o, &c, 1);
+ }
+
+ /* Restore original terminal mode. */
+ tcsetattr(t, TCSANOW, &orig);
+}