--- ray/src/rt/persist.c 1993/01/29 12:02:29 2.6 +++ ray/src/rt/persist.c 1993/02/10 11:02:20 2.7 @@ -171,30 +171,45 @@ io_process() /* just act as conduits to and from actu error(SYSTEM, "fork failed in io_process"); /* connect to appropriate pipe */ if (pid) { /* parent passes renderer output */ - if (freopen(pfout, "r", stdin) == NULL) + close(0); + if (open(pfout, O_RDONLY) != 0) error(SYSTEM, "cannot open input pipe in io_process"); } else { /* child passes renderer input */ - if (freopen(pfin, "w", stdout) == NULL) - error(SYSTEM, "cannot open input pipe in io_process"); + close(1); + if (open(pfin, O_WRONLY) != 1) + error(SYSTEM, "cannot open output pipe in io_process"); } /* pass input to output */ cp = buf; n = sizeof(buf); - while ((nr = read(fileno(stdin), cp, n)) > 0) { + /* do as much as we can each way */ + while ((nr = read(0, cp, n)) > 0) { nr += cp-buf; - if ((n = write(fileno(stdout), buf, nr)) <= 0) - error(SYSTEM, "write error in io_process"); + if ((n = write(1, buf, nr)) <= 0) + goto writerr; cp = buf; while (n < nr) *cp++ = buf[n++]; n = sizeof(buf) - (cp-buf); } - fclose(stdin); - fclose(stdout); + if (nr < 0) + error(SYSTEM, "read error in io_process"); + close(0); /* close input */ + nr = cp-buf; /* write remainder */ + cp = buf; + while (nr > 0) { + if ((n = write(1, cp, nr)) <= 0) + goto writerr; + cp += n; + nr -= n; + } + close(1); /* close output */ if (pid) /* parent waits for child */ wait(0); exit(0); /* all done, exit (not quit!) */ formerr: error(USER, "format error in persist file"); +writerr: + error(SYSTEM, "write error in io_process"); } #endif