buffer += vstrprintf(pszFormat, arg_ptr);
va_end(arg_ptr);
- int line_start = 0, line_end;
+ size_t line_start = 0, line_end;
while((line_end = buffer.find('\n', line_start)) != -1)
{
OutputDebugStringA(buffer.substr(line_start, line_end - line_start).c_str());
if (p != buffer)
delete[] p;
limit *= 2;
- p = new char[limit];
+ p = new(nothrow) char[limit];
if (p == NULL)
throw std::bad_alloc();
}
// Right-trim excess zeros before the decimal point:
int nTrim = 0;
- for (int i = str.size()-1; (str[i] == '0' && isdigit(str[i-2])); --i)
+ for (size_t i = str.size()-1; (str[i] == '0' && isdigit(str[i-2])); --i)
++nTrim;
if (nTrim)
str.erase(str.size()-nTrim, nTrim);
return nDefault;
}
+int32_t GetArgInt(const std::string& strArg, int32_t nDefault)
+{
+ if (mapArgs.count(strArg))
+ return strtol(mapArgs[strArg]);
+ return nDefault;
+}
+
+uint32_t GetArgUInt(const std::string& strArg, uint32_t nDefault)
+{
+ if (mapArgs.count(strArg))
+ return strtoul(mapArgs[strArg]);
+ return nDefault;
+}
+
bool GetBoolArg(const std::string& strArg, bool fDefault)
{
if (mapArgs.count(strArg))
// Restart the file with some of the end
char pch[200000];
fseek(file, -((long long)sizeof(pch)), SEEK_END);
- int nBytes = fread(pch, 1, sizeof(pch), file);
+ size_t nBytes = fread(pch, 1, sizeof(pch), file);
fclose(file);
file = fopen(pathLog.string().c_str(), "w");
static int64_t nNodesOffset = INT64_MAX;
// Select time offset:
-//
-// * If NTP and system clock are in agreement within 40 minutes, then use NTP.
-// * If not, then choose between median peer time and system clock using the same condition.
int64_t GetTimeOffset()
{
+ // If NTP and system clock are in agreement within 40 minutes, then use NTP.
if (abs64(nNtpOffset) < 40 * 60)
return nNtpOffset;
- if (abs64(nNodesOffset) < 40 * 60)
+ // If not, then choose between median peer time and system clock.
+ if (abs64(nNodesOffset) < 70 * 60)
return nNodesOffset;
return 0;
}
+int64_t GetNodesOffset()
+{
+ return nNodesOffset;
+}
+
int64_t GetAdjustedTime()
{
return GetTime() + GetTimeOffset();