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 committed 2021-04-04 12:35:35 +02:00
1 parent c84c17ea8c
commit 5342881bf4
5 files changed
+41 -24

No files matched your search

+19 -1
View File
@@ -70,7 +70,7 @@ void show_progress (pstyle_t style);
int getty (char *tty, speed_t speed, char *term, char *user);
int sh (char *tty);
int stty (int fd, speed_t speed);
void stty (int fd, speed_t speed);
speed_t stty_parse_speed(char *baud);
void print_banner (const char *heading);
@@ -109,6 +109,24 @@ static inline int create(char *path, mode_t mode, uid_t uid, gid_t gid)
return 0;
}
static inline int dprint(int fd, const char *s, size_t len)
{
size_t loop = 3;
int rc = -1;
if (!len)
len = strlen(s);
while (loop--) {
rc = write(fd, s, len);
if (rc == -1 && errno == EINTR)
continue;
break;
}
return rc;
}
int ismnt (char *file, char *dir, char *mode);
int fismnt (char *dir);