Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use boost::filesystem::resize_file #698

Merged
merged 1 commit into from
Aug 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 1 addition & 26 deletions src/rime/dict/mapped_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,6 @@
#include <boost/interprocess/mapped_region.hpp>
#include <rime/dict/mapped_file.h>

#ifdef BOOST_RESIZE_FILE

#define RESIZE_FILE boost::filesystem::resize_file

#else

#ifdef _WIN32
#include <windows.h>
#define RESIZE_FILE(P, SZ) (resize_file_api(P, SZ) != 0)
static BOOL resize_file_api(const char* p, boost::uintmax_t size) {
HANDLE handle = CreateFileA(p, GENERIC_WRITE, 0, 0, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0);
LARGE_INTEGER sz;
sz.QuadPart = size;
return handle != INVALID_HANDLE_VALUE &&
::SetFilePointerEx(handle, sz, 0, FILE_BEGIN) &&
::SetEndOfFile(handle) && ::CloseHandle(handle);
}
#else
#include <unistd.h>
#define RESIZE_FILE(P, SZ) (::truncate(P, SZ) == 0)
#endif // _WIN32

#endif // BOOST_RESIZE_FILE

namespace rime {

class MappedFileImpl {
Expand Down Expand Up @@ -155,7 +130,7 @@ bool MappedFile::Resize(size_t capacity) {
if (IsOpen())
Close();
try {
RESIZE_FILE(file_name_.c_str(), capacity);
boost::filesystem::resize_file(file_name_.c_str(), capacity);
} catch (...) {
return false;
}
Expand Down