12#include <sys/utsname.h>
31 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t> utf8_cvt;
32 return ::_wfopen(p.wstring().c_str(), utf8_cvt.from_bytes(mode).c_str());
38 assert(base.is_absolute());
39 return path.empty() ? base :
fs::path(base / path);
51 fd = open(file.c_str(), O_RDWR);
71 lock.l_type = F_WRLCK;
72 lock.l_whence = SEEK_SET;
75 if (fcntl(
fd, F_SETLK, &lock) == -1) {
85 return Win32ErrorString(GetLastError());
90 hFile = CreateFileW(file.wstring().c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
91 nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
nullptr);
92 if (hFile == INVALID_HANDLE_VALUE) {
99 if (hFile != INVALID_HANDLE_VALUE) {
106 if (hFile == INVALID_HANDLE_VALUE) {
109 _OVERLAPPED overlapped = {};
110 if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
124 std::string mb_string(e.what());
125 int size = MultiByteToWideChar(CP_ACP, 0, mb_string.data(), mb_string.size(),
nullptr, 0);
127 std::wstring utf16_string(size, L
'\0');
128 MultiByteToWideChar(CP_ACP, 0, mb_string.data(), mb_string.size(), &*utf16_string.begin(), size);
130 return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t>().to_bytes(utf16_string);
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Bridge operations to C stdio.
FILE * fopen(const fs::path &p, const char *mode)
std::string get_filesystem_error_message(const fs::filesystem_error &e)
fs::path AbsPathJoin(const fs::path &base, const fs::path &path)
Helper function for joining two paths.
static std::string GetErrorReason()
std::string SysErrorString(int err)
Return system error string from errno value.