1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-22 07:48:50 -05:00

Avoid logical OR duplication warning from gcc-6

The value EAGAIN is allowed by POSIX to be the same as EWOULDBLOCK, but this is
not guaranteed. Thus on some systems (e.g. glibc Linux), we get a warning that
the logical OR is being performed on two expressions of the same type. We can
not get rid of this test in case any system defines these as unique values.

Suggested-by: Dave Reisner
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Allan McRae 2016-05-04 17:39:34 +10:00
parent b012da645e
commit 3729ef7a9a

View File

@ -446,6 +446,16 @@ ssize_t _alpm_files_in_directory(alpm_handle_t *handle, const char *path,
return files; return files;
} }
static int should_retry(int errnum)
{
return errnum == EAGAIN
/* EAGAIN may be the same value as EWOULDBLOCK (POSIX.1) - prevent GCC warning */
#if EAGAIN != EWOULDBLOCK
|| errnum == EWOULDBLOCK
#endif
|| errnum == EINTR;
}
static int _alpm_chroot_write_to_child(alpm_handle_t *handle, int fd, static int _alpm_chroot_write_to_child(alpm_handle_t *handle, int fd,
char *buf, ssize_t *buf_size, ssize_t buf_limit, char *buf, ssize_t *buf_size, ssize_t buf_limit,
_alpm_cb_io out_cb, void *cb_ctx) _alpm_cb_io out_cb, void *cb_ctx)
@ -476,7 +486,7 @@ static int _alpm_chroot_write_to_child(alpm_handle_t *handle, int fd,
/* write was successful, remove the written data from the buffer */ /* write was successful, remove the written data from the buffer */
*buf_size -= nwrite; *buf_size -= nwrite;
memmove(buf, buf + nwrite, *buf_size); memmove(buf, buf + nwrite, *buf_size);
} else if(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) { } else if(should_retry(errno)) {
/* nothing written, try again later */ /* nothing written, try again later */
} else { } else {
_alpm_log(handle, ALPM_LOG_ERROR, _alpm_log(handle, ALPM_LOG_ERROR,
@ -530,7 +540,7 @@ static int _alpm_chroot_read_from_child(alpm_handle_t *handle, int fd,
_alpm_chroot_process_output(handle, buf); _alpm_chroot_process_output(handle, buf);
} }
return -1; return -1;
} else if(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) { } else if(should_retry(errno)) {
/* nothing read, try again */ /* nothing read, try again */
} else { } else {
/* read error */ /* read error */