From fc4a579d83aece58d9630db5a54955a997aca578 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Nov 2024 08:49:29 +0100 Subject: [PATCH] io/FileDescriptor: remove Read()/Write() with void pointers Obsolete and unsafe. --- src/io/FileDescriptor.cxx | 4 ++-- src/io/FileDescriptor.hxx | 10 ---------- src/io/FileOutputStream.cxx | 2 +- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/io/FileDescriptor.cxx b/src/io/FileDescriptor.cxx index 08c38ca6c..5d326b1a0 100644 --- a/src/io/FileDescriptor.cxx +++ b/src/io/FileDescriptor.cxx @@ -267,7 +267,7 @@ void FileDescriptor::FullRead(std::span dest) const { while (!dest.empty()) { - ssize_t nbytes = Read(dest.data(), dest.size()); + ssize_t nbytes = Read(dest); if (nbytes <= 0) { if (nbytes < 0) throw MakeErrno("Failed to read"); @@ -282,7 +282,7 @@ void FileDescriptor::FullWrite(std::span src) const { while (!src.empty()) { - ssize_t nbytes = Write(src.data(), src.size()); + ssize_t nbytes = Write(src); if (nbytes <= 0) { if (nbytes < 0) throw MakeErrno("Failed to write"); diff --git a/src/io/FileDescriptor.hxx b/src/io/FileDescriptor.hxx index c132a4e9c..458cd8168 100644 --- a/src/io/FileDescriptor.hxx +++ b/src/io/FileDescriptor.hxx @@ -246,11 +246,6 @@ public: return ::read(fd, dest.data(), dest.size()); } - [[nodiscard]] - ssize_t Read(void *buffer, std::size_t length) const noexcept { - return ::read(fd, buffer, length); - } - /** * Read until all of the given buffer has been filled. Throws * on error. @@ -269,11 +264,6 @@ public: return ::write(fd, src.data(), src.size()); } - [[nodiscard]] - ssize_t Write(const void *buffer, std::size_t length) const noexcept { - return ::write(fd, buffer, length); - } - /** * Write until all of the given buffer has been written. * Throws on error. diff --git a/src/io/FileOutputStream.cxx b/src/io/FileOutputStream.cxx index d6df7985b..88386488f 100644 --- a/src/io/FileOutputStream.cxx +++ b/src/io/FileOutputStream.cxx @@ -250,7 +250,7 @@ FileOutputStream::Write(std::span src) { assert(IsDefined()); - ssize_t nbytes = fd.Write(src.data(), src.size()); + ssize_t nbytes = fd.Write(src); if (nbytes < 0) throw FmtErrno("Failed to write to {}", GetPath()); else if ((size_t)nbytes < src.size())