Using write_ignore instead of write where the result is not checked

This silences warnings from the compiler about ignoring return value of
‘ssize_t write(int, const void*, size_t)’, declared with attribute
warn_unused_result [-Wunused-result].
This commit is contained in:
Mahmoud Al-Qudsi 2017-07-25 23:34:22 -05:00 committed by Kurtis Rader
parent a1c4475c0d
commit 7a18c37b39
6 changed files with 12 additions and 26 deletions

View File

@ -598,16 +598,6 @@ void __attribute__((noinline)) debug(int level, const char *msg, ...) {
errno = errno_old;
}
void read_ignore(int fd, void *buff, size_t count) {
size_t ignore __attribute__((unused));
ignore = read(fd, buff, count);
}
void write_ignore(int fd, const void *buff, size_t count) {
size_t ignore __attribute__((unused));
ignore = write(fd, buff, count);
}
void debug_safe(int level, const char *msg, const char *param1, const char *param2,
const char *param3, const char *param4, const char *param5, const char *param6,
const char *param7, const char *param8, const char *param9, const char *param10,
@ -626,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);
write_ignore(STDERR_FILENO, cursor, end - cursor);
(void)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)";
write_ignore(STDERR_FILENO, format, strlen(format));
(void)write(STDERR_FILENO, format, strlen(format));
cursor = end + 2;
} else if (end[0] == '\0') {
// Must be at the end of the string.
@ -645,7 +635,7 @@ void debug_safe(int level, const char *msg, const char *param1, const char *para
}
// We always append a newline.
write_ignore(STDERR_FILENO, "\n", 1);
(void)write(STDERR_FILENO, "\n", 1);
errno = errno_old;
}

View File

@ -179,10 +179,6 @@ extern bool g_profiling_active;
/// Name of the current program. Should be set at startup. Used by the debug function.
extern const wchar_t *program_name;
// Variants of read() and write() that ignores return values, defeating a warning.
void read_ignore(int fd, void *buff, size_t count);
void write_ignore(int fd, const void *buff, size_t count);
/// Set to false at run-time if it's been determined we can't trust the last modified timestamp on
/// the tty.
extern bool has_working_tty_timestamps;
@ -207,7 +203,7 @@ extern bool has_working_tty_timestamps;
{ \
char exit_read_buff; \
show_stackframe(L'E'); \
read_ignore(0, &exit_read_buff, 1); \
(void)read(0, &exit_read_buff, 1); \
exit_without_destructors(1); \
}

View File

@ -1209,7 +1209,7 @@ class universal_notifier_named_pipe_t : public universal_notifier_t {
// would cause us to hang!
size_t read_amt = 64 * 1024;
void *buff = malloc(read_amt);
read_ignore(this->pipe_fd, buff, read_amt);
(void)read(this->pipe_fd, buff, read_amt);
free(buff);
}
@ -1308,7 +1308,7 @@ class universal_notifier_named_pipe_t : public universal_notifier_t {
while (this->readback_amount > 0) {
char buff[64];
size_t amt_to_read = mini(this->readback_amount, sizeof buff);
read_ignore(this->pipe_fd, buff, amt_to_read);
(void)read(this->pipe_fd, buff, amt_to_read);
this->readback_amount -= amt_to_read;
}
assert(this->readback_amount == 0);

View File

@ -275,7 +275,7 @@ static void maybe_issue_path_warning(const wcstring &which_dir, const wcstring &
debug(0, _(L"The error was '%s'."), strerror(saved_errno));
debug(0, _(L"Please set $%ls to a directory where you have write access."), env_var);
}
write(STDERR_FILENO, "\n", 1);
(void)write(STDERR_FILENO, "\n", 1);
}
static void path_create(wcstring &path, const wcstring &xdg_var, const wcstring &which_dir,

View File

@ -696,14 +696,14 @@ void reader_write_title(const wcstring &cmd, bool reset_cursor_position) {
for (size_t i = 0; i < lst.size(); i++) {
fputws(lst.at(i).c_str(), stdout);
}
write(STDOUT_FILENO, "\a", 1);
(void)write(STDOUT_FILENO, "\a", 1);
}
proc_pop_interactive();
set_color(rgb_color_t::reset(), rgb_color_t::reset());
if (reset_cursor_position && !lst.empty()) {
// Put the cursor back at the beginning of the line (issue #2453).
write(STDOUT_FILENO, "\r", 1);
(void)write(STDOUT_FILENO, "\r", 1);
}
}
@ -1291,7 +1291,7 @@ static void reader_flash() {
}
reader_repaint();
write(STDOUT_FILENO, "\a", 1);
(void)write(STDOUT_FILENO, "\a", 1);
pollint.tv_sec = 0;
pollint.tv_nsec = 100 * 1000000;
@ -3229,7 +3229,7 @@ const wchar_t *reader_readline(int nchars) {
reader_repaint_if_needed();
}
write(STDOUT_FILENO, "\n", 1);
(void)write(STDOUT_FILENO, "\n", 1);
// Ensure we have no pager contents when we exit.
if (!data->pager.empty()) {

View File

@ -338,7 +338,7 @@ void safe_perror(const char *message) {
safe_append(buff, safe_strerror(err), sizeof buff);
safe_append(buff, "\n", sizeof buff);
write_ignore(STDERR_FILENO, buff, strlen(buff));
(void)write(STDERR_FILENO, buff, strlen(buff));
errno = err;
}