Refactor, wrap write() syscall in new dprint() function

Fixes the GCC warning for unchecked return value from write():

  ... ignoring return value of ‘write’, declared with attribute warn_unused_result

The new dprint() function wraps write() in a bounded retry-loop that
catches EINTR.  The length argument is optional computed with strlen()
if omitted (zero).

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2021-04-04 12:35:35 +02:00
parent c84c17ea8c
commit 5342881bf4
5 changed files with 41 additions and 24 deletions
+5 -5
View File
@@ -316,7 +316,7 @@ static int activate_console(int noclear, int nowait)
return 1;
if (!noclear)
(void)write(STDERR_FILENO, "\e[r\e[H\e[J", 9);
dprint(STDERR_FILENO, "\e[r\e[H\e[J", 9);
/* Disable ECHO, XON/OFF while waiting for <CR> */
if (!tcgetattr(STDIN_FILENO, &orig)) {
@@ -340,16 +340,16 @@ static int activate_console(int noclear, int nowait)
continue;
}
(void)write(STDERR_FILENO, clr, strlen(clr));
(void)write(STDERR_FILENO, msg, strlen(msg));
dprint(STDERR_FILENO, clr, strlen(clr));
dprint(STDERR_FILENO, msg, strlen(msg));
while (read(STDIN_FILENO, &c, 1) == 1 && c != '\r')
continue;
if (fexist(SYNC_STOPPED))
continue;
(void)write(STDERR_FILENO, clr, strlen(clr));
(void)write(STDERR_FILENO, cup, strlen(cup));
dprint(STDERR_FILENO, clr, strlen(clr));
dprint(STDERR_FILENO, cup, strlen(cup));
ret = 1;
break;
}