rc

[fork] interactive rc shell
git clone https://hhvn.uk/rc
git clone git://hhvn.uk/rc
Log | Files | Refs | README | LICENSE

tripping.c (713B)


      1 /* This is an auxiliary test program for rc.  */
      2 
      3 #include "config.h"
      4 
      5 #include <fcntl.h>
      6 #include <stdio.h>
      7 #include <stdlib.h>
      8 #include <sys/types.h>
      9 #include <unistd.h>
     10 
     11 static void out0(void) {
     12 	putchar('t'); putchar('r');
     13 	putchar('\0');
     14 	putchar('u'); putchar('e');
     15 	putchar('\n');
     16 }
     17 
     18 static void ctrl_a(void) {
     19 	puts("a\001ab\002b");
     20 }
     21 
     22 static void makenonblock(void) {
     23 	int flags;
     24 
     25 	if ((flags = fcntl(0, F_GETFL)) == -1)
     26 		perror("fcntl 1");
     27 	flags |= O_NONBLOCK;
     28 	if (fcntl(0, F_SETFL, (long) flags) == -1)
     29 		perror("fcntl 2");
     30 }
     31 
     32 int main(int argc, char **argv) {
     33 	switch(argv[1][0]) {
     34 	case '0':
     35 		out0();
     36 		break;
     37 	case 'a':
     38 		ctrl_a();
     39 		break;
     40 	case 'n':
     41 		makenonblock();
     42 		break;
     43 	}
     44 	return 0;
     45 }