From 12e09f9f85ac48ff891adf92f3b2c9a5fea27273 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Sat, 4 Dec 2021 14:10:21 -0800 Subject: Chore(REMOVE): finished deprecation of old io functions. The old methods were simple wrappers of C standard library functions. We've moved (painfully) over to a new interface that allows for files to live on the stack. All users of the functionality are ported over. --- src/cmd/rc/exec.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) (limited to 'src/cmd/rc/exec.c') diff --git a/src/cmd/rc/exec.c b/src/cmd/rc/exec.c index bd68bf5..bdbc151 100644 --- a/src/cmd/rc/exec.c +++ b/src/cmd/rc/exec.c @@ -5,16 +5,20 @@ int yyparse(void); -struct Builtin{ +struct Builtin +{ char *name; void (*func)(void); }; -struct State { +#if 0 +struct State +{ int async; }; static struct State state; +#endif // ----------------------------------------------------------------------- // globals @@ -1414,6 +1418,54 @@ Xpipe(void) } } +void +Xpipefd(void) +{ + char name[40]; + Thread *orig = runner; + int pc, fd, pid, pfd[2], sidefd, mainfd; + + pc = runner->code.i; + if(pipe(pfd)<0){ + Xerror("can't get pipe"); + return; + } + + if(runner->code.exe[runner->code.i].i == Rread) + fd=1, sidefd=pfd[1], mainfd=pfd[0]; + else + fd=0, sidefd=pfd[0], mainfd=pfd[1]; + + switch(pid = fork()){ + case -1: + Xerror("try again"); + break; + case 0: + initchild(runner,1); + + /* child 0 (writer) forked process */ + run(runner->code.exe, pc+2, runner->local, 1); + + close(mainfd); + pushredir(Ropen, sidefd, fd); + runner->caller = nil; + break; + + default: + initparent(runner,pid,0); + + close(sidefd); + pushredir(Ropen, mainfd, mainfd); + + strcpy(name, "/dev/fd/"); + strĀ·itoa(name+8, mainfd); + pushword(name); + + orig->code.i = orig->code.exe[pc+1].i; + break; + } +} + void Xbasic(void) { -- cgit v1.2.1