- 4B0F7B3A7757336B6E5C349D89170BFC4B4C40A04E0EC3FCCF0B155314689C781DEB9590AB05DAA8AF20A123E2F3CAD55C5AF1244700197A3530D0D4699D32C5
+ 626E2306C3784911C960136E39BD3EB7C925CA90378FAA03FB616A5D7180335889F0807BB39C9AC1907B285C43E730558190E1A1D5717EBA4BAE6006A9ABEDFD
bitcoin/src/util.cpp
(64 . 11)(64 . 6)
608 ppmutexOpenSSL[i] = new boost::interprocess::interprocess_mutex();
609 CRYPTO_set_locking_callback(locking_callback);
610
611 #ifdef WIN32
612 // Seed random number generator with screen scrape and other hardware sources
613 RAND_screen();
614 #endif
615
616 // Seed random number generator with performance counter
617 RandAddSeed();
618 }
(108 . 21)(103 . 6)
620 return;
621 nLastPerfmon = GetTime();
622
623 #ifdef WIN32
624 // Don't need this on Linux, OpenSSL automatically uses /dev/urandom
625 // Seed with the entire set of perfmon data
626 unsigned char pdata[250000];
627 memset(pdata, 0, sizeof(pdata));
628 unsigned long nSize = sizeof(pdata);
629 long ret = RegQueryValueExA(HKEY_PERFORMANCE_DATA, "Global", NULL, NULL, pdata, &nSize);
630 RegCloseKey(HKEY_PERFORMANCE_DATA);
631 if (ret == ERROR_SUCCESS)
632 {
633 RAND_add(pdata, nSize, nSize/100.0);
634 memset(pdata, 0, nSize);
635 printf("%s RandAddSeed() %d bytes\n", DateTimeStrFormat("%x %H:%M", GetTime()).c_str(), nSize);
636 }
637 #endif
638 }
639
640 uint64 GetRand(uint64 nMax)
(198 . 48)(178 . 6)
642 }
643 }
644
645 #ifdef WIN32
646 if (fPrintToDebugger)
647 {
648 static CCriticalSection cs_OutputDebugStringF;
649
650 // accumulate a line at a time
651 CRITICAL_BLOCK(cs_OutputDebugStringF)
652 {
653 static char pszBuffer[50000];
654 static char* pend;
655 if (pend == NULL)
656 pend = pszBuffer;
657 va_list arg_ptr;
658 va_start(arg_ptr, pszFormat);
659 int limit = END(pszBuffer) - pend - 2;
660 int ret = _vsnprintf(pend, limit, pszFormat, arg_ptr);
661 va_end(arg_ptr);
662 if (ret < 0 || ret >= limit)
663 {
664 pend = END(pszBuffer) - 2;
665 *pend++ = '\n';
666 }
667 else
668 pend += ret;
669 *pend = '\0';
670 char* p1 = pszBuffer;
671 char* p2;
672 while (p2 = strchr(p1, '\n'))
673 {
674 p2++;
675 char c = *p2;
676 *p2 = '\0';
677 OutputDebugStringA(p1);
678 *p2 = c;
679 p1 = p2;
680 }
681 if (p1 != pszBuffer)
682 memmove(pszBuffer, p1, pend - p1 + 1);
683 pend -= (p1 - pszBuffer);
684 }
685 }
686 #endif
687 return ret;
688 }
689
(457 . 11)(395 . 6)
691 pszValue = strchr(psz, '=');
692 *pszValue++ = '\0';
693 }
694 #ifdef WIN32
695 _strlwr(psz);
696 if (psz[0] == '/')
697 psz[0] = '-';
698 #endif
699 if (psz[0] != '-')
700 break;
701 mapArgs[psz] = pszValue;
(665 . 13)(598 . 7)
703
704 void FormatException(char* pszMessage, std::exception* pex, const char* pszThread)
705 {
706 #ifdef WIN32
707 char pszModule[MAX_PATH];
708 pszModule[0] = '\0';
709 GetModuleFileNameA(NULL, pszModule, sizeof(pszModule));
710 #else
711 const char* pszModule = "bitcoin";
712 #endif
713 if (pex)
714 snprintf(pszMessage, 1000,
715 "EXCEPTION: %s \n%s \n%s in %s \n", typeid(*pex).name(), pex->what(), pszModule, pszThread);
(717 . 67)(644 . 10)
717 strMiscWarning = pszMessage;
718 }
719
720
721
722
723
724
725
726
727 #ifdef WIN32
728 typedef WINSHELLAPI BOOL (WINAPI *PSHGETSPECIALFOLDERPATHA)(HWND hwndOwner, LPSTR lpszPath, int nFolder, BOOL fCreate);
729
730 string MyGetSpecialFolderPath(int nFolder, bool fCreate)
731 {
732 char pszPath[MAX_PATH+100] = "";
733
734 // SHGetSpecialFolderPath isn't always available on old Windows versions
735 HMODULE hShell32 = LoadLibraryA("shell32.dll");
736 if (hShell32)
737 {
738 PSHGETSPECIALFOLDERPATHA pSHGetSpecialFolderPath =
739 (PSHGETSPECIALFOLDERPATHA)GetProcAddress(hShell32, "SHGetSpecialFolderPathA");
740 bool fSuccess = false;
741 if (pSHGetSpecialFolderPath)
742 fSuccess =
743 (*pSHGetSpecialFolderPath)(NULL, pszPath, nFolder, fCreate);
744 FreeModule(hShell32);
745 if (fSuccess)
746 return pszPath;
747 }
748
749 // Backup option
750 std::string strPath;
751 {
752 const char *pszEnv;
753 if (nFolder == CSIDL_STARTUP)
754 {
755 pszEnv = getenv("USERPROFILE");
756 if (pszEnv)
757 strPath = pszEnv;
758 strPath += "\\Start Menu\\Programs\\Startup";
759 }
760 else if (nFolder == CSIDL_APPDATA)
761 {
762 pszEnv = getenv("APPDATA");
763 if (pszEnv)
764 strPath = pszEnv;
765 }
766 }
767
768 return strPath;
769 }
770 #endif
771
772 string GetDefaultDataDir()
773 {
774 // Windows: C:\Documents and Settings\username\Application Data\Bitcoin
775 // Mac: ~/Library/Application Support/Bitcoin
776 // Unix: ~/.bitcoin
777 #ifdef WIN32
778 // Windows
779 return MyGetSpecialFolderPath(CSIDL_APPDATA, true) + "\\Bitcoin";
780 #else
781 char* pszHome = getenv("HOME");
782 if (pszHome == NULL || strlen(pszHome) == 0)
783 pszHome = (char*)"/";
(793 . 7)(663 . 6)
785 // Unix
786 return strHome + ".bitcoin";
787 #endif
788 #endif
789 }
790
791 void GetDataDir(char* pszDir)