1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #if defined(HAVE_CONFIG_H)
7 #include "config/bitcoin-config.h"
12 #include "chainparamsbase.h"
14 #include "serialize.h"
16 #include "utilstrencodings.h"
21 #if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
23 #include <pthread_np.h>
27 // for posix_fallocate
30 #ifdef _POSIX_C_SOURCE
31 #undef _POSIX_C_SOURCE
34 #define _POSIX_C_SOURCE 200112L
40 #include <sys/resource.h>
46 #pragma warning(disable:4786)
47 #pragma warning(disable:4804)
48 #pragma warning(disable:4805)
49 #pragma warning(disable:4717)
55 #define _WIN32_WINNT 0x0501
60 #define _WIN32_IE 0x0501
62 #define WIN32_LEAN_AND_MEAN 1
67 #include <io.h> /* for _commit */
71 #ifdef HAVE_SYS_PRCTL_H
72 #include <sys/prctl.h>
75 #include <boost/algorithm/string/case_conv.hpp> // for to_lower()
76 #include <boost/algorithm/string/join.hpp>
77 #include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith()
78 #include <boost/filesystem.hpp>
79 #include <boost/filesystem/fstream.hpp>
80 #include <boost/foreach.hpp>
81 #include <boost/program_options/detail/config_file.hpp>
82 #include <boost/program_options/parsers.hpp>
83 #include <boost/thread.hpp>
84 #include <openssl/crypto.h>
85 #include <openssl/rand.h>
86 #include <openssl/conf.h>
88 // Work around clang compilation problem in Boost 1.46:
89 // /usr/include/boost/program_options/detail/config_file.hpp:163:17: error: call to function 'to_internal' that is neither visible in the template definition nor found by argument-dependent lookup
90 // See also: http://stackoverflow.com/questions/10020179/compilation-fail-in-boost-librairies-program-options
91 // http://clang.debian.net/status.php?version=3.0&key=CANNOT_FIND_FUNCTION
94 namespace program_options
{
95 std::string
to_internal(const std::string
&);
102 const char * const BITCOIN_CONF_FILENAME
= "bitcoin.conf";
103 const char * const BITCOIN_PID_FILENAME
= "bitcoind.pid";
105 CCriticalSection cs_args
;
106 map
<string
, string
> mapArgs
;
107 static map
<string
, vector
<string
> > _mapMultiArgs
;
108 const map
<string
, vector
<string
> >& mapMultiArgs
= _mapMultiArgs
;
110 bool fPrintToConsole
= false;
111 bool fPrintToDebugLog
= true;
113 bool fLogTimestamps
= DEFAULT_LOGTIMESTAMPS
;
114 bool fLogTimeMicros
= DEFAULT_LOGTIMEMICROS
;
115 bool fLogIPs
= DEFAULT_LOGIPS
;
116 std::atomic
<bool> fReopenDebugLog(false);
117 CTranslationInterface translationInterface
;
119 /** Init OpenSSL library multithreading support */
120 static CCriticalSection
** ppmutexOpenSSL
;
121 void locking_callback(int mode
, int i
, const char* file
, int line
) NO_THREAD_SAFETY_ANALYSIS
123 if (mode
& CRYPTO_LOCK
) {
124 ENTER_CRITICAL_SECTION(*ppmutexOpenSSL
[i
]);
126 LEAVE_CRITICAL_SECTION(*ppmutexOpenSSL
[i
]);
136 // Init OpenSSL library multithreading support
137 ppmutexOpenSSL
= (CCriticalSection
**)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(CCriticalSection
*));
138 for (int i
= 0; i
< CRYPTO_num_locks(); i
++)
139 ppmutexOpenSSL
[i
] = new CCriticalSection();
140 CRYPTO_set_locking_callback(locking_callback
);
142 // OpenSSL can optionally load a config file which lists optional loadable modules and engines.
143 // We don't use them so we don't require the config. However some of our libs may call functions
144 // which attempt to load the config file, possibly resulting in an exit() or crash if it is missing
145 // or corrupt. Explicitly tell OpenSSL not to try to load the file. The result for our libs will be
146 // that the config appears to have been loaded and there are no modules/engines available.
150 // Seed OpenSSL PRNG with current contents of the screen
154 // Seed OpenSSL PRNG with performance counter
159 // Securely erase the memory used by the PRNG
161 // Shutdown OpenSSL library multithreading support
162 CRYPTO_set_locking_callback(NULL
);
163 for (int i
= 0; i
< CRYPTO_num_locks(); i
++)
164 delete ppmutexOpenSSL
[i
];
165 OPENSSL_free(ppmutexOpenSSL
);
171 * LogPrintf() has been broken a couple of times now
172 * by well-meaning people adding mutexes in the most straightforward way.
173 * It breaks because it may be called by global destructors during shutdown.
174 * Since the order of destruction of static/global objects is undefined,
175 * defining a mutex as a global object doesn't work (the mutex gets
176 * destroyed, and then some later destructor calls OutputDebugStringF,
177 * maybe indirectly, and you get a core dump at shutdown trying to lock
181 static boost::once_flag debugPrintInitFlag
= BOOST_ONCE_INIT
;
184 * We use boost::call_once() to make sure mutexDebugLog and
185 * vMsgsBeforeOpenLog are initialized in a thread-safe manner.
187 * NOTE: fileout, mutexDebugLog and sometimes vMsgsBeforeOpenLog
188 * are leaked on exit. This is ugly, but will be cleaned up by
189 * the OS/libc. When the shutdown sequence is fully audited and
190 * tested, explicit destruction of these objects can be implemented.
192 static FILE* fileout
= NULL
;
193 static boost::mutex
* mutexDebugLog
= NULL
;
194 static list
<string
> *vMsgsBeforeOpenLog
;
196 static int FileWriteStr(const std::string
&str
, FILE *fp
)
198 return fwrite(str
.data(), 1, str
.size(), fp
);
201 static void DebugPrintInit()
203 assert(mutexDebugLog
== NULL
);
204 mutexDebugLog
= new boost::mutex();
205 vMsgsBeforeOpenLog
= new list
<string
>;
210 boost::call_once(&DebugPrintInit
, debugPrintInitFlag
);
211 boost::mutex::scoped_lock
scoped_lock(*mutexDebugLog
);
213 assert(fileout
== NULL
);
214 assert(vMsgsBeforeOpenLog
);
215 boost::filesystem::path pathDebug
= GetDataDir() / "debug.log";
216 fileout
= fopen(pathDebug
.string().c_str(), "a");
218 setbuf(fileout
, NULL
); // unbuffered
219 // dump buffered messages from before we opened the log
220 while (!vMsgsBeforeOpenLog
->empty()) {
221 FileWriteStr(vMsgsBeforeOpenLog
->front(), fileout
);
222 vMsgsBeforeOpenLog
->pop_front();
226 delete vMsgsBeforeOpenLog
;
227 vMsgsBeforeOpenLog
= NULL
;
230 bool LogAcceptCategory(const char* category
)
232 if (category
!= NULL
)
237 // Give each thread quick access to -debug settings.
238 // This helps prevent issues debugging global destructors,
239 // where mapMultiArgs might be deleted before another
240 // global destructor calls LogPrint()
241 static boost::thread_specific_ptr
<set
<string
> > ptrCategory
;
242 if (ptrCategory
.get() == NULL
)
244 if (mapMultiArgs
.count("-debug")) {
245 const vector
<string
>& categories
= mapMultiArgs
.at("-debug");
246 ptrCategory
.reset(new set
<string
>(categories
.begin(), categories
.end()));
247 // thread_specific_ptr automatically deletes the set when the thread ends.
249 ptrCategory
.reset(new set
<string
>());
251 const set
<string
>& setCategories
= *ptrCategory
.get();
253 // if not debugging everything and not debugging specific category, LogPrint does nothing.
254 if (setCategories
.count(string("")) == 0 &&
255 setCategories
.count(string("1")) == 0 &&
256 setCategories
.count(string(category
)) == 0)
263 * fStartedNewLine is a state variable held by the calling context that will
264 * suppress printing of the timestamp when multiple calls are made that don't
265 * end in a newline. Initialize it to true, and hold it, in the calling context.
267 static std::string
LogTimestampStr(const std::string
&str
, std::atomic_bool
*fStartedNewLine
)
274 if (*fStartedNewLine
) {
275 int64_t nTimeMicros
= GetLogTimeMicros();
276 strStamped
= DateTimeStrFormat("%Y-%m-%d %H:%M:%S", nTimeMicros
/1000000);
278 strStamped
+= strprintf(".%06d", nTimeMicros
%1000000);
279 strStamped
+= ' ' + str
;
283 if (!str
.empty() && str
[str
.size()-1] == '\n')
284 *fStartedNewLine
= true;
286 *fStartedNewLine
= false;
291 int LogPrintStr(const std::string
&str
)
293 int ret
= 0; // Returns total number of characters written
294 static std::atomic_bool
fStartedNewLine(true);
296 string strTimestamped
= LogTimestampStr(str
, &fStartedNewLine
);
301 ret
= fwrite(strTimestamped
.data(), 1, strTimestamped
.size(), stdout
);
304 else if (fPrintToDebugLog
)
306 boost::call_once(&DebugPrintInit
, debugPrintInitFlag
);
307 boost::mutex::scoped_lock
scoped_lock(*mutexDebugLog
);
309 // buffer if we haven't opened the log yet
310 if (fileout
== NULL
) {
311 assert(vMsgsBeforeOpenLog
);
312 ret
= strTimestamped
.length();
313 vMsgsBeforeOpenLog
->push_back(strTimestamped
);
317 // reopen the log file, if requested
318 if (fReopenDebugLog
) {
319 fReopenDebugLog
= false;
320 boost::filesystem::path pathDebug
= GetDataDir() / "debug.log";
321 if (freopen(pathDebug
.string().c_str(),"a",fileout
) != NULL
)
322 setbuf(fileout
, NULL
); // unbuffered
325 ret
= FileWriteStr(strTimestamped
, fileout
);
331 /** Interpret string as boolean, for argument parsing */
332 static bool InterpretBool(const std::string
& strValue
)
334 if (strValue
.empty())
336 return (atoi(strValue
) != 0);
339 /** Turn -noX into -X=0 */
340 static void InterpretNegativeSetting(std::string
& strKey
, std::string
& strValue
)
342 if (strKey
.length()>3 && strKey
[0]=='-' && strKey
[1]=='n' && strKey
[2]=='o')
344 strKey
= "-" + strKey
.substr(3);
345 strValue
= InterpretBool(strValue
) ? "0" : "1";
349 void ParseParameters(int argc
, const char* const argv
[])
353 _mapMultiArgs
.clear();
355 for (int i
= 1; i
< argc
; i
++)
357 std::string
str(argv
[i
]);
358 std::string strValue
;
359 size_t is_index
= str
.find('=');
360 if (is_index
!= std::string::npos
)
362 strValue
= str
.substr(is_index
+1);
363 str
= str
.substr(0, is_index
);
366 boost::to_lower(str
);
367 if (boost::algorithm::starts_with(str
, "/"))
368 str
= "-" + str
.substr(1);
374 // Interpret --foo as -foo.
375 // If both --foo and -foo are set, the last takes effect.
376 if (str
.length() > 1 && str
[1] == '-')
378 InterpretNegativeSetting(str
, strValue
);
380 mapArgs
[str
] = strValue
;
381 _mapMultiArgs
[str
].push_back(strValue
);
385 bool IsArgSet(const std::string
& strArg
)
388 return mapArgs
.count(strArg
);
391 std::string
GetArg(const std::string
& strArg
, const std::string
& strDefault
)
394 if (mapArgs
.count(strArg
))
395 return mapArgs
[strArg
];
399 int64_t GetArg(const std::string
& strArg
, int64_t nDefault
)
402 if (mapArgs
.count(strArg
))
403 return atoi64(mapArgs
[strArg
]);
407 bool GetBoolArg(const std::string
& strArg
, bool fDefault
)
410 if (mapArgs
.count(strArg
))
411 return InterpretBool(mapArgs
[strArg
]);
415 bool SoftSetArg(const std::string
& strArg
, const std::string
& strValue
)
418 if (mapArgs
.count(strArg
))
420 mapArgs
[strArg
] = strValue
;
424 bool SoftSetBoolArg(const std::string
& strArg
, bool fValue
)
427 return SoftSetArg(strArg
, std::string("1"));
429 return SoftSetArg(strArg
, std::string("0"));
432 void ForceSetArg(const std::string
& strArg
, const std::string
& strValue
)
435 mapArgs
[strArg
] = strValue
;
440 static const int screenWidth
= 79;
441 static const int optIndent
= 2;
442 static const int msgIndent
= 7;
444 std::string
HelpMessageGroup(const std::string
&message
) {
445 return std::string(message
) + std::string("\n\n");
448 std::string
HelpMessageOpt(const std::string
&option
, const std::string
&message
) {
449 return std::string(optIndent
,' ') + std::string(option
) +
450 std::string("\n") + std::string(msgIndent
,' ') +
451 FormatParagraph(message
, screenWidth
- msgIndent
, msgIndent
) +
455 static std::string
FormatException(const std::exception
* pex
, const char* pszThread
)
458 char pszModule
[MAX_PATH
] = "";
459 GetModuleFileNameA(NULL
, pszModule
, sizeof(pszModule
));
461 const char* pszModule
= "bitcoin";
465 "EXCEPTION: %s \n%s \n%s in %s \n", typeid(*pex
).name(), pex
->what(), pszModule
, pszThread
);
468 "UNKNOWN EXCEPTION \n%s in %s \n", pszModule
, pszThread
);
471 void PrintExceptionContinue(const std::exception
* pex
, const char* pszThread
)
473 std::string message
= FormatException(pex
, pszThread
);
474 LogPrintf("\n\n************************\n%s\n", message
);
475 fprintf(stderr
, "\n\n************************\n%s\n", message
.c_str());
478 boost::filesystem::path
GetDefaultDataDir()
480 namespace fs
= boost::filesystem
;
481 // Windows < Vista: C:\Documents and Settings\Username\Application Data\Bitcoin
482 // Windows >= Vista: C:\Users\Username\AppData\Roaming\Bitcoin
483 // Mac: ~/Library/Application Support/Bitcoin
487 return GetSpecialFolderPath(CSIDL_APPDATA
) / "Bitcoin";
490 char* pszHome
= getenv("HOME");
491 if (pszHome
== NULL
|| strlen(pszHome
) == 0)
492 pathRet
= fs::path("/");
494 pathRet
= fs::path(pszHome
);
497 return pathRet
/ "Library/Application Support/Bitcoin";
500 return pathRet
/ ".bitcoin";
505 static boost::filesystem::path pathCached
;
506 static boost::filesystem::path pathCachedNetSpecific
;
507 static CCriticalSection csPathCached
;
509 const boost::filesystem::path
&GetDataDir(bool fNetSpecific
)
511 namespace fs
= boost::filesystem
;
515 fs::path
&path
= fNetSpecific
? pathCachedNetSpecific
: pathCached
;
517 // This can be called during exceptions by LogPrintf(), so we cache the
518 // value so we don't have to do memory allocations after that.
522 if (IsArgSet("-datadir")) {
523 path
= fs::system_complete(GetArg("-datadir", ""));
524 if (!fs::is_directory(path
)) {
529 path
= GetDefaultDataDir();
532 path
/= BaseParams().DataDir();
534 fs::create_directories(path
);
539 void ClearDatadirCache()
543 pathCached
= boost::filesystem::path();
544 pathCachedNetSpecific
= boost::filesystem::path();
547 boost::filesystem::path
GetConfigFile(const std::string
& confPath
)
549 boost::filesystem::path
pathConfigFile(confPath
);
550 if (!pathConfigFile
.is_complete())
551 pathConfigFile
= GetDataDir(false) / pathConfigFile
;
553 return pathConfigFile
;
556 void ReadConfigFile(const std::string
& confPath
)
558 boost::filesystem::ifstream
streamConfig(GetConfigFile(confPath
));
559 if (!streamConfig
.good())
560 return; // No bitcoin.conf file is OK
564 set
<string
> setOptions
;
565 setOptions
.insert("*");
567 for (boost::program_options::detail::config_file_iterator
it(streamConfig
, setOptions
), end
; it
!= end
; ++it
)
569 // Don't overwrite existing settings so command line settings override bitcoin.conf
570 string strKey
= string("-") + it
->string_key
;
571 string strValue
= it
->value
[0];
572 InterpretNegativeSetting(strKey
, strValue
);
573 if (mapArgs
.count(strKey
) == 0)
574 mapArgs
[strKey
] = strValue
;
575 _mapMultiArgs
[strKey
].push_back(strValue
);
578 // If datadir is changed in .conf file:
583 boost::filesystem::path
GetPidFile()
585 boost::filesystem::path
pathPidFile(GetArg("-pid", BITCOIN_PID_FILENAME
));
586 if (!pathPidFile
.is_complete()) pathPidFile
= GetDataDir() / pathPidFile
;
590 void CreatePidFile(const boost::filesystem::path
&path
, pid_t pid
)
592 FILE* file
= fopen(path
.string().c_str(), "w");
595 fprintf(file
, "%d\n", pid
);
601 bool RenameOver(boost::filesystem::path src
, boost::filesystem::path dest
)
604 return MoveFileExA(src
.string().c_str(), dest
.string().c_str(),
605 MOVEFILE_REPLACE_EXISTING
) != 0;
607 int rc
= std::rename(src
.string().c_str(), dest
.string().c_str());
613 * Ignores exceptions thrown by Boost's create_directory if the requested directory exists.
614 * Specifically handles case where path p exists, but it wasn't possible for the user to
615 * write to the parent directory.
617 bool TryCreateDirectory(const boost::filesystem::path
& p
)
621 return boost::filesystem::create_directory(p
);
622 } catch (const boost::filesystem::filesystem_error
&) {
623 if (!boost::filesystem::exists(p
) || !boost::filesystem::is_directory(p
))
627 // create_directory didn't create the directory, it had to have existed already
631 void FileCommit(FILE *file
)
633 fflush(file
); // harmless if redundantly called
635 HANDLE hFile
= (HANDLE
)_get_osfhandle(_fileno(file
));
636 FlushFileBuffers(hFile
);
638 #if defined(__linux__) || defined(__NetBSD__)
639 fdatasync(fileno(file
));
640 #elif defined(__APPLE__) && defined(F_FULLFSYNC)
641 fcntl(fileno(file
), F_FULLFSYNC
, 0);
648 bool TruncateFile(FILE *file
, unsigned int length
) {
650 return _chsize(_fileno(file
), length
) == 0;
652 return ftruncate(fileno(file
), length
) == 0;
657 * this function tries to raise the file descriptor limit to the requested number.
658 * It returns the actual file descriptor limit (which may be more or less than nMinFD)
660 int RaiseFileDescriptorLimit(int nMinFD
) {
664 struct rlimit limitFD
;
665 if (getrlimit(RLIMIT_NOFILE
, &limitFD
) != -1) {
666 if (limitFD
.rlim_cur
< (rlim_t
)nMinFD
) {
667 limitFD
.rlim_cur
= nMinFD
;
668 if (limitFD
.rlim_cur
> limitFD
.rlim_max
)
669 limitFD
.rlim_cur
= limitFD
.rlim_max
;
670 setrlimit(RLIMIT_NOFILE
, &limitFD
);
671 getrlimit(RLIMIT_NOFILE
, &limitFD
);
673 return limitFD
.rlim_cur
;
675 return nMinFD
; // getrlimit failed, assume it's fine
680 * this function tries to make a particular range of a file allocated (corresponding to disk space)
681 * it is advisory, and the range specified in the arguments will never contain live data
683 void AllocateFileRange(FILE *file
, unsigned int offset
, unsigned int length
) {
685 // Windows-specific version
686 HANDLE hFile
= (HANDLE
)_get_osfhandle(_fileno(file
));
687 LARGE_INTEGER nFileSize
;
688 int64_t nEndPos
= (int64_t)offset
+ length
;
689 nFileSize
.u
.LowPart
= nEndPos
& 0xFFFFFFFF;
690 nFileSize
.u
.HighPart
= nEndPos
>> 32;
691 SetFilePointerEx(hFile
, nFileSize
, 0, FILE_BEGIN
);
693 #elif defined(MAC_OSX)
694 // OSX specific version
696 fst
.fst_flags
= F_ALLOCATECONTIG
;
697 fst
.fst_posmode
= F_PEOFPOSMODE
;
699 fst
.fst_length
= (off_t
)offset
+ length
;
700 fst
.fst_bytesalloc
= 0;
701 if (fcntl(fileno(file
), F_PREALLOCATE
, &fst
) == -1) {
702 fst
.fst_flags
= F_ALLOCATEALL
;
703 fcntl(fileno(file
), F_PREALLOCATE
, &fst
);
705 ftruncate(fileno(file
), fst
.fst_length
);
706 #elif defined(__linux__)
707 // Version using posix_fallocate
708 off_t nEndPos
= (off_t
)offset
+ length
;
709 posix_fallocate(fileno(file
), 0, nEndPos
);
712 // TODO: just write one byte per block
713 static const char buf
[65536] = {};
714 fseek(file
, offset
, SEEK_SET
);
716 unsigned int now
= 65536;
719 fwrite(buf
, 1, now
, file
); // allowed to fail; this function is advisory anyway
725 void ShrinkDebugFile()
727 // Amount of debug.log to save at end when shrinking (must fit in memory)
728 constexpr size_t RECENT_DEBUG_HISTORY_SIZE
= 10 * 1000000;
729 // Scroll debug.log if it's getting too big
730 boost::filesystem::path pathLog
= GetDataDir() / "debug.log";
731 FILE* file
= fopen(pathLog
.string().c_str(), "r");
732 // If debug.log file is more than 10% bigger the RECENT_DEBUG_HISTORY_SIZE
733 // trim it down by saving only the last RECENT_DEBUG_HISTORY_SIZE bytes
734 if (file
&& boost::filesystem::file_size(pathLog
) > 11 * (RECENT_DEBUG_HISTORY_SIZE
/ 10))
736 // Restart the file with some of the end
737 std::vector
<char> vch(RECENT_DEBUG_HISTORY_SIZE
, 0);
738 fseek(file
, -((long)vch
.size()), SEEK_END
);
739 int nBytes
= fread(vch
.data(), 1, vch
.size(), file
);
742 file
= fopen(pathLog
.string().c_str(), "w");
745 fwrite(vch
.data(), 1, nBytes
, file
);
749 else if (file
!= NULL
)
754 boost::filesystem::path
GetSpecialFolderPath(int nFolder
, bool fCreate
)
756 namespace fs
= boost::filesystem
;
758 char pszPath
[MAX_PATH
] = "";
760 if(SHGetSpecialFolderPathA(NULL
, pszPath
, nFolder
, fCreate
))
762 return fs::path(pszPath
);
765 LogPrintf("SHGetSpecialFolderPathA() failed, could not obtain requested path.\n");
770 void runCommand(const std::string
& strCommand
)
772 int nErr
= ::system(strCommand
.c_str());
774 LogPrintf("runCommand error: system(%s) returned %d\n", strCommand
, nErr
);
777 void RenameThread(const char* name
)
779 #if defined(PR_SET_NAME)
780 // Only the first 15 characters are used (16 - NUL terminator)
781 ::prctl(PR_SET_NAME
, name
, 0, 0, 0);
782 #elif (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
783 pthread_set_name_np(pthread_self(), name
);
785 #elif defined(MAC_OSX)
786 pthread_setname_np(name
);
788 // Prevent warnings for unused parameters...
793 void SetupEnvironment()
795 // On most POSIX systems (e.g. Linux, but not BSD) the environment's locale
796 // may be invalid, in which case the "C" locale is used as fallback.
797 #if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
799 std::locale(""); // Raises a runtime error if current locale is invalid
800 } catch (const std::runtime_error
&) {
801 setenv("LC_ALL", "C", 1);
804 // The path locale is lazy initialized and to avoid deinitialization errors
805 // in multithreading environments, it is set explicitly by the main thread.
806 // A dummy locale is used to extract the internal default locale, used by
807 // boost::filesystem::path, which is then used to explicitly imbue the path.
808 std::locale loc
= boost::filesystem::path::imbue(std::locale::classic());
809 boost::filesystem::path::imbue(loc
);
812 bool SetupNetworking()
815 // Initialize Windows Sockets
817 int ret
= WSAStartup(MAKEWORD(2,2), &wsadata
);
818 if (ret
!= NO_ERROR
|| LOBYTE(wsadata
.wVersion
) != 2 || HIBYTE(wsadata
.wVersion
) != 2)
826 #if BOOST_VERSION >= 105600
827 return boost::thread::physical_concurrency();
828 #else // Must fall back to hardware_concurrency, which unfortunately counts virtual cores
829 return boost::thread::hardware_concurrency();
833 std::string
CopyrightHolders(const std::string
& strPrefix
)
835 std::string strCopyrightHolders
= strPrefix
+ strprintf(_(COPYRIGHT_HOLDERS
), _(COPYRIGHT_HOLDERS_SUBSTITUTION
));
837 // Check for untranslated substitution to make sure Bitcoin Core copyright is not removed by accident
838 if (strprintf(COPYRIGHT_HOLDERS
, COPYRIGHT_HOLDERS_SUBSTITUTION
).find("Bitcoin Core") == std::string::npos
) {
839 strCopyrightHolders
+= "\n" + strPrefix
+ "The Bitcoin Core developers";
841 return strCopyrightHolders
;