Source release 18.1.0

This commit is contained in:
John "Juce" Bruce
2023-06-23 15:45:08 -07:00
parent 2baa7c6e2b
commit b2c35151ad
2074 changed files with 196004 additions and 427059 deletions

View File

@@ -58,6 +58,7 @@ class FileSystem {
virtual std::unique_ptr<File> Open(const std::string& file_path, int flags);
virtual bool Exists(const std::string& file_path);
virtual bool Exists(const std::string& file_path, int* errno_value);
virtual bool Remove(const std::string& file_path);
virtual ssize_t FileSize(const std::string& file_path);

View File

@@ -13,6 +13,11 @@ namespace wvutil {
#endif
bool FormatString(std::string* out, const char* fmt, ...);
#ifdef __GNUC__
[[gnu::format(printf, 2, 0)]]
#endif
bool VFormatString(std::string* out, const char* fmt, va_list vlist);
} // namespace wvutil
#endif // WVCDM_UTIL_STRING_FORMAT_H_

View File

@@ -16,20 +16,27 @@ namespace wvutil {
bool FormatString(std::string* out, const char* fmt, ...) {
if (out == nullptr || fmt == nullptr) return false;
va_list ap1;
va_start(ap1, fmt);
const int desired_size = vsnprintf(nullptr, 0, fmt, ap1);
va_end(ap1);
va_list vlist;
va_start(vlist, fmt);
const bool result = VFormatString(out, fmt, vlist);
va_end(vlist);
return result;
}
bool VFormatString(std::string* out, const char* fmt, va_list vlist) {
if (out == nullptr || fmt == nullptr) return false;
va_list vlist_copy;
va_copy(vlist_copy, vlist);
const int desired_size = vsnprintf(nullptr, 0, fmt, vlist_copy);
va_end(vlist_copy);
if (desired_size < 0) return false;
const size_t buffer_size =
static_cast<size_t>(desired_size) + 1; // +1 for null
std::unique_ptr<char[]> buffer(new char[buffer_size]);
va_list ap2;
va_start(ap2, fmt);
const int actual_size = vsnprintf(buffer.get(), buffer_size, fmt, ap2);
va_end(ap2);
const int actual_size = vsnprintf(buffer.get(), buffer_size, fmt, vlist);
if (actual_size != desired_size) return false;

View File

@@ -39,9 +39,17 @@ class FileTest : public testing::Test {
};
TEST_F(FileTest, FileExists) {
int errno_value = -1;
EXPECT_TRUE(file_system_.Exists(wvcdm::test_vectors::kExistentFile));
EXPECT_TRUE(
file_system_.Exists(wvcdm::test_vectors::kExistentFile, &errno_value));
EXPECT_EQ(0, errno_value);
EXPECT_TRUE(file_system_.Exists(wvcdm::test_vectors::kExistentDir));
EXPECT_FALSE(file_system_.Exists(wvcdm::test_vectors::kNonExistentFile));
EXPECT_FALSE(
file_system_.Exists(wvcdm::test_vectors::kNonExistentFile, &errno_value));
EXPECT_EQ(ENOENT, errno_value);
EXPECT_FALSE(file_system_.Exists(wvcdm::test_vectors::kNonExistentDir));
}