Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
util.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef BITCOIN_UTIL_H
6 #define BITCOIN_UTIL_H
7 
8 #include "uint256.h"
9 
10 #include <stdarg.h>
11 
12 #ifndef WIN32
13 #include <sys/types.h>
14 #include <sys/time.h>
15 #include <sys/resource.h>
16 #endif
17 #include <map>
18 #include <list>
19 #include <utility>
20 #include <vector>
21 #include <string>
22 
23 #include <boost/version.hpp>
24 #include <boost/thread.hpp>
25 #include <boost/filesystem.hpp>
26 #include <boost/filesystem/path.hpp>
27 #include <boost/date_time/gregorian/gregorian_types.hpp>
28 #include <boost/date_time/posix_time/posix_time_types.hpp>
29 
30 #include "netbase.h" // for AddTimeData
31 
32 typedef long long int64;
33 typedef unsigned long long uint64;
34 
35 static const int64 COIN = 100000000;
36 static const int64 CENT = 1000000;
37 
38 #define loop for (;;)
39 #define BEGIN(a) ((char*)&(a))
40 #define END(a) ((char*)&((&(a))[1]))
41 #define UBEGIN(a) ((unsigned char*)&(a))
42 #define UEND(a) ((unsigned char*)&((&(a))[1]))
43 #define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0]))
44 
45 #ifndef PRI64d
46 #if defined(_MSC_VER) || defined(__MSVCRT__)
47 #define PRI64d "I64d"
48 #define PRI64u "I64u"
49 #define PRI64x "I64x"
50 #else
51 #define PRI64d "lld"
52 #define PRI64u "llu"
53 #define PRI64x "llx"
54 #endif
55 #endif
56 
57 /* Format characters for (s)size_t and ptrdiff_t */
58 #if defined(_MSC_VER) || defined(__MSVCRT__)
59  /* (s)size_t and ptrdiff_t have the same size specifier in MSVC:
60  http://msdn.microsoft.com/en-us/library/tcxf1dw6%28v=vs.100%29.aspx
61  */
62  #define PRIszx "Ix"
63  #define PRIszu "Iu"
64  #define PRIszd "Id"
65  #define PRIpdx "Ix"
66  #define PRIpdu "Iu"
67  #define PRIpdd "Id"
68 #else /* C99 standard */
69  #define PRIszx "zx"
70  #define PRIszu "zu"
71  #define PRIszd "zd"
72  #define PRIpdx "tx"
73  #define PRIpdu "tu"
74  #define PRIpdd "td"
75 #endif
76 
77 // This is needed because the foreach macro can't get over the comma in pair<t1, t2>
78 #define PAIRTYPE(t1, t2) std::pair<t1, t2>
79 
80 // Align by increasing pointer, must have extra space at end of buffer
81 template <size_t nBytes, typename T>
82 T* alignup(T* p)
83 {
84  union
85  {
86  T* ptr;
87  size_t n;
88  } u;
89  u.ptr = p;
90  u.n = (u.n + (nBytes-1)) & ~(nBytes-1);
91  return u.ptr;
92 }
93 
94 #ifdef WIN32
95 #define MSG_NOSIGNAL 0
96 #define MSG_DONTWAIT 0
97 
98 #ifndef S_IRUSR
99 #define S_IRUSR 0400
100 #define S_IWUSR 0200
101 #endif
102 #else
103 #define MAX_PATH 1024
104 #endif
105 
106 inline void MilliSleep(int64 n)
107 {
108 // Boost's sleep_for was uninterruptable when backed by nanosleep from 1.50
109 // until fixed in 1.52. Use the deprecated sleep method for the broken case.
110 // See: https://svn.boost.org/trac/boost/ticket/7238
111 
112 #if BOOST_VERSION >= 105000 && (!defined(BOOST_HAS_NANOSLEEP) || BOOST_VERSION >= 105200)
113  boost::this_thread::sleep_for(boost::chrono::milliseconds(n));
114 #else
115  boost::this_thread::sleep(boost::posix_time::milliseconds(n));
116 #endif
117 }
118 
119 /* This GNU C extension enables the compiler to check the format string against the parameters provided.
120  * X is the number of the "format string" parameter, and Y is the number of the first variadic parameter.
121  * Parameters count from 1.
122  */
123 #ifdef __GNUC__
124 #define ATTR_WARN_PRINTF(X,Y) __attribute__((format(printf,X,Y)))
125 #else
126 #define ATTR_WARN_PRINTF(X,Y)
127 #endif
128 
129 
130 
131 
132 
133 
134 
135 
136 extern std::map<std::string, std::string> mapArgs;
137 extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
138 extern bool fDebug;
139 extern bool fDebugNet;
140 extern bool fPrintToConsole;
141 extern bool fPrintToDebugger;
142 extern bool fDaemon;
143 extern bool fServer;
144 extern bool fCommandLine;
145 extern std::string strMiscWarning;
146 extern bool fTestNet;
147 extern bool fBloomFilters;
148 extern bool fNoListen;
149 extern bool fLogTimestamps;
150 extern volatile bool fReopenDebugLog;
151 
152 void RandAddSeed();
153 void RandAddSeedPerfmon();
154 int ATTR_WARN_PRINTF(1,2) OutputDebugStringF(const char* pszFormat, ...);
155 
156 /*
157  Rationale for the real_strprintf / strprintf construction:
158  It is not allowed to use va_start with a pass-by-reference argument.
159  (C++ standard, 18.7, paragraph 3). Use a dummy argument to work around this, and use a
160  macro to keep similar semantics.
161 */
162 
164 std::string ATTR_WARN_PRINTF(1,3) real_strprintf(const char *format, int dummy, ...);
168 std::string real_strprintf(const std::string &format, int dummy, ...);
169 #define strprintf(format, ...) real_strprintf(format, 0, __VA_ARGS__)
170 std::string vstrprintf(const char *format, va_list ap);
171 
172 bool ATTR_WARN_PRINTF(1,2) error(const char *format, ...);
173 
174 /* Redefine printf so that it directs output to debug.log
175  *
176  * Do this *after* defining the other printf-like functions, because otherwise the
177  * __attribute__((format(printf,X,Y))) gets expanded to __attribute__((format(OutputDebugStringF,X,Y)))
178  * which confuses gcc.
179  */
180 #define printf OutputDebugStringF
181 
182 void LogException(std::exception* pex, const char* pszThread);
183 void PrintException(std::exception* pex, const char* pszThread);
184 void PrintExceptionContinue(std::exception* pex, const char* pszThread);
185 void ParseString(const std::string& str, char c, std::vector<std::string>& v);
186 std::string FormatMoney(int64 n, bool fPlus=false);
187 bool ParseMoney(const std::string& str, int64& nRet);
188 bool ParseMoney(const char* pszIn, int64& nRet);
189 std::string SanitizeString(const std::string& str);
190 std::vector<unsigned char> ParseHex(const char* psz);
191 std::vector<unsigned char> ParseHex(const std::string& str);
192 bool IsHex(const std::string& str);
193 std::vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid = NULL);
194 std::string DecodeBase64(const std::string& str);
195 std::string EncodeBase64(const unsigned char* pch, size_t len);
196 std::string EncodeBase64(const std::string& str);
197 std::vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid = NULL);
198 std::string DecodeBase32(const std::string& str);
199 std::string EncodeBase32(const unsigned char* pch, size_t len);
200 std::string EncodeBase32(const std::string& str);
201 void ParseParameters(int argc, const char*const argv[]);
202 bool WildcardMatch(const char* psz, const char* mask);
203 bool WildcardMatch(const std::string& str, const std::string& mask);
204 void FileCommit(FILE *fileout);
205 int GetFilesize(FILE* file);
206 bool TruncateFile(FILE *file, unsigned int length);
207 int RaiseFileDescriptorLimit(int nMinFD);
208 void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);
209 bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest);
210 boost::filesystem::path GetDefaultDataDir();
211 const boost::filesystem::path &GetDataDir(bool fNetSpecific = true);
212 boost::filesystem::path GetConfigFile();
213 boost::filesystem::path GetPidFile();
214 #ifndef WIN32
215 void CreatePidFile(const boost::filesystem::path &path, pid_t pid);
216 #endif
217 void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet, std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet);
218 #ifdef WIN32
219 boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
220 #endif
221 boost::filesystem::path GetTempPath();
222 void ShrinkDebugFile();
223 int GetRandInt(int nMax);
224 uint64 GetRand(uint64 nMax);
226 int64 GetTime();
227 void SetMockTime(int64 nMockTimeIn);
230 std::string FormatFullVersion();
231 std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
232 void AddTimeData(const CNetAddr& ip, int64 nTime);
233 void runCommand(std::string strCommand);
234 
235 
236 
237 
238 
239 
240 
241 
242 
243 inline std::string i64tostr(int64 n)
244 {
245  return strprintf("%"PRI64d, n);
246 }
247 
248 inline std::string itostr(int n)
249 {
250  return strprintf("%d", n);
251 }
252 
253 inline int64 atoi64(const char* psz)
254 {
255 #ifdef _MSC_VER
256  return _atoi64(psz);
257 #else
258  return strtoll(psz, NULL, 10);
259 #endif
260 }
261 
262 inline int64 atoi64(const std::string& str)
263 {
264 #ifdef _MSC_VER
265  return _atoi64(str.c_str());
266 #else
267  return strtoll(str.c_str(), NULL, 10);
268 #endif
269 }
270 
271 inline int atoi(const std::string& str)
272 {
273  return atoi(str.c_str());
274 }
275 
276 inline int roundint(double d)
277 {
278  return (int)(d > 0 ? d + 0.5 : d - 0.5);
279 }
280 
281 inline int64 roundint64(double d)
282 {
283  return (int64)(d > 0 ? d + 0.5 : d - 0.5);
284 }
285 
286 inline int64 abs64(int64 n)
287 {
288  return (n >= 0 ? n : -n);
289 }
290 
291 template<typename T>
292 std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
293 {
294  std::string rv;
295  static const char hexmap[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
296  '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
297  rv.reserve((itend-itbegin)*3);
298  for(T it = itbegin; it < itend; ++it)
299  {
300  unsigned char val = (unsigned char)(*it);
301  if(fSpaces && it != itbegin)
302  rv.push_back(' ');
303  rv.push_back(hexmap[val>>4]);
304  rv.push_back(hexmap[val&15]);
305  }
306 
307  return rv;
308 }
309 
310 template<typename T>
311 inline std::string HexStr(const T& vch, bool fSpaces=false)
312 {
313  return HexStr(vch.begin(), vch.end(), fSpaces);
314 }
315 
316 template<typename T>
317 void PrintHex(const T pbegin, const T pend, const char* pszFormat="%s", bool fSpaces=true)
318 {
319  printf(pszFormat, HexStr(pbegin, pend, fSpaces).c_str());
320 }
321 
322 inline void PrintHex(const std::vector<unsigned char>& vch, const char* pszFormat="%s", bool fSpaces=true)
323 {
324  printf(pszFormat, HexStr(vch, fSpaces).c_str());
325 }
326 
328 {
329  int64 nCounter = 0;
330 #ifdef WIN32
331  QueryPerformanceCounter((LARGE_INTEGER*)&nCounter);
332 #else
333  timeval t;
334  gettimeofday(&t, NULL);
335  nCounter = (int64) t.tv_sec * 1000000 + t.tv_usec;
336 #endif
337  return nCounter;
338 }
339 
341 {
342  return (boost::posix_time::ptime(boost::posix_time::microsec_clock::universal_time()) -
343  boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_milliseconds();
344 }
345 
347 {
348  return (boost::posix_time::ptime(boost::posix_time::microsec_clock::universal_time()) -
349  boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds();
350 }
351 
352 inline std::string DateTimeStrFormat(const char* pszFormat, int64 nTime)
353 {
354  time_t n = nTime;
355  struct tm* ptmTime = gmtime(&n);
356  char pszTime[200];
357  strftime(pszTime, sizeof(pszTime), pszFormat, ptmTime);
358  return pszTime;
359 }
360 
361 template<typename T>
362 void skipspaces(T& it)
363 {
364  while (isspace(*it))
365  ++it;
366 }
367 
368 inline bool IsSwitchChar(char c)
369 {
370 #ifdef WIN32
371  return c == '-' || c == '/';
372 #else
373  return c == '-';
374 #endif
375 }
376 
384 std::string GetArg(const std::string& strArg, const std::string& strDefault);
385 
393 int64 GetArg(const std::string& strArg, int64 nDefault);
394 
402 bool GetBoolArg(const std::string& strArg, bool fDefault=false);
403 
411 bool SoftSetArg(const std::string& strArg, const std::string& strValue);
412 
420 bool SoftSetBoolArg(const std::string& strArg, bool fValue);
421 
431 static inline uint32_t insecure_rand(void)
432 {
433  insecure_rand_Rz = 36969 * (insecure_rand_Rz & 65535) + (insecure_rand_Rz >> 16);
434  insecure_rand_Rw = 18000 * (insecure_rand_Rw & 65535) + (insecure_rand_Rw >> 16);
435  return (insecure_rand_Rw << 16) + insecure_rand_Rz;
436 }
437 
442 void seed_insecure_rand(bool fDeterministic=false);
443 
449 template <typename T>
450 bool TimingResistantEqual(const T& a, const T& b)
451 {
452  if (b.size() == 0) return a.size() == 0;
453  size_t accumulator = a.size() ^ b.size();
454  for (size_t i = 0; i < a.size(); i++)
455  accumulator |= a[i] ^ b[i%b.size()];
456  return accumulator == 0;
457 }
458 
462 template <typename T> class CMedianFilter
463 {
464 private:
465  std::vector<T> vValues;
466  std::vector<T> vSorted;
467  unsigned int nSize;
468 public:
469  CMedianFilter(unsigned int size, T initial_value):
470  nSize(size)
471  {
472  vValues.reserve(size);
473  vValues.push_back(initial_value);
474  vSorted = vValues;
475  }
476 
477  void input(T value)
478  {
479  if(vValues.size() == nSize)
480  {
481  vValues.erase(vValues.begin());
482  }
483  vValues.push_back(value);
484 
485  vSorted.resize(vValues.size());
486  std::copy(vValues.begin(), vValues.end(), vSorted.begin());
487  std::sort(vSorted.begin(), vSorted.end());
488  }
489 
490  T median() const
491  {
492  int size = vSorted.size();
493  assert(size>0);
494  if(size & 1) // Odd number of elements
495  {
496  return vSorted[size/2];
497  }
498  else // Even number of elements
499  {
500  return (vSorted[size/2-1] + vSorted[size/2]) / 2;
501  }
502  }
503 
504  int size() const
505  {
506  return vValues.size();
507  }
508 
509  std::vector<T> sorted () const
510  {
511  return vSorted;
512  }
513 };
514 
515 bool NewThread(void(*pfn)(void*), void* parg);
516 
517 #ifdef WIN32
518 inline void SetThreadPriority(int nPriority)
519 {
520  SetThreadPriority(GetCurrentThread(), nPriority);
521 }
522 #else
523 
524 #define THREAD_PRIORITY_LOWEST PRIO_MAX
525 #define THREAD_PRIORITY_BELOW_NORMAL 2
526 #define THREAD_PRIORITY_NORMAL 0
527 #define THREAD_PRIORITY_ABOVE_NORMAL 0
528 
529 inline void SetThreadPriority(int nPriority)
530 {
531  // It's unclear if it's even possible to change thread priorities on Linux,
532  // but we really and truly need it for the generation threads.
533 #ifdef PRIO_THREAD
534  setpriority(PRIO_THREAD, 0, nPriority);
535 #else
536  setpriority(PRIO_PROCESS, 0, nPriority);
537 #endif
538 }
539 
540 inline void ExitThread(size_t nExitCode)
541 {
542  pthread_exit((void*)nExitCode);
543 }
544 #endif
545 
546 void RenameThread(const char* name);
547 
549 {
550  value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8);
551  return (value<<16) | (value>>16);
552 }
553 
554 // Standard wrapper for do-something-forever thread functions.
555 // "Forever" really means until the thread is interrupted.
556 // Use it like:
557 // new boost::thread(boost::bind(&LoopForever<void (*)()>, "dumpaddr", &DumpAddresses, 900000));
558 // or maybe:
559 // boost::function<void()> f = boost::bind(&FunctionWithArg, argument);
560 // threadGroup.create_thread(boost::bind(&LoopForever<boost::function<void()> >, "nothing", f, milliseconds));
561 template <typename Callable> void LoopForever(const char* name, Callable func, int64 msecs)
562 {
563  std::string s = strprintf("bitcoin-%s", name);
564  RenameThread(s.c_str());
565  printf("%s thread start\n", name);
566  try
567  {
568  while (1)
569  {
570  MilliSleep(msecs);
571  func();
572  }
573  }
574  catch (boost::thread_interrupted)
575  {
576  printf("%s thread stop\n", name);
577  throw;
578  }
579  catch (std::exception& e) {
580  PrintException(&e, name);
581  }
582  catch (...) {
583  PrintException(NULL, name);
584  }
585 }
586 // .. and a wrapper that just calls func once
587 template <typename Callable> void TraceThread(const char* name, Callable func)
588 {
589  std::string s = strprintf("bitcoin-%s", name);
590  RenameThread(s.c_str());
591  try
592  {
593  printf("%s thread start\n", name);
594  func();
595  printf("%s thread exit\n", name);
596  }
597  catch (boost::thread_interrupted)
598  {
599  printf("%s thread interrupt\n", name);
600  throw;
601  }
602  catch (std::exception& e) {
603  PrintException(&e, name);
604  }
605  catch (...) {
606  PrintException(NULL, name);
607  }
608 }
609 
610 #endif
std::string FormatMoney(int64 n, bool fPlus=false)
Definition: util.cpp:389
bool error(const char *format,...)
Definition: util.cpp:358
std::string FormatSubVersion(const std::string &name, int nClientVersion, const std::vector< std::string > &comments)
Definition: util.cpp:1410
void skipspaces(T &it)
Definition: util.h:362
unsigned long long uint64
Definition: util.h:33
#define ATTR_WARN_PRINTF(X, Y)
Definition: util.h:126
int64 GetPerformanceCounter()
Definition: util.h:327
#define strprintf(format,...)
Definition: util.h:169
#define PRI64d
Definition: util.h:51
void PrintException(std::exception *pex, const char *pszThread)
Definition: util.cpp:1014
std::string * value
Definition: version_set.cc:270
bool ParseMoney(const std::string &str, int64 &nRet)
bool GetBoolArg(const std::string &strArg, bool fDefault=false)
Return boolean argument or default value.
Definition: util.cpp:600
void PrintHex(const T pbegin, const T pend, const char *pszFormat="%s", bool fSpaces=true)
Definition: util.h:317
void ShrinkDebugFile()
Definition: util.cpp:1258
bool fPrintToConsole
Definition: util.cpp:75
void LogException(std::exception *pex, const char *pszThread)
Definition: util.cpp:1008
std::vector< unsigned char > DecodeBase32(const char *p, bool *pfInvalid=NULL)
Definition: util.cpp:832
void RandAddSeedPerfmon()
Definition: util.cpp:148
void RenameThread(const char *name)
Definition: util.cpp:1467
Median filter over a stream of values.
Definition: util.h:462
void ReadConfigFile(std::map< std::string, std::string > &mapSettingsRet, std::map< std::string, std::vector< std::string > > &mapMultiSettingsRet)
std::string SanitizeString(const std::string &str)
int64 GetTime()
Definition: util.cpp:1298
int GetRandInt(int nMax)
Definition: util.cpp:190
unsigned long long uint64
Definition: serialize.h:26
std::map< std::string, std::vector< std::string > > mapMultiArgs
Definition: util.cpp:72
std::vector< T > vSorted
Definition: util.h:466
void LoopForever(const char *name, Callable func, int64 msecs)
Definition: util.h:561
std::string FormatFullVersion()
Definition: util.cpp:1404
void CreatePidFile(const boost::filesystem::path &path, pid_t pid)
Definition: util.cpp:1136
int64 atoi64(const char *psz)
Definition: util.h:253
void ParseString(const std::string &str, char c, std::vector< std::string > &v)
bool NewThread(void(*pfn)(void *), void *parg)
Definition: util.cpp:1491
std::map< std::string, std::string > mapArgs
Definition: util.cpp:71
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
Definition: util.cpp:611
std::vector< unsigned char > ParseHex(const char *psz)
Definition: util.cpp:500
int64 GetTimeMillis()
Definition: util.h:340
int std::string int dummy
Definition: util.h:164
void MilliSleep(int64 n)
Definition: util.h:106
std::vector< T > vValues
Definition: util.h:465
int GetFilesize(FILE *file)
Definition: util.cpp:1174
const boost::filesystem::path & GetDataDir(bool fNetSpecific=true)
Definition: util.cpp:1060
bool fDebugNet
Definition: util.cpp:74
void RandAddSeed()
Definition: util.cpp:140
void input(T value)
Definition: util.h:477
std::string itostr(int n)
Definition: util.h:248
unsigned int uint32_t
Definition: stdint.h:21
bool fCommandLine
Definition: util.cpp:79
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
Definition: util.cpp:619
bool fNoListen
Definition: util.cpp:83
bool fPrintToDebugger
Definition: util.cpp:76
void TraceThread(const char *name, Callable func)
Definition: util.h:587
CMedianFilter(unsigned int size, T initial_value)
Definition: util.h:469
void ParseParameters(int argc, const char *const argv[])
Definition: util.cpp:541
T median() const
Definition: util.h:490
uint256 GetRandHash()
Definition: util.cpp:195
bool fTestNet
Definition: util.cpp:81
long long int64
Definition: util.h:32
std::string DateTimeStrFormat(const char *pszFormat, int64 nTime)
Definition: util.h:352
bool fDaemon
Definition: util.cpp:77
bool fServer
Definition: util.cpp:78
int64 GetTimeOffset()
Definition: util.cpp:1312
void ExitThread(size_t nExitCode)
Definition: util.h:540
#define printf
Definition: util.h:180
int OutputDebugStringF(const char *pszFormat,...)
Definition: util.cpp:237
T * alignup(T *p)
Definition: util.h:82
bool IsHex(const std::string &str)
int64 GetAdjustedTime()
Definition: util.cpp:1317
std::string EncodeBase64(const unsigned char *pch, size_t len)
Definition: util.cpp:628
void SetThreadPriority(int nPriority)
Definition: util.h:529
void PrintExceptionContinue(std::exception *pex, const char *pszThread)
Definition: util.cpp:1023
std::vector< unsigned char > DecodeBase64(const char *p, bool *pfInvalid=NULL)
Definition: util.cpp:679
int64 GetTimeMicros()
Definition: util.h:346
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
Definition: netbase.h:34
void(* func)()
Definition: testharness.cc:19
std::string EncodeBase32(const unsigned char *pch, size_t len)
Definition: util.cpp:768
int size() const
Definition: util.h:504
256-bit unsigned integer
Definition: uint256.h:537
std::string strMiscWarning
Definition: util.cpp:80
bool IsSwitchChar(char c)
Definition: util.h:368
uint32_t insecure_rand_Rz
MWC RNG of George Marsaglia This is intended to be fast.
Definition: util.cpp:1375
bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
Definition: util.cpp:1147
uint32_t ByteReverse(uint32_t value)
Definition: util.h:548
void FileCommit(FILE *fileout)
Definition: util.cpp:1158
bool fDebug
Definition: util.cpp:73
boost::filesystem::path GetConfigFile()
Definition: util.cpp:1094
bool fBloomFilters
Definition: util.cpp:82
void seed_insecure_rand(bool fDeterministic=false)
Seed insecure_rand using the random pool.
Definition: util.cpp:1377
boost::filesystem::path GetTempPath()
Definition: util.cpp:1438
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
Definition: util.cpp:586
bool TimingResistantEqual(const T &a, const T &b)
Timing-attack-resistant comparison.
Definition: util.h:450
void SetMockTime(int64 nMockTimeIn)
Definition: util.cpp:1305
bool WildcardMatch(const char *psz, const char *mask)
Definition: util.cpp:956
int RaiseFileDescriptorLimit(int nMinFD)
Definition: util.cpp:1195
std::vector< T > sorted() const
Definition: util.h:509
uint64 GetRand(uint64 nMax)
Definition: util.cpp:175
boost::filesystem::path GetPidFile()
Definition: util.cpp:1128
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length)
Definition: util.cpp:1216
bool TruncateFile(FILE *file, unsigned int length)
Definition: util.cpp:1184
unsigned int nSize
Definition: util.h:467
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
Definition: util.h:292
std::string i64tostr(int64 n)
Definition: util.h:243
void AddTimeData(const CNetAddr &ip, int64 nTime)
Definition: util.cpp:1322
volatile bool fReopenDebugLog
Definition: util.cpp:86
int64 roundint64(double d)
Definition: util.h:281
bool fLogTimestamps
Definition: util.cpp:84
CService ip(uint32_t i)
Definition: DoS_tests.cpp:24
boost::filesystem::path GetDefaultDataDir()
Definition: util.cpp:1031
std::string vstrprintf(const char *format, va_list ap)
Definition: util.cpp:309
int std::string int std::string real_strprintf(const std::string &format, int dummy,...)
Overload strprintf for std::string, to be able to use it with _ (translation).
Definition: util.cpp:349
uint32_t insecure_rand_Rw
Definition: util.cpp:1376
int roundint(double d)
Definition: util.h:276
int atoi(const std::string &str)
Definition: util.h:271
const char * name
Definition: testharness.cc:18
void runCommand(std::string strCommand)
Definition: util.cpp:1460
int64 abs64(int64 n)
Definition: util.h:286
long long int64
Definition: serialize.h:25