Skip to content

Commit ebb783a

Browse files
committed
Merge pull request #3603
a486abd replace custom GetFilesize() with boost::filesystem::file_size() (Philip Kaufmann)
2 parents 77eaa6f + a486abd commit ebb783a

File tree

3 files changed

+5
-21
lines changed

3 files changed

+5
-21
lines changed

src/net.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include <miniupnpc/upnperrors.h>
2828
#endif
2929

30+
#include <boost/filesystem.hpp>
31+
3032
// Dump addresses to peers.dat every 15 minutes (900s)
3133
#define DUMP_ADDRESSES_INTERVAL 900
3234

@@ -1986,9 +1988,9 @@ bool CAddrDB::Read(CAddrMan& addr)
19861988
return error("CAddrman::Read() : open failed");
19871989

19881990
// use file size to size memory buffer
1989-
int fileSize = GetFilesize(filein);
1991+
int fileSize = boost::filesystem::file_size(pathAddr);
19901992
int dataSize = fileSize - sizeof(uint256);
1991-
//Don't try to resize to a negative number if file is small
1993+
// Don't try to resize to a negative number if file is small
19921994
if ( dataSize < 0 ) dataSize = 0;
19931995
vector<unsigned char> vchData;
19941996
vchData.resize(dataSize);

src/util.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,16 +1107,6 @@ void FileCommit(FILE *fileout)
11071107
#endif
11081108
}
11091109

1110-
int GetFilesize(FILE* file)
1111-
{
1112-
int nSavePos = ftell(file);
1113-
int nFilesize = -1;
1114-
if (fseek(file, 0, SEEK_END) == 0)
1115-
nFilesize = ftell(file);
1116-
fseek(file, nSavePos, SEEK_SET);
1117-
return nFilesize;
1118-
}
1119-
11201110
bool TruncateFile(FILE *file, unsigned int length) {
11211111
#if defined(WIN32)
11221112
return _chsize(_fileno(file), length) == 0;
@@ -1195,7 +1185,7 @@ void ShrinkDebugFile()
11951185
// Scroll debug.log if it's getting too big
11961186
boost::filesystem::path pathLog = GetDataDir() / "debug.log";
11971187
FILE* file = fopen(pathLog.string().c_str(), "r");
1198-
if (file && GetFilesize(file) > 10 * 1000000)
1188+
if (file && boost::filesystem::file_size(pathLog) > 10 * 1000000)
11991189
{
12001190
// Restart the file with some of the end
12011191
char pch[200000];
@@ -1214,13 +1204,6 @@ void ShrinkDebugFile()
12141204
fclose(file);
12151205
}
12161206

1217-
1218-
1219-
1220-
1221-
1222-
1223-
12241207
//
12251208
// "Never go to sea with two chronometers; take one or three."
12261209
// Our three time sources are:

src/util.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ void ParseParameters(int argc, const char*const argv[]);
185185
bool WildcardMatch(const char* psz, const char* mask);
186186
bool WildcardMatch(const std::string& str, const std::string& mask);
187187
void FileCommit(FILE *fileout);
188-
int GetFilesize(FILE* file);
189188
bool TruncateFile(FILE *file, unsigned int length);
190189
int RaiseFileDescriptorLimit(int nMinFD);
191190
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);

0 commit comments

Comments
 (0)