#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
-#else
-typedef int pid_t; /* define for Windows compatibility */
#endif
+
#include <map>
#include <vector>
#include <string>
static const int64 COIN = 1000000;
static const int64 CENT = 10000;
-#define loop for (;;)
#define BEGIN(a) ((char*)&(a))
#define END(a) ((char*)&((&(a))[1]))
#define UBEGIN(a) ((unsigned char*)&(a))
const boost::filesystem::path &GetDataDir(bool fNetSpecific = true);
boost::filesystem::path GetConfigFile();
boost::filesystem::path GetPidFile();
+#ifndef WIN32
void CreatePidFile(const boost::filesystem::path &path, pid_t pid);
+#endif
void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet, std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet);
#ifdef WIN32
boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
return (n >= 0 ? n : -n);
}
+inline std::string leftTrim(std::string src, char chr)
+{
+ std::string::size_type pos = src.find_first_not_of(chr, 0);
+
+ if(pos > 0)
+ src.erase(0, pos);
+
+ return src;
+}
+
template<typename T>
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
{
return hash2;
}
+/**
+ * Timing-attack-resistant comparison.
+ * Takes time proportional to length
+ * of first argument.
+ */
+template <typename T>
+bool TimingResistantEqual(const T& a, const T& b)
+{
+ if (b.size() == 0) return a.size() == 0;
+ size_t accumulator = a.size() ^ b.size();
+ for (size_t i = 0; i < a.size(); i++)
+ accumulator |= a[i] ^ b[i%b.size()];
+ return accumulator == 0;
+}
/** Median filter over a stream of values.
* Returns the median of the last N numbers