Changeset View
Changeset View
Standalone View
Standalone View
src/fs.cpp
// Copyright (c) 2017 The Bitcoin Core developers | // Copyright (c) 2017 The Bitcoin Core developers | ||||
// Copyright (c) 2019 The Bitcoin developers | // Copyright (c) 2019 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <fs.h> | #include <fs.h> | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <string> | #include <string> | ||||
#include <sys/file.h> | #include <sys/file.h> | ||||
#include <sys/utsname.h> | #include <sys/utsname.h> | ||||
#else | #else | ||||
#define NOMINMAX | |||||
#include <codecvt> | #include <codecvt> | ||||
#include <windows.h> | #include <windows.h> | ||||
#endif | #endif | ||||
namespace fsbridge { | namespace fsbridge { | ||||
FILE *fopen(const fs::path &p, const char *mode) { | FILE *fopen(const fs::path &p, const char *mode) { | ||||
return ::fopen(p.string().c_str(), mode); | return ::fopen(p.string().c_str(), mode); | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
bool FileLock::TryLock() { | bool FileLock::TryLock() { | ||||
if (hFile == INVALID_HANDLE_VALUE) { | if (hFile == INVALID_HANDLE_VALUE) { | ||||
return false; | return false; | ||||
} | } | ||||
_OVERLAPPED overlapped = {0}; | _OVERLAPPED overlapped = {0}; | ||||
if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, | if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, | ||||
0, 0, 0, &overlapped)) { | 0, std::numeric_limits<DWORD>::max(), | ||||
std::numeric_limits<DWORD>::max(), &overlapped)) { | |||||
reason = GetErrorReason(); | reason = GetErrorReason(); | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
#endif | #endif | ||||
std::string get_filesystem_error_message(const fs::filesystem_error &e) { | std::string get_filesystem_error_message(const fs::filesystem_error &e) { | ||||
▲ Show 20 Lines • Show All 121 Lines • Show Last 20 Lines |