From df31b88187bc1e262abbeddc63c6cde6331bf07a Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Thu, 10 Dec 2015 11:00:10 +0300 Subject: [PATCH] Fix "unused result" warnings for several system calls. --- src/file.cc | 7 +++++-- src/remote.cc | 3 ++- src/shell_manager.cc | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/file.cc b/src/file.cc index bc9c1cf9..508a7bcc 100644 --- a/src/file.cc +++ b/src/file.cc @@ -100,7 +100,9 @@ String compact_path(StringView filename) String real_filename = real_path(filename); char cwd[1024]; - getcwd(cwd, 1024); + if (!::getcwd(cwd, 1024)) + throw runtime_error(format("unable to get the current working directory (errno: {})", ::strerror(errno))); + String real_cwd = real_path(cwd) + "/"; if (prefix_match(real_filename, real_cwd)) return real_filename.substr(real_cwd.length()).str(); @@ -223,7 +225,8 @@ void write_buffer_to_fd(Buffer& buffer, int fd) eoldata = "\n"; if (buffer.options()["BOM"].get() == ByteOrderMark::Utf8) - ::write(fd, "\xEF\xBB\xBF", 3); + if (::write(fd, "\xEF\xBB\xBF", 3) < 0) + throw runtime_error(format("unable to write data to the buffer (fd: {}; errno: {})", fd, ::strerror(errno))); for (LineCount i = 0; i < buffer.line_count(); ++i) { diff --git a/src/remote.cc b/src/remote.cc index 6169e906..e15d4d0f 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -532,7 +532,8 @@ void RemoteClient::write_next_key() void send_command(StringView session, StringView command) { int sock = connect_to(session); - ::write(sock, command.data(), (int)command.length()); + if (::write(sock, command.data(), (int)command.length()) < 0) + throw runtime_error(format("unable to write data to socket (fd: {}; errno: {})", sock, ::strerror(errno))); close(sock); } diff --git a/src/shell_manager.cc b/src/shell_manager.cc index 2d98298e..d8ae6d78 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -29,7 +29,10 @@ namespace struct Pipe { - Pipe() { ::pipe(m_fd); } + Pipe() { + if (::pipe(m_fd) < 0) + throw runtime_error(format("unable to create pipe (fds: {}/{}; errno: {})", m_fd[0], m_fd[1], ::strerror(errno))); + } ~Pipe() { close_read_fd(); close_write_fd(); } int read_fd() const { return m_fd[0]; }