From 87071200872c2450c947047350132aee493033c1 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Thu, 2 Jan 2025 15:11:51 -0600 Subject: Get basic CSV parser operating. --- test/test_common.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'test/test_common.cpp') diff --git a/test/test_common.cpp b/test/test_common.cpp index 07a0088..f272dad 100644 --- a/test/test_common.cpp +++ b/test/test_common.cpp @@ -74,7 +74,7 @@ int unlink_cb(const char* fpath, const struct stat* sb_unused, int typeflag, str return retValue; } -FudStatus removeRecursive(const String& path) +FudStatus removeRecursive(StringView path) { if (!path.utf8Valid()) { return FudStatus::Utf8Invalid; @@ -82,6 +82,9 @@ FudStatus removeRecursive(const String& path) if (path.length() < 5) { return FudStatus::ArgumentInvalid; } + if (not path.nullTerminated()) { + return FudStatus::StringInvalid; + } auto prefix{String::makeFromCString("/tmp/").takeOkay()}; auto diffResult = compareMem(path.data(), path.length(), prefix.data(), prefix.length()); if (diffResult.isError()) { @@ -92,7 +95,8 @@ FudStatus removeRecursive(const String& path) return FudStatus::ArgumentInvalid; } constexpr int maxOpenFd = 64; - auto status = nftw(path.c_str(), unlink_cb, maxOpenFd, FTW_DEPTH | FTW_PHYS); + + auto status = nftw(reinterpret_cast(path.data()), unlink_cb, maxOpenFd, FTW_DEPTH | FTW_PHYS); if (status == 0) { return FudStatus::Success; } @@ -104,4 +108,15 @@ FudStatus removeRecursive(const String& path) return FudStatus::Failure; } +auto rmFile(StringView filename) -> int +{ + auto result = unlink(filename.c_str()); + if (result == -1) { + if (errno == ENOENT) { + return 0; + } + } + return result; +} + } // namespace fud -- cgit v1.2.3