Move pv_write_retry() and pv_tty_write() from cursor.c to display.c so they sit with all the other display functions.

This commit is contained in:
Andrew Wood
2024-10-04 09:06:24 +01:00
parent 31d70dae49
commit a6c978573f
2 changed files with 43 additions and 38 deletions
+5 -38
View File
@@ -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--;
+38
View File
@@ -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.