Fixed a bunch of clang-tidy warnings.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include "../detect.hpp"
|
||||
#include "../util/iterators.hpp"
|
||||
#include "../debug/assert.hpp"
|
||||
#include "../util/string.hpp"
|
||||
|
||||
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX || MIJIN_TARGET_OS == MIJIN_OS_OSX
|
||||
@@ -34,10 +34,10 @@ StreamError ProcessStream::open(const char* command, FileOpenMode mode_)
|
||||
modeStr = "rw";
|
||||
break;
|
||||
default:
|
||||
assert(!"Unsupported mode for ProcessStream::open()");
|
||||
MIJIN_ERROR("Unsupported mode for ProcessStream::open()");
|
||||
return StreamError::NOT_SUPPORTED;
|
||||
}
|
||||
handle = popen(command, modeStr); // NOLINT(cppcoreguidelines-owning-memory)
|
||||
handle = popen(command, modeStr); // NOLINT(cppcoreguidelines-owning-memory,cert-env33-c)
|
||||
if (!handle) {
|
||||
return StreamError::IO_ERROR;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ StreamError ProcessStream::open(const char* command, FileOpenMode mode_)
|
||||
|
||||
int ProcessStream::close()
|
||||
{
|
||||
assert(handle);
|
||||
MIJIN_ASSERT(handle != nullptr, "Process stream has not been opened.");
|
||||
const int result = pclose(handle);
|
||||
handle = nullptr;
|
||||
return result;
|
||||
@@ -55,10 +55,10 @@ int ProcessStream::close()
|
||||
|
||||
StreamError ProcessStream::readRaw(std::span<std::uint8_t> buffer, const ReadOptions& options, std::size_t* outBytesRead)
|
||||
{
|
||||
assert(handle);
|
||||
assert(mode == FileOpenMode::READ || mode == FileOpenMode::READ_WRITE);
|
||||
MIJIN_ASSERT(handle != nullptr, "Process stream has not been openend.");
|
||||
MIJIN_ASSERT(mode == FileOpenMode::READ || mode == FileOpenMode::READ_WRITE, "Cannot read from this process stream.");
|
||||
|
||||
if (bufferedChar >= 0 && buffer.size() > 0)
|
||||
if (bufferedChar >= 0 && !buffer.empty())
|
||||
{
|
||||
buffer[0] = static_cast<std::uint8_t>(bufferedChar);
|
||||
}
|
||||
@@ -80,8 +80,8 @@ StreamError ProcessStream::readRaw(std::span<std::uint8_t> buffer, const ReadOpt
|
||||
|
||||
StreamError ProcessStream::writeRaw(std::span<const std::uint8_t> buffer)
|
||||
{
|
||||
assert(handle);
|
||||
assert(mode == FileOpenMode::WRITE || mode == FileOpenMode::READ_WRITE);
|
||||
MIJIN_ASSERT(handle != nullptr, "Process stream has not been opened.");
|
||||
MIJIN_ASSERT(mode == FileOpenMode::WRITE || mode == FileOpenMode::READ_WRITE, "Cannot write to this process stream.");
|
||||
|
||||
const std::size_t written = std::fwrite(buffer.data(), 1, buffer.size(), handle);
|
||||
if (written != buffer.size() || std::ferror(handle)) {
|
||||
@@ -93,7 +93,7 @@ StreamError ProcessStream::writeRaw(std::span<const std::uint8_t> buffer)
|
||||
|
||||
std::size_t ProcessStream::tell()
|
||||
{
|
||||
assert(handle);
|
||||
MIJIN_ASSERT(handle != nullptr, "Process stream has not been opened.");
|
||||
|
||||
return std::ftell(handle); // TODO: does this work?
|
||||
}
|
||||
@@ -108,22 +108,19 @@ StreamError ProcessStream::seek(std::intptr_t pos, SeekMode seekMode)
|
||||
void ProcessStream::flush()
|
||||
{
|
||||
const int result = std::fflush(handle);
|
||||
assert(result == 0);
|
||||
MIJIN_ASSERT(result == 0, "Error flushing process stream.");
|
||||
}
|
||||
|
||||
bool ProcessStream::isAtEnd()
|
||||
{
|
||||
assert(handle);
|
||||
MIJIN_ASSERT(handle != nullptr, "Process stream has not been opened.");
|
||||
|
||||
if (bufferedChar >= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bufferedChar = std::fgetc(handle);
|
||||
if (std::feof(handle)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return static_cast<bool>(std::feof(handle));
|
||||
}
|
||||
|
||||
StreamFeatures ProcessStream::getFeatures()
|
||||
@@ -161,6 +158,7 @@ std::string shellEscape(const std::string& arg) noexcept
|
||||
case '$':
|
||||
oss << '\\';
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
oss << chr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user