Skip to content

Commit

Permalink
Update util.h
Browse files Browse the repository at this point in the history
  • Loading branch information
vashshawn authored Apr 13, 2024
1 parent a79ed4d commit a50219b
Showing 1 changed file with 60 additions and 14 deletions.
74 changes: 60 additions & 14 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,33 @@ static const int64_t CENT = 1000000;
#define UINTBEGIN(a) ((uint32_t*)&(a))
#define CUINTBEGIN(a) ((const uint32_t*)&(a))

#ifndef PRId64
#if defined(_MSC_VER) || defined(__MSVCRT__)
#define PRIu64 "I64u"
#define PRId64 "I64d"
#define PRIx64 "I64x"
#else
#define PRId64 "lld"
#define PRIu64 "llu"
#define PRIx64 "llx"
#endif
#endif

#ifndef THROW_WITH_STACKTRACE
#define THROW_WITH_STACKTRACE(exception) \
{ \
LogStackTrace(); \
throw (exception); \
}
void LogStackTrace();
#endif

/* Format characters for (s)size_t and ptrdiff_t */
#if defined(_MSC_VER) || defined(__MSVCRT__)
/* (s)size_t and ptrdiff_t have the same size specifier in MSVC:
http://msdn.microsoft.com/en-us/library/tcxf1dw6%28v=vs.100%29.aspx
*/

#define PRIszx "Ix"
#define PRIszu "Iu"
#define PRIszd "Id"
Expand All @@ -74,13 +96,6 @@ static const int64_t CENT = 1000000;
#define PRIpdx "tx"
#define PRIpdu "tu"
#define PRIpdd "td"
#undef PRIu64
#undef PRId64
#undef PRIx64

#define PRIu64 "I64u"
#define PRId64 "I64d"
#define PRIx64 "I64x"
#endif

// This is needed because the foreach macro can't get over the comma in pair<t1, t2>
Expand Down Expand Up @@ -110,6 +125,8 @@ T* alignup(T* p)
#endif
#else
#define MAX_PATH 1024
#endif

inline void Sleep(int64_t n)
{
/*Boost has a year 2038 problem— if the request sleep time is past epoch+2^31 seconds the sleep returns instantly.
Expand All @@ -131,21 +148,56 @@ inline void Sleep(int64_t n)







extern std::map<std::string, std::string> mapArgs;
extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
extern bool fDebug;
extern bool fDebugNet;
extern bool fPrintToConsole;
extern bool fPrintToDebugLog;
extern bool fRequestShutdown;
extern bool fShutdown;
extern bool fDaemon;
extern bool fServer;
extern bool fCommandLine;
extern std::string strMiscWarning;
extern bool fTestNet;
extern bool fNoListen;
extern bool fLogTimestamps;
extern volatile bool fReopenDebugLog;

void RandAddSeed();
void RandAddSeedPerfmon();
int ATTR_WARN_PRINTF(1,2) OutputDebugStringF(const char* pszFormat, ...);

/*
Rationale for the real_strprintf / strprintf construction:
It is not allowed to use va_start with a pass-by-reference argument.
(C++ standard, 18.7, paragraph 3). Use a dummy argument to work around this, and use a
macro to keep similar semantics.
*/

/** Overload strprintf for char*, so that GCC format type warnings can be given */
std::string ATTR_WARN_PRINTF(1,3) real_strprintf(const char *format, int dummy, ...);
/** Overload strprintf for std::string, to be able to use it with _ (translation).
* This will not support GCC format type warnings (-Wformat) so be careful.
*/
std::string real_strprintf(const std::string &format, int dummy, ...);
#define strprintf(format, ...) real_strprintf(format, 0, __VA_ARGS__)
std::string vstrprintf(const char *format, va_list ap);

bool ATTR_WARN_PRINTF(1,2) error(const char *format, ...);

/* Redefine printf so that it directs output to debug.log
*
* Do this *after* defining the other printf-like functions, because otherwise the
* __attribute__((format(printf,X,Y))) gets expanded to __attribute__((format(OutputDebugStringF,X,Y)))
* which confuses gcc.
*/
#define printf OutputDebugStringF

/* Return true if log accepts specified category */
bool LogAcceptCategory(const char* category);
Expand Down Expand Up @@ -189,7 +241,6 @@ static inline bool error(const char* format)
return false;
}


void PrintException(std::exception* pex, const char* pszThread);
void PrintExceptionContinue(std::exception* pex, const char* pszThread);
void ParseString(const std::string& str, char c, std::vector<std::string>& v);
Expand Down Expand Up @@ -231,14 +282,9 @@ uint256 GetRandHash();
int64_t GetTime();
int64_t GetTimeMillis();
int64_t GetTimeMicros();
void SetMockTime(int64_t nMockTimeIn);
std::string FormatFullVersion();
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
void runCommand(std::string strCommand);

int64_t GetAdjustedTime();
int64_t GetTimeOffset();
int64_t GetNodesOffset();
void SetMockTime(int64_t nMockTimeIn);
std::string FormatFullVersion();
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
void AddTimeData(const CNetAddr& ip, int64_t nTime);
Expand Down

0 comments on commit a50219b

Please sign in to comment.