Silence unused result warnings on newer compilers

Newer versions of GCC and Clang are not satisfied by a cast to void,
this fix is adapted from glibc's solution.

New wrapper function ignore_result should be used when a function with
explicit _unused_attribute_ wrapper is called whose result will not be
handled.
This commit is contained in:
Mahmoud Al-Qudsi
2017-08-12 09:54:26 -05:00
committed by Kurtis Rader
parent 5356384d0a
commit e6bb7fc973
6 changed files with 25 additions and 12 deletions

View File

@@ -616,14 +616,14 @@ void debug_safe(int level, const char *msg, const char *param1, const char *para
const char *end = strchr(cursor, '%');
if (end == NULL) end = cursor + strlen(cursor);
(void)write(STDERR_FILENO, cursor, end - cursor);
ignore_result(write(STDERR_FILENO, cursor, end - cursor));
if (end[0] == '%' && end[1] == 's') {
// Handle a format string.
assert(param_idx < sizeof params / sizeof *params);
const char *format = params[param_idx++];
if (!format) format = "(null)";
(void)write(STDERR_FILENO, format, strlen(format));
ignore_result(write(STDERR_FILENO, format, strlen(format)));
cursor = end + 2;
} else if (end[0] == '\0') {
// Must be at the end of the string.
@@ -635,7 +635,7 @@ void debug_safe(int level, const char *msg, const char *param1, const char *para
}
// We always append a newline.
(void)write(STDERR_FILENO, "\n", 1);
ignore_result(write(STDERR_FILENO, "\n", 1));
errno = errno_old;
}