mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-04 09:41:52 +01:00
Add new utility functions FileCommit(), RenameOver()
This commit is contained in:
21
src/util.cpp
21
src/util.cpp
@@ -910,6 +910,27 @@ void CreatePidFile(const boost::filesystem::path &path, pid_t pid)
|
||||
}
|
||||
}
|
||||
|
||||
bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return MoveFileEx(src.string().c_str(), dest.string().c_str(),
|
||||
MOVEFILE_REPLACE_EXISTING);
|
||||
#else
|
||||
int rc = std::rename(src.string().c_str(), dest.string().c_str());
|
||||
return (rc == 0);
|
||||
#endif /* WIN32 */
|
||||
}
|
||||
|
||||
void FileCommit(FILE *fileout)
|
||||
{
|
||||
fflush(fileout); // harmless if redundantly called
|
||||
#ifdef WIN32
|
||||
_commit(_fileno(fileout));
|
||||
#else
|
||||
fsync(fileno(fileout));
|
||||
#endif
|
||||
}
|
||||
|
||||
int GetFilesize(FILE* file)
|
||||
{
|
||||
int nSavePos = ftell(file);
|
||||
|
||||
Reference in New Issue
Block a user