diff options
| author | Jeff Garzik <[email protected]> | 2012-05-12 01:24:27 -0400 |
|---|---|---|
| committer | Jeff Garzik <[email protected]> | 2012-05-16 19:25:25 -0400 |
| commit | 768e5d52fb295b000940f6a806c3d4bfc3e4f54d (patch) | |
| tree | cd0ae64786ceb7c363226fee822dad8ae919dd76 /src/util.cpp | |
| parent | Merge pull request #1319 from Diapolo/add_new_languages (diff) | |
| download | discoin-768e5d52fb295b000940f6a806c3d4bfc3e4f54d.tar.xz discoin-768e5d52fb295b000940f6a806c3d4bfc3e4f54d.zip | |
Add new utility functions FileCommit(), RenameOver()
Diffstat (limited to 'src/util.cpp')
| -rw-r--r-- | src/util.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp index 823d00a4e..82c16feda 100644 --- a/src/util.cpp +++ b/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); |