diff options
Diffstat (limited to 'source/fud_file.cpp')
-rw-r--r-- | source/fud_file.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/source/fud_file.cpp b/source/fud_file.cpp index ca6404d..7219638 100644 --- a/source/fud_file.cpp +++ b/source/fud_file.cpp @@ -28,6 +28,7 @@ namespace fud { +// NOLINTNEXTLINE(performance-unnecessary-value-param) FileResult RegularFile::open(StringView filename, FileAccessMode mode, OpenFlags flags, Option<int> dirFdOption) { if (!filename.nullTerminated()) { @@ -64,6 +65,8 @@ FileResult RegularFile::open(StringView filename, FileAccessMode mode, OpenFlags openHow.flags = openFlags; openHow.resolve = RESOLVE_NO_SYMLINKS; + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) auto status = syscall(SYS_openat2, dirFd, filename.data(), &openHow, sizeof(openHow)); if (status == -1) { if constexpr (EAGAIN != EWOULDBLOCK && status == EWOULDBLOCK) { @@ -119,6 +122,7 @@ FileResult RegularFile::create( OpenFlags flags, Permissions permissions, bool createOnly, + // NOLINTNEXTLINE(performance-unnecessary-value-param) Option<int> dirFdOption) { if (!filename.nullTerminated()) { @@ -156,6 +160,7 @@ FileResult RegularFile::create( openHow.resolve = RESOLVE_NO_SYMLINKS; openHow.mode = permissions.mode(); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) auto status = syscall(SYS_openat2, dirFd, filename.data(), &openHow, sizeof(openHow)); if (status == -1) { if constexpr (EAGAIN != EWOULDBLOCK && status == EWOULDBLOCK) { @@ -580,6 +585,7 @@ DrainResult BufferedRegularFile::validateBufferedIO(const std::byte* pointer, Op return result; } +// NOLINTNEXTLINE(performance-unnecessary-value-param) DrainResult BufferedRegularFile::write(const std::byte* source, size_t length, Option<size_t> maxExtraAttempts) { DrainResult result{validateBufferedIO(source, Operation::Write)}; @@ -593,10 +599,7 @@ DrainResult BufferedRegularFile::write(const std::byte* source, size_t length, O if (m_bufferLength < m_buffer.size()) { auto cap = m_buffer.size() - m_bufferLength; - size_t count = length; - if (count > cap) { - count = cap; - } + size_t count = fud::min(length, cap); auto copyStatus = copyMem(m_buffer.data() + m_bufferLength, cap, source, count); fudAssert(copyStatus == FudStatus::Success); @@ -641,6 +644,7 @@ DrainResult BufferedRegularFile::write(const std::byte* source, size_t length, O return result; } +// NOLINTNEXTLINE(performance-unnecessary-value-param) DrainResult BufferedRegularFile::read(std::byte* sink, size_t length, Option<size_t> maxExtraAttempts) { auto extraAttempts = maxExtraAttempts.valueOr(0); @@ -693,6 +697,10 @@ DrainResult BufferedRegularFile::read(std::byte* sink, size_t length, Option<siz auto drainResult = m_file.read(m_buffer.data(), m_buffer.size(), extraAttempts); result.status = drainResult.status; if (drainResult.status == FudStatus::Success || drainResult.status == FudStatus::Partial) { + if (drainResult.status == FudStatus::Partial && drainResult.bytesDrained >= length) { + result.status = FudStatus::Success; + } + m_bufferLength = drainResult.bytesDrained; auto count = min(length, m_bufferLength); @@ -704,7 +712,7 @@ DrainResult BufferedRegularFile::read(std::byte* sink, size_t length, Option<siz length -= count; if (drainResult.status == FudStatus::Partial && length == 0) { - drainResult.status = FudStatus::Success; + result.status = FudStatus::Success; } m_bufferPosition = count; @@ -715,10 +723,12 @@ DrainResult BufferedRegularFile::read(std::byte* sink, size_t length, Option<siz } /** \brief Attempt to read one UTF8 sequence. */ +// NOLINTNEXTLINE(performance-unnecessary-value-param) DrainResult BufferedRegularFile::readUtf8(Utf8& sink, Option<size_t> maxExtraAttempts) { size_t extraAttempts{maxExtraAttempts.valueOr(0)}; Array<utf8, 4> utf8Data{}; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) auto drainResult = read(reinterpret_cast<std::byte*>(utf8Data.data()), 1, maxExtraAttempts); if (drainResult.status != FudStatus::Success) { return drainResult; @@ -746,6 +756,7 @@ DrainResult BufferedRegularFile::readUtf8(Utf8& sink, Option<size_t> maxExtraAtt } if (bytesToRead > 0) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) auto utf8ReadResult = read(reinterpret_cast<std::byte*>(utf8Data.data() + 1), bytesToRead, extraAttempts); drainResult.status = utf8ReadResult.status; drainResult.bytesDrained += utf8ReadResult.bytesDrained; @@ -773,6 +784,7 @@ void BufferedRegularFile::drainReadBuffer(std::byte*& sink, size_t& length, Drai } } +// NOLINTNEXTLINE(readability-convert-member-functions-to-static,cppcoreguidelines-rvalue-*) FudStatus BufferedRegularFile::setBuffer(Vector<std::byte>&& buffer, bool discardOldBuffer) { static_cast<void>(buffer); |