7#include "../telemetry/telemetry.hpp"
8#include "../utility/utility.hpp"
9#include "../macros.hpp"
15hi_export_module(hikogui.file.file_impl);
17hi_export
namespace hi::inline
v1 {
19File::File(std::filesystem::path
const &path, AccessMode accessMode) : accessMode(accessMode), location(location)
23 if (accessMode >= (AccessMode::Read | AccessMode::Write)) {
25 }
else if (accessMode >= AccessMode::Read) {
28 }
else if (accessMode >= AccessMode::Write) {
32 throw io_error(
"{}: Invalid AccessMode; expecting Readable and/or Writeable.", location());
35 if (accessMode >= AccessMode::WriteLock) {
36 openFlags |= O_EXLOCK;
37 }
else if (accessMode >= AccessMode::ReadLock) {
38 openFlags |= O_SHLOCK;
41 if (accessMode >= (AccessMode::Create | AccessMode::Open)) {
43 if (accessMode >= AccessMode::Truncate) {
47 }
else if (accessMode >= AccessMode::Create) {
48 openFlags |= (O_CREAT | O_EXCL);
50 }
else if (accessMode >= AccessMode::Open) {
51 if (accessMode >= AccessMode::Truncate) {
56 throw io_error(
"{}: Invalid AccessMode; expecting CreateFile and/or OpenFile.", location());
72 int permissions = 0666;
74 auto const fileName = location.nativePath();
75 if ((fileHandle = ::open(fileName.data(), openFlags, permissions)) == -1) {
87 if (fileHandle != -1) {
88 if (::close(fileHandle) != 0) {
95std::size_t File::fileSize(std::filesystem::path
const &path)
97 auto const name = url.nativePath();
99 struct ::stat statbuf;
101 if (::stat(name.data(), &statbuf) == -1) {
105 return narrow_cast<std::size_t>(statbuf.st_size);
hi_export std::string get_last_error_message(uint32_t error_code)
Get the error message from an error code.
Definition exception_win32_impl.hpp:21
DOXYGEN BUG.
Definition algorithm_misc.hpp:20