Skip to content

Commit

Permalink
replace custom GetFilesize() with boost::filesystem::file_size()
Browse files Browse the repository at this point in the history
  • Loading branch information
Tranz5 committed Jul 12, 2014
1 parent a1943e2 commit b40c7b4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/db.cpp
Expand Up @@ -564,9 +564,9 @@ bool CAddrDB::Read(CAddrMan& addr)
return error("CAddrman::Read() : open failed"); return error("CAddrman::Read() : open failed");


// use file size to size memory buffer // use file size to size memory buffer
int fileSize = GetFilesize(filein); int fileSize = boost::filesystem::file_size(pathAddr);
int dataSize = fileSize - sizeof(uint256); int dataSize = fileSize - sizeof(uint256);
//Don't try to resize to a negative number if file is small // Don't try to resize to a negative number if file is small
if ( dataSize < 0 ) dataSize = 0; if ( dataSize < 0 ) dataSize = 0;
vector<unsigned char> vchData; vector<unsigned char> vchData;
vchData.resize(dataSize); vchData.resize(dataSize);
Expand Down
19 changes: 1 addition & 18 deletions src/util.cpp
Expand Up @@ -1256,22 +1256,12 @@ void FileCommit(FILE *fileout)


} }


int GetFilesize(FILE* file)
{
int nSavePos = ftell(file);
int nFilesize = -1;
if (fseek(file, 0, SEEK_END) == 0)
nFilesize = ftell(file);
fseek(file, nSavePos, SEEK_SET);
return nFilesize;
}

void ShrinkDebugFile() void ShrinkDebugFile()
{ {
// Scroll debug.log if it's getting too big // Scroll debug.log if it's getting too big
boost::filesystem::path pathLog = GetDataDir() / "debug.log"; boost::filesystem::path pathLog = GetDataDir() / "debug.log";
FILE* file = fopen(pathLog.string().c_str(), "r"); FILE* file = fopen(pathLog.string().c_str(), "r");
if (file && GetFilesize(file) > 10 * 1000000) if (file && boost::filesystem::file_size(pathLog) > 10 * 1000000)
{ {
// Restart the file with some of the end // Restart the file with some of the end
char pch[200000]; char pch[200000];
Expand All @@ -1288,13 +1278,6 @@ void ShrinkDebugFile()
} }
} }









// //
// "Never go to sea with two chronometers; take one or three." // "Never go to sea with two chronometers; take one or three."
// Our three time sources are: // Our three time sources are:
Expand Down
7 changes: 0 additions & 7 deletions src/util.h
Expand Up @@ -133,12 +133,6 @@ inline void Sleep(int64 n)
#endif #endif










extern std::map<std::string, std::string> mapArgs; extern std::map<std::string, std::string> mapArgs;
extern std::map<std::string, std::vector<std::string> > mapMultiArgs; extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
extern bool fDebug; extern bool fDebug;
Expand Down Expand Up @@ -213,7 +207,6 @@ void ParseParameters(int argc, const char*const argv[]);
bool WildcardMatch(const char* psz, const char* mask); bool WildcardMatch(const char* psz, const char* mask);
bool WildcardMatch(const std::string& str, const std::string& mask); bool WildcardMatch(const std::string& str, const std::string& mask);
void FileCommit(FILE *fileout); void FileCommit(FILE *fileout);
int GetFilesize(FILE* file);
bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest); bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest);
boost::filesystem::path GetDefaultDataDir(); boost::filesystem::path GetDefaultDataDir();
const boost::filesystem::path &GetDataDir(bool fNetSpecific = true); const boost::filesystem::path &GetDataDir(bool fNetSpecific = true);
Expand Down

0 comments on commit b40c7b4

Please sign in to comment.