aboutsummaryrefslogtreecommitdiff
path: root/src/fs.h
diff options
context:
space:
mode:
authorChun Kuan Lee <ken2812221@gmail.com>2018-07-25 17:33:22 +0800
committerChun Kuan Lee <ken2812221@gmail.com>2018-08-28 00:55:13 +0800
commit1661a472b8245eb4588fedbf19c9ed07a41e7602 (patch)
tree6a9c19af730f79a66e4ba3524dbec5514353cb48 /src/fs.h
parentf180e81d5780805a28bcc71c2bb6b16076336c3c (diff)
downloadbitcoin-1661a472b8245eb4588fedbf19c9ed07a41e7602.tar.xz
add unicode compatible file_lock for Windows
boost::interprocess::file_lock cannot open the files that contain characters which cannot be parsed by the user's code page on Windows. This commit add a new class to handle those specific file for Windows.
Diffstat (limited to 'src/fs.h')
-rw-r--r--src/fs.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/fs.h b/src/fs.h
index abb4be254b..e3ff51604d 100644
--- a/src/fs.h
+++ b/src/fs.h
@@ -19,6 +19,26 @@ namespace fs = boost::filesystem;
namespace fsbridge {
FILE *fopen(const fs::path& p, const char *mode);
FILE *freopen(const fs::path& p, const char *mode, FILE *stream);
+
+ class FileLock
+ {
+ public:
+ FileLock() = delete;
+ FileLock(const FileLock&) = delete;
+ FileLock(FileLock&&) = delete;
+ explicit FileLock(const fs::path& file);
+ ~FileLock();
+ bool TryLock();
+ std::string GetReason() { return reason; }
+
+ private:
+ std::string reason;
+#ifndef WIN32
+ int fd = -1;
+#else
+ void* hFile = (void*)-1; // INVALID_HANDLE_VALUE
+#endif
+ };
};
#endif // BITCOIN_FS_H