X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/f7aa4b367eaf2c1e928f97263bcf4da74680aff3..f9520103d3b3a1a36fdb30a46aa4f6c1cd3f1c9e:/unix/uxplink.c diff --git a/unix/uxplink.c b/unix/uxplink.c index 9e10c488..898f27c3 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -396,20 +396,18 @@ int try_output(int is_stderr) bufchain *chain = (is_stderr ? &stderr_data : &stdout_data); int fd = (is_stderr ? STDERR_FILENO : STDOUT_FILENO); void *senddata; - int sendlen, ret, fl; + int sendlen, ret; if (bufchain_size(chain) > 0) { - fl = fcntl(fd, F_GETFL); - if (fl != -1 && !(fl & O_NONBLOCK)) - fcntl(fd, F_SETFL, fl | O_NONBLOCK); + int prev_nonblock = nonblock(fd); do { bufchain_prefix(chain, &senddata, &sendlen); ret = write(fd, senddata, sendlen); if (ret > 0) bufchain_consume(chain, ret); } while (ret == sendlen && bufchain_size(chain) != 0); - if (fl != -1 && !(fl & O_NONBLOCK)) - fcntl(fd, F_SETFL, fl); + if (!prev_nonblock) + no_nonblock(fd); if (ret < 0 && errno != EAGAIN) { perror(is_stderr ? "stderr: write" : "stdout: write"); exit(1);