| 180 |
|
error(SYSTEM, "cannot open output pipe in io_process"); |
| 181 |
|
} |
| 182 |
|
/* pass input to output */ |
| 183 |
< |
cp = buf; n = sizeof(buf); |
| 184 |
< |
/* do as much as we can each way */ |
| 185 |
< |
while ((nr = read(0, cp, n)) > 0) { |
| 186 |
< |
nr += cp-buf; |
| 187 |
< |
if ((n = write(1, buf, nr)) <= 0) |
| 188 |
< |
goto writerr; |
| 189 |
< |
cp = buf; |
| 190 |
< |
while (n < nr) |
| 191 |
< |
*cp++ = buf[n++]; |
| 192 |
< |
n = sizeof(buf) - (cp-buf); |
| 193 |
< |
} |
| 183 |
> |
/* read as much as we can, write all of it */ |
| 184 |
> |
while ((nr = read(0, cp=buf, sizeof(buf))) > 0) |
| 185 |
> |
do { |
| 186 |
> |
if ((n = write(1, cp, nr)) <= 0) |
| 187 |
> |
goto writerr; |
| 188 |
> |
cp += n; |
| 189 |
> |
} while ((nr -= n) > 0); |
| 190 |
|
if (nr < 0) |
| 191 |
|
error(SYSTEM, "read error in io_process"); |
| 192 |
|
close(0); /* close input */ |
| 197 |
– |
nr = cp-buf; /* write remainder */ |
| 198 |
– |
cp = buf; |
| 199 |
– |
while (nr > 0) { |
| 200 |
– |
if ((n = write(1, cp, nr)) <= 0) |
| 201 |
– |
goto writerr; |
| 202 |
– |
cp += n; |
| 203 |
– |
nr -= n; |
| 204 |
– |
} |
| 193 |
|
close(1); /* close output */ |
| 194 |
|
if (pid) /* parent waits for child */ |
| 195 |
|
wait(0); |