From bf16b7b8593d4013adbd03838af5a2fb3bce34ee Mon Sep 17 00:00:00 2001 From: epoch Date: Wed, 6 Feb 2019 00:53:08 -0600 Subject: I forgot to add the examples dir somehow. they're back. tictactoe works again too. --- share/hackvr/examples/hackvr_term/pty.c | 62 +++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 share/hackvr/examples/hackvr_term/pty.c (limited to 'share/hackvr/examples/hackvr_term/pty.c') diff --git a/share/hackvr/examples/hackvr_term/pty.c b/share/hackvr/examples/hackvr_term/pty.c new file mode 100644 index 0000000..1011e38 --- /dev/null +++ b/share/hackvr/examples/hackvr_term/pty.c @@ -0,0 +1,62 @@ +#include +#include +#include + +int main(int argc,char *argv[]) { + char *pts; + char in[256];//I dunno. + int r; + int pid; + int master,slave; + master=open("/dev/ptmx",O_RDWR); + if(master == -1) return 1; + pts=ptsname(master); +// printf("%s\n",pts); +// system("ls -l /dev/pts/*"); + grantpt(master); + unlockpt(master); +// system("ls -l /dev/pts/*"); + if(pts == NULL) return 2; + slave=open(pts,O_RDWR); + if(slave == -1) { + perror("open"); + return 3; + } + argv++; + fcntl(master,F_SETFL,O_NONBLOCK); +// fcntl(slave,F_SETFL,O_NONBLOCK); + fcntl(0,F_SETFL,O_NONBLOCK); + fcntl(1,F_SETFL,O_NONBLOCK); + fcntl(2,F_SETFL,O_NONBLOCK); + switch(pid=fork()) { + case -1: + return 4;//fork failed + case 0://child + setsid(); + close(master); + dup2(slave,0); + dup2(slave,1); + dup2(slave,2); + execv(argv[0],argv);//execute arguments. + return 5;//exec failed + default: + break; + } + for(;;) { + if(waitpid(-1,0,WNOHANG) > 0) { + return 0;//fuck if I know. + //we got a dead child. let's bail. + } + switch(r=read(0,&in,1)) { + case 0: return 6;//EOF + case -1: break;//EAGAIN probably. + default: write(master,in,r); + } + switch(r=read(master,&in,1)) { + case 0: return 7;//EOF + case -1: break;//EAGAIN probably + default: write(1,in,r); + } + usleep(100);//kek + } +} -- cgit v1.2.3