flatten 20260225

This commit is contained in:
Timothy Prepscius
2026-02-25 12:39:24 -05:00
commit fa54be052a
315 changed files with 49791 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
// TJP COPYRIGHT HEADER
#include "writeSegmentsToFile.h"
#include <iostream>
#include <fstream>
#include <sys/stat.h>
#include <sys/types.h>
#include <tjp/core/exception/Exception.hpp>
#include <tjp/core/system/System.h>
#include <tjp/core/string/to_string.hpp>
#include "../random/Random.h"
#include <utime.h>
namespace tjp {
namespace core {
namespace file {
bool writeSegmentsToFile(const StringView &path_, const StackArray<containers::MemorySegment<u8>> &segments, const WriteOptions &options)
{
auto path = String(path_);
auto extension = "." + core::to_string(core::StandardRandom.next<u32>());
auto temporary = path + extension;
std::ofstream file(temporary, std::ios::binary);
if (!file)
return false;
for (auto &contents: segments)
file.write((char *)contents.data(), contents.size());
file.close();
remove(path.c_str());
if (rename(temporary.c_str(), path.c_str()))
return false;
if (options.lastModifiedTime)
{
setFileLastModifiedTime(path, options.lastModifiedTime);
}
return true;
}
} // namespace
} // namespace
} // namespace