aboutsummaryrefslogtreecommitdiff
path: root/util.cpp
diff options
context:
space:
mode:
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-01-28 00:31:00 +0000
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-01-28 00:31:00 +0000
commitcb0f89646f065800d38d7cfc10ba1e855563296a (patch)
tree2cef9a44c911d1a80ef48bc74d50e7cc86b512b9 /util.cpp
parent9a36562347122482fd1e6e77c74df66ad8cf2c3f (diff)
downloadbitcoin-cb0f89646f065800d38d7cfc10ba1e855563296a.tar.xz
simplify AddAddress,
readcompactsize limit, fixed a 64-bit compile error in serialize.h, change status "# blocks" to "# confirmations" and widen the column. git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@53 1a98c847-1fd6-4fd8-948a-caf3550aa51b
Diffstat (limited to 'util.cpp')
-rw-r--r--util.cpp77
1 files changed, 76 insertions, 1 deletions
diff --git a/util.cpp b/util.cpp
index f5f2797fec..4292246762 100644
--- a/util.cpp
+++ b/util.cpp
@@ -8,8 +8,8 @@
map<string, string> mapArgs;
map<string, vector<string> > mapMultiArgs;
bool fDebug = false;
-bool fPrintToDebugger = false;
bool fPrintToConsole = false;
+bool fPrintToDebugger = false;
char pszSetDataDir[MAX_PATH] = "";
bool fShutdown = false;
@@ -75,6 +75,8 @@ void RandAddSeed()
void RandAddSeedPerfmon()
{
+ RandAddSeed();
+
// This can take up to 2 seconds, so only do it every 10 minutes
static int64 nLastPerfmon;
if (GetTime() < nLastPerfmon + 10 * 60)
@@ -129,6 +131,79 @@ uint64 GetRand(uint64 nMax)
+inline int OutputDebugStringF(const char* pszFormat, ...)
+{
+ int ret = 0;
+ if (fPrintToConsole || wxTheApp == NULL)
+ {
+ // print to console
+ va_list arg_ptr;
+ va_start(arg_ptr, pszFormat);
+ ret = vprintf(pszFormat, arg_ptr);
+ va_end(arg_ptr);
+ }
+ else
+ {
+ // print to debug.log
+ char pszFile[MAX_PATH+100];
+ GetDataDir(pszFile);
+ strlcat(pszFile, "/debug.log", sizeof(pszFile));
+ FILE* fileout = fopen(pszFile, "a");
+ if (fileout)
+ {
+ //// Debug print useful for profiling
+ //fprintf(fileout, " %"PRI64d" ", wxGetLocalTimeMillis().GetValue());
+ va_list arg_ptr;
+ va_start(arg_ptr, pszFormat);
+ ret = vfprintf(fileout, pszFormat, arg_ptr);
+ va_end(arg_ptr);
+ fclose(fileout);
+ }
+ }
+
+#ifdef __WXMSW__
+ if (fPrintToDebugger)
+ {
+ // accumulate a line at a time
+ static CCriticalSection cs_OutputDebugStringF;
+ CRITICAL_BLOCK(cs_OutputDebugStringF)
+ {
+ static char pszBuffer[50000];
+ static char* pend;
+ if (pend == NULL)
+ pend = pszBuffer;
+ va_list arg_ptr;
+ va_start(arg_ptr, pszFormat);
+ int limit = END(pszBuffer) - pend - 2;
+ int ret = _vsnprintf(pend, limit, pszFormat, arg_ptr);
+ va_end(arg_ptr);
+ if (ret < 0 || ret >= limit)
+ {
+ pend = END(pszBuffer) - 2;
+ *pend++ = '\n';
+ }
+ else
+ pend += ret;
+ *pend = '\0';
+ char* p1 = pszBuffer;
+ char* p2;
+ while (p2 = strchr(p1, '\n'))
+ {
+ p2++;
+ char c = *p2;
+ *p2 = '\0';
+ OutputDebugString(p1);
+ *p2 = c;
+ p1 = p2;
+ }
+ if (p1 != pszBuffer)
+ memmove(pszBuffer, p1, pend - p1 + 1);
+ pend -= (p1 - pszBuffer);
+ }
+ }
+#endif
+ return ret;
+}
// Safer snprintf