diff --git a/src/pv/cursor.c b/src/pv/cursor.c index 89f565d..7c5e664 100644 --- a/src/pv/cursor.c +++ b/src/pv/cursor.c @@ -43,44 +43,6 @@ #endif -/* - * Write the given buffer to the given file descriptor, retrying until all - * bytes have been written or an error has occurred. - */ -void pv_write_retry(int fd, const char *buf, size_t count) -{ - while (count > 0) { - ssize_t nwritten; - - nwritten = write(fd, buf, count); - - if (nwritten < 0) { - if ((EINTR == errno) || (EAGAIN == errno)) { - continue; - } - return; - } - if (nwritten < 1) - return; - - count -= nwritten; - buf += nwritten; - } -} - - -/* - * Write the given buffer to the terminal with pv_write_retry(), unless - * stderr is suspended. - */ -void pv_tty_write(pvstate_t state, const char *buf, size_t count) -{ - if (1 == state->flag.suspend_stderr) - return; - pv_write_retry(STDERR_FILENO, buf, count); -} - - /* * Create a per-euid, per-tty, lockfile in ${TMPDIR:-${TMP:-/tmp}} for the * tty on the given file descriptor. @@ -507,6 +469,11 @@ static void pv_crs_reinit(pvstate_t state) { debug("%s", "reinit"); + if (1 == state->flag.suspend_stderr) { + debug("%s", "reinit abandoned - stderr is suspended"); + return; + } + pv_crs_lock(state, STDERR_FILENO); state->cursor.needreinit--; diff --git a/src/pv/display.c b/src/pv/display.c index 794a083..2a1b3df 100644 --- a/src/pv/display.c +++ b/src/pv/display.c @@ -92,6 +92,44 @@ bool pv_in_foreground(void) } +/* + * Write the given buffer to the given file descriptor, retrying until all + * bytes have been written or an error has occurred. + */ +void pv_write_retry(int fd, const char *buf, size_t count) +{ + while (count > 0) { + ssize_t nwritten; + + nwritten = write(fd, buf, count); + + if (nwritten < 0) { + if ((EINTR == errno) || (EAGAIN == errno)) { + continue; + } + return; + } + if (nwritten < 1) + return; + + count -= nwritten; + buf += nwritten; + } +} + + +/* + * Write the given buffer to the terminal with pv_write_retry(), unless + * stderr is suspended. + */ +void pv_tty_write(pvstate_t state, const char *buf, size_t count) +{ + if (1 == state->flag.suspend_stderr) + return; + pv_write_retry(STDERR_FILENO, buf, count); +} + + /* * Fill in *width and *height with the current terminal size, * if possible.