62#if defined (_MSC_VER) && (_MSC_VER >= 1400)
64#elif defined (_M_IX86)
65 static void __cpuid(
int* cpuid_data,
int info_type)
92 static void __cpuid(
int* cpuid_data,
int) {
93 cpuid_data[0] = 0x00000000;
94 cpuid_data[1] = 0x00000000;
95 cpuid_data[2] = 0x00000000;
96 cpuid_data[3] = 0x00000000;
111 TFdSet() { fds_bits =
new fd_set; fds_bits->fd_count = 0; }
112 virtual ~TFdSet() {
delete fds_bits; }
113 void Copy(TFdSet &fd)
const { memcpy((
void*)fd.fds_bits, fds_bits,
sizeof(fd_set)); }
114 TFdSet(
const TFdSet& fd) { fd.Copy(*
this); }
115 TFdSet&
operator=(
const TFdSet& fd) { fd.Copy(*
this);
return *
this; }
116 void Zero() { fds_bits->fd_count = 0; }
119 if (fds_bits->fd_count < FD_SETSIZE-1)
120 fds_bits->fd_array[fds_bits->fd_count++] = (
SOCKET)fd;
122 ::SysError(
"TFdSet::Set",
"fd_count will exeed FD_SETSIZE");
127 for (i=0; i<fds_bits->fd_count; i++) {
128 if (fds_bits->fd_array[i]==(
SOCKET)fd) {
129 while (i<fds_bits->fd_count-1) {
130 fds_bits->fd_array[i] = fds_bits->fd_array[i+1];
133 fds_bits->fd_count--;
139 Int_t *GetBits() {
return fds_bits && fds_bits->fd_count ? (
Int_t*)fds_bits : 0; }
140 UInt_t GetCount() {
return (
UInt_t)fds_bits->fd_count; }
141 Int_t GetFd(
Int_t i) {
return i<fds_bits->fd_count ? fds_bits->fd_array[i] : 0; }
149 static HANDLE gGlobalEvent;
150 static HANDLE gTimerThreadHandle;
151 typedef NET_API_STATUS (WINAPI *pfn1)(LPVOID);
152 typedef NET_API_STATUS (WINAPI *pfn2)(LPCWSTR, LPCWSTR, DWORD, LPBYTE*);
153 typedef NET_API_STATUS (WINAPI *pfn3)(LPCWSTR, LPCWSTR, DWORD, LPBYTE*,
154 DWORD, LPDWORD, LPDWORD, PDWORD);
155 typedef NET_API_STATUS (WINAPI *pfn4)(LPCWSTR, DWORD, LPBYTE*, DWORD, LPDWORD,
157 static pfn1 p2NetApiBufferFree;
158 static pfn2 p2NetUserGetInfo;
159 static pfn3 p2NetLocalGroupGetMembers;
160 static pfn4 p2NetLocalGroupEnum;
162 static struct signal_map {
168 SIGSEGV, 0,
"segmentation violation",
169 -1 , 0,
"bad argument to system call",
170 -1 , 0,
"write on a pipe with no one to read it",
171 SIGILL, 0,
"illegal instruction",
174 SIGINT, 0,
"interrupt",
175 -1 , 0,
"window size change",
176 -1 , 0,
"alarm clock",
177 -1 , 0,
"death of a child",
178 -1 , 0,
"urgent data arrived on an I/O channel",
179 SIGFPE, 0,
"floating point exception",
180 SIGTERM, 0,
"termination signal",
181 -1 , 0,
"user-defined signal 1",
182 -1 , 0,
"user-defined signal 2"
203 static int WinNTRecv(
int socket,
void *buffer,
int length,
int flag)
205 if (socket == -1)
return -1;
213 if (flag == MSG_PEEK) {
218 char *buf = (
char *)buffer;
220 for (
n = 0;
n < length;
n += nrecv) {
221 if ((nrecv = ::recv(sock, buf+
n, length-
n, flag)) <= 0) {
225 if (flag == MSG_OOB) {
226 if (::WSAGetLastError() == WSAEWOULDBLOCK) {
228 }
else if (::WSAGetLastError() == WSAEINVAL) {
232 if (::WSAGetLastError() == WSAEWOULDBLOCK) {
235 if (::WSAGetLastError() != WSAEINTR)
236 ::SysError(
"TWinNTSystem::WinNTRecv",
"recv");
237 if (::WSAGetLastError() == EPIPE ||
238 ::WSAGetLastError() == WSAECONNRESET)
257 static int WinNTSend(
int socket,
const void *buffer,
int length,
int flag)
259 if (socket < 0)
return -1;
269 const char *buf = (
const char *)buffer;
271 for (
n = 0;
n < length;
n += nsent) {
272 if ((nsent = ::send(sock, buf+
n, length-
n, flag)) <= 0) {
276 if (::WSAGetLastError() == WSAEWOULDBLOCK) {
279 if (::WSAGetLastError() != WSAEINTR)
280 ::SysError(
"TWinNTSystem::WinNTSend",
"send");
281 if (::WSAGetLastError() == EPIPE ||
282 ::WSAGetLastError() == WSAECONNRESET)
299 static int WinNTSelect(TFdSet *readready, TFdSet *writeready,
Long_t timeout)
302 fd_set* rbits = readready ? (fd_set*)readready->GetBits() : 0;
303 fd_set* wbits = writeready ? (fd_set*)writeready->GetBits() : 0;
307 tv.tv_sec = timeout / 1000;
308 tv.tv_usec = (timeout % 1000) * 1000;
310 retcode = ::select(0, rbits, wbits, 0, &tv);
312 retcode = ::select(0, rbits, wbits, 0, 0);
315 if (retcode == SOCKET_ERROR) {
316 int errcode = ::WSAGetLastError();
320 if (errcode == WSAENOTSOCK) {
322 int result = _fstat64( readready->GetFd(0), &buf );
330 ::WaitForSingleObject(gGlobalEvent, 1);
331 ::ResetEvent(gGlobalEvent);
336 if ( errcode == WSAEINTR) {
340 if (errcode == EBADF) {
355 if (reset || newpath) {
362 }
else if (dynpath ==
"") {
365 if (rdynpath ==
"") {
372 dynpath = path; dynpath +=
";"; dynpath += rdynpath;
390 if (signal_map[i].code == sig) {
391 (*signal_map[i].handler)((
ESignals)i);
402 signal_map[sig].handler = handler;
403 if (signal_map[sig].code != -1)
410 static const char *WinNTSigname(
ESignals sig)
412 return signal_map[sig].signame;
418 static BOOL ConsoleSigHandler(DWORD sig)
426 Break(
"TInterruptHandler::Notify",
"keyboard interrupt");
432 case CTRL_BREAK_EVENT:
433 case CTRL_LOGOFF_EVENT:
434 case CTRL_SHUTDOWN_EVENT:
435 case CTRL_CLOSE_EVENT:
437 printf(
"\n *** Break *** keyboard interrupt - ROOT is terminated\n");
443 static CONTEXT *fgXcptContext = 0;
457 LONG WINAPI ExceptionFilter(LPEXCEPTION_POINTERS pXcp)
459 fgXcptContext = pXcp->ContextRecord;
461 return EXCEPTION_CONTINUE_SEARCH;
465#pragma intrinsic(_ReturnAddress)
466#pragma auto_inline(off)
467 DWORD_PTR GetProgramCounter()
472#pragma auto_inline(on)
483 static DWORD WINAPI GUIThreadMessageProcessingLoop(
void *p)
488 ::PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
493 if (gGlobalEvent) ::SetEvent(gGlobalEvent);
494 erret = ::GetMessage(&msg, NULL, NULL, NULL);
495 if (erret <= 0) endLoop =
kTRUE;
496 if (gGUIThreadMsgFunc)
497 endLoop = (*gGUIThreadMsgFunc)(&msg);
504 erret = ::GetLastError();
505 Error(
"MsgLoop",
"Error in GetMessage");
519 typedef BOOL (__stdcall *SYMINITIALIZEPROC)( HANDLE, LPSTR, BOOL );
520 typedef BOOL (__stdcall *SYMCLEANUPPROC)( HANDLE );
521 typedef BOOL (__stdcall *STACKWALK64PROC)
522 ( DWORD, HANDLE, HANDLE, LPSTACKFRAME64, LPVOID,
523 PREAD_PROCESS_MEMORY_ROUTINE,PFUNCTION_TABLE_ACCESS_ROUTINE,
524 PGET_MODULE_BASE_ROUTINE, PTRANSLATE_ADDRESS_ROUTINE );
525 typedef LPVOID (__stdcall *SYMFUNCTIONTABLEACCESS64PROC)( HANDLE, DWORD64 );
526 typedef DWORD (__stdcall *SYMGETMODULEBASE64PROC)( HANDLE, DWORD64 );
527 typedef BOOL (__stdcall *SYMGETMODULEINFO64PROC)(HANDLE, DWORD64, PIMAGEHLP_MODULE64);
528 typedef BOOL (__stdcall *SYMGETSYMFROMADDR64PROC)( HANDLE, DWORD64, PDWORD64, PIMAGEHLP_SYMBOL64);
529 typedef BOOL (__stdcall *SYMGETLINEFROMADDR64PROC)(HANDLE, DWORD64, PDWORD, PIMAGEHLP_LINE64);
530 typedef DWORD (__stdcall *UNDECORATESYMBOLNAMEPROC)(PCSTR, PSTR, DWORD, DWORD);
533 static SYMINITIALIZEPROC _SymInitialize = 0;
534 static SYMCLEANUPPROC _SymCleanup = 0;
535 static STACKWALK64PROC _StackWalk64 = 0;
536 static SYMFUNCTIONTABLEACCESS64PROC _SymFunctionTableAccess64 = 0;
537 static SYMGETMODULEBASE64PROC _SymGetModuleBase64 = 0;
538 static SYMGETMODULEINFO64PROC _SymGetModuleInfo64 = 0;
539 static SYMGETSYMFROMADDR64PROC _SymGetSymFromAddr64 = 0;
540 static SYMGETLINEFROMADDR64PROC _SymGetLineFromAddr64 = 0;
541 static UNDECORATESYMBOLNAMEPROC _UnDecorateSymbolName = 0;
543 BOOL InitImagehlpFunctions()
551 HMODULE hModImagehlp = LoadLibrary(
"IMAGEHLP.DLL" );
555 _SymInitialize = (SYMINITIALIZEPROC) GetProcAddress( hModImagehlp,
"SymInitialize" );
559 _SymCleanup = (SYMCLEANUPPROC) GetProcAddress( hModImagehlp,
"SymCleanup" );
563 _StackWalk64 = (STACKWALK64PROC) GetProcAddress( hModImagehlp,
"StackWalk64" );
567 _SymFunctionTableAccess64 = (SYMFUNCTIONTABLEACCESS64PROC) GetProcAddress(hModImagehlp,
"SymFunctionTableAccess64" );
568 if (!_SymFunctionTableAccess64)
571 _SymGetModuleBase64=(SYMGETMODULEBASE64PROC)GetProcAddress(hModImagehlp,
"SymGetModuleBase64");
572 if (!_SymGetModuleBase64)
575 _SymGetModuleInfo64=(SYMGETMODULEINFO64PROC)GetProcAddress(hModImagehlp,
"SymGetModuleInfo64");
576 if (!_SymGetModuleInfo64)
579 _SymGetSymFromAddr64=(SYMGETSYMFROMADDR64PROC)GetProcAddress(hModImagehlp,
"SymGetSymFromAddr64");
580 if (!_SymGetSymFromAddr64)
583 _SymGetLineFromAddr64=(SYMGETLINEFROMADDR64PROC)GetProcAddress(hModImagehlp,
"SymGetLineFromAddr64");
584 if (!_SymGetLineFromAddr64)
587 _UnDecorateSymbolName=(UNDECORATESYMBOLNAMEPROC)GetProcAddress(hModImagehlp,
"UnDecorateSymbolName");
588 if (!_UnDecorateSymbolName)
591 if (!_SymInitialize(GetCurrentProcess(), 0,
TRUE ))
607 std::string GetModuleName(DWORD64 address)
611 std::ostringstream out;
612 HANDLE process = ::GetCurrentProcess();
614 DWORD lineDisplacement = 0;
615 IMAGEHLP_LINE64
line;
618 if(_SymGetLineFromAddr64(process, address, &lineDisplacement, &
line)) {
619 out <<
line.FileName <<
"(" <<
line.LineNumber <<
"): ";
624 if(_SymGetModuleInfo64(process, address, &
module)) {
625 out <<
module.ModuleName <<
"!";
627 out <<
"0x" << std::hex << address << std::dec <<
" ";
634 std::string GetFunctionName(DWORD64 address)
638 DWORD64 symbolDisplacement = 0;
639 HANDLE process = ::GetCurrentProcess();
641 const unsigned int SYMBOL_BUFFER_SIZE = 8192;
642 char symbolBuffer[SYMBOL_BUFFER_SIZE];
643 PIMAGEHLP_SYMBOL64 symbol =
reinterpret_cast<PIMAGEHLP_SYMBOL64
>(symbolBuffer);
644 ::ZeroMemory(symbol, SYMBOL_BUFFER_SIZE);
645 symbol->SizeOfStruct = SYMBOL_BUFFER_SIZE;
646 symbol->MaxNameLength = SYMBOL_BUFFER_SIZE -
sizeof(IMAGEHLP_SYMBOL64);
648 if(_SymGetSymFromAddr64(process, address, &symbolDisplacement, symbol)) {
650 const unsigned int NAME_SIZE = 8192;
651 char name[NAME_SIZE];
652 _UnDecorateSymbolName(
657 UNDNAME_NO_THISTYPE |
658 UNDNAME_NO_SPECIAL_SYMS |
659 UNDNAME_NO_MEMBER_TYPE |
660 UNDNAME_NO_MS_KEYWORDS |
661 UNDNAME_NO_ACCESS_SPECIFIERS
679 static BOOL IsShortcut(
const char *filename)
682 const char *extLnk =
".lnk";
683 if (filename != NULL) {
686 if (strfilename.EndsWith(extLnk))
695 static BOOL ResolveShortCut(LPCSTR pszShortcutFile,
char *pszPath,
int maxbuf)
699 char szGotPath[MAX_PATH];
706 typedef HRESULT (__stdcall *COINITIALIZEPROC)( LPVOID );
707 static COINITIALIZEPROC _CoInitialize = 0;
708 typedef void (__stdcall *COUNINITIALIZEPROC)(
void );
709 static COUNINITIALIZEPROC _CoUninitialize = 0;
710 typedef HRESULT (__stdcall *COCREATEINSTANCEPROC)( REFCLSID, LPUNKNOWN,
711 DWORD, REFIID, LPVOID );
712 static COCREATEINSTANCEPROC _CoCreateInstance = 0;
714 HMODULE hModImagehlp = LoadLibrary(
"ole32.dll" );
718 _CoInitialize = (COINITIALIZEPROC) GetProcAddress( hModImagehlp,
"CoInitialize" );
721 _CoUninitialize = (COUNINITIALIZEPROC) GetProcAddress( hModImagehlp,
"CoUninitialize");
722 if (!_CoUninitialize)
724 _CoCreateInstance = (COCREATEINSTANCEPROC) GetProcAddress( hModImagehlp,
"CoCreateInstance" );
725 if (!_CoCreateInstance)
730 hres = _CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
731 IID_IShellLink, (
void **) &psl);
732 if (SUCCEEDED(hres)) {
735 hres = psl->QueryInterface(IID_IPersistFile, (
void **) &ppf);
736 if (SUCCEEDED(hres)) {
738 MultiByteToWideChar(CP_ACP, 0, pszShortcutFile, -1, wsz, MAX_PATH);
740 hres = ppf->Load(wsz, STGM_READ);
741 if (SUCCEEDED(hres)) {
742 hres = psl->Resolve(HWND_DESKTOP, SLR_ANY_MATCH | SLR_NO_UI | SLR_UPDATE);
743 if (SUCCEEDED(hres)) {
744 strlcpy(szGotPath, pszShortcutFile,MAX_PATH);
745 hres = psl->GetPath(szGotPath, MAX_PATH, (WIN32_FIND_DATA *)&wfd,
746 SLGP_UNCPRIORITY | SLGP_RAWPATH);
747 strlcpy(pszPath,szGotPath, maxbuf);
748 if (maxbuf) pszPath[maxbuf-1] = 0;
757 return SUCCEEDED(hres);
763 if (strcmp(sys->TWinNTSystem::BaseName(buf),
"root.exe"))
766 if (!::RegOpenKeyEx(HKEY_CURRENT_USER,
"Software", 0, KEY_READ, ®CUS) == ERROR_SUCCESS)
769 if (!::RegOpenKeyEx(regCUS,
"Classes", 0, KEY_READ, ®CUSC) == ERROR_SUCCESS) {
770 ::RegCloseKey(regCUS);
775 bool regROOTwrite =
false;
779 if (::RegOpenKeyEx(regCUSC,
"ROOTDEV.ROOT", 0, KEY_READ, ®ROOT) != ERROR_SUCCESS) {
780 ::RegCloseKey(regCUSC);
781 if (::RegOpenKeyEx(regCUS,
"Classes", 0, KEY_READ | KEY_WRITE, ®CUSC) == ERROR_SUCCESS &&
782 ::RegCreateKeyEx(regCUSC,
"ROOTDEV.ROOT", 0, NULL, 0, KEY_READ | KEY_WRITE,
783 NULL, ®ROOT, NULL) == ERROR_SUCCESS) {
788 if (::RegOpenKeyEx(regROOT,
"DefaultIcon", 0, KEY_READ, ®ROOTIcon) == ERROR_SUCCESS) {
789 char bufIconLoc[1024];
791 DWORD dwSize =
sizeof(bufIconLoc);
793 if (::RegQueryValueEx(regROOTIcon, NULL, NULL, &dwType, (BYTE*)bufIconLoc, &dwSize) == ERROR_SUCCESS)
794 regROOTwrite = (iconloc != bufIconLoc);
797 ::RegCloseKey(regROOTIcon);
802 ::RegCloseKey(regCUSC);
803 ::RegCloseKey(regROOT);
804 if (::RegOpenKeyEx(regCUS,
"Classes", 0, KEY_READ | KEY_WRITE, ®CUSC) != ERROR_SUCCESS) {
806 regROOTwrite =
false;
808 if (::RegOpenKeyEx(regCUSC,
"ROOTDEV.ROOT", 0, KEY_WRITE, ®ROOT) != ERROR_SUCCESS) {
810 regROOTwrite =
false;
811 ::RegCloseKey(regCUSC);
818 TString fileopen =
"fileopen.C";
819 TString rootmacrodir =
"macros";
829 ::RegCloseKey(regROOT);
830 ::RegCloseKey(regCUSC);
831 ::RegCloseKey(regCUS);
835 static const char apptitle[] =
"ROOT data file";
836 ::RegSetValueEx(regROOT, NULL, 0, REG_SZ, (BYTE*)apptitle,
sizeof(apptitle));
837 DWORD editflags = 0x00010000;
838 ::RegSetValueEx(regROOT,
"EditFlags", 0, REG_DWORD, (BYTE*)&editflags,
sizeof(editflags));
841 if (::RegCreateKeyEx(regROOT,
"DefaultIcon", 0, NULL, 0, KEY_READ | KEY_WRITE,
842 NULL, ®ROOTIcon, NULL) == ERROR_SUCCESS) {
845 ::RegSetValueEx(regROOTIcon, NULL, 0, REG_SZ, (BYTE*)iconloc.Data(), iconloc.Length() + 1);
846 ::RegCloseKey(regROOTIcon);
851 if (::RegCreateKeyEx(regROOT,
"shell", 0, NULL, 0, KEY_READ | KEY_WRITE,
852 NULL, ®ROOTshell, NULL) == ERROR_SUCCESS) {
854 if (::RegCreateKeyEx(regROOTshell,
"open", 0, NULL, 0, KEY_READ | KEY_WRITE,
855 NULL, ®ShellOpen, NULL) == ERROR_SUCCESS) {
856 HKEY regShellOpenCmd;
857 if (::RegCreateKeyEx(regShellOpen,
"command", 0, NULL, 0, KEY_READ | KEY_WRITE,
858 NULL, ®ShellOpenCmd, NULL) == ERROR_SUCCESS) {
860 cmd +=
" -l \"%1\" \"";
863 ::RegSetValueEx(regShellOpenCmd, NULL, 0, REG_SZ, (BYTE*)cmd.Data(), cmd.Length() + 1);
864 ::RegCloseKey(regShellOpenCmd);
866 ::RegCloseKey(regShellOpen);
868 ::RegCloseKey(regROOTshell);
870 ::RegCloseKey(regROOT);
872 if (::RegCreateKeyEx(regCUSC,
".root", 0, NULL, 0, KEY_READ | KEY_WRITE,
873 NULL, ®ROOT, NULL) == ERROR_SUCCESS) {
874 static const char appname[] =
"ROOTDEV.ROOT";
875 ::RegSetValueEx(regROOT, NULL, 0, REG_SZ, (BYTE*)appname,
sizeof(appname));
877 ::RegCloseKey(regCUSC);
878 ::RegCloseKey(regCUS);
881 ::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
889 static bool once =
true;
892 if (!once ||
gROOT->IsBatch())
return false;
893 TString cmdline(::GetCommandLine());
894 Int_t i = 0, from = 0;
895 while (cmdline.Tokenize(arg, from,
" ")) {
897 if (i == 0 && ((arg !=
"root") && (arg !=
"rootn") &&
898 (arg !=
"root.exe") && (arg !=
"rootn.exe")))
return false;
899 else if ((arg ==
"-l") || (arg ==
"-b"))
return false;
911 static void SetConsoleWindowName()
913 char pszNewWindowTitle[1024];
914 char pszOldWindowTitle[1024];
916 CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
918 if (!::GetConsoleTitle(pszOldWindowTitle, 1024))
921 wsprintf(pszNewWindowTitle,
"%d/%d", ::GetTickCount(), ::GetCurrentProcessId());
923 if (!::SetConsoleTitle(pszNewWindowTitle))
933 ::SetConsoleTitle(
"ROOT session");
935 hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
938 ::SetConsoleMode(hStdout, ENABLE_PROCESSED_OUTPUT |
939 ENABLE_WRAP_AT_EOL_OUTPUT);
940 if (!::GetConsoleScreenBufferInfo(hStdout, &csbiInfo))
983 if (initwinsock = ::WSAStartup(MAKEWORD(2, 0), &WSAData)) {
984 Error(
"TWinNTSystem()",
"Starting sockets failed");
995 char *buf =
new char[MAX_MODULE_NAME32 + 1];
1001 HMODULE hModCore = ::GetModuleHandle(
"libCore.dll");
1004 char *pLibName = strstr(buf,
"libCore.dll");
1007 while (--pLibName >= buf && *pLibName !=
'\\' && *pLibName !=
'/');
1010 check_path +=
"\\etc";
1012 while (buf[0] && GetFileAttributes(check_path.
Data()) == INVALID_FILE_ATTRIBUTES) {
1013 while (--pLibName >= buf && *pLibName !=
'\\' && *pLibName !=
'/');
1016 check_path +=
"\\etc";
1031 UpdateRegistry(
this, buf);
1042 typedef UINT (WINAPI* LPTIMEENDPERIOD)( UINT uPeriod );
1043 HINSTANCE hInstWinMM = LoadLibrary(
"winmm.dll" );
1045 LPTIMEENDPERIOD pTimeEndPeriod = (LPTIMEENDPERIOD)GetProcAddress( hInstWinMM,
"timeEndPeriod" );
1046 if( NULL != pTimeEndPeriod )
1048 FreeLibrary(hInstWinMM);
1054 ::ResetEvent(gGlobalEvent);
1055 ::CloseHandle(gGlobalEvent);
1058 if (gTimerThreadHandle) {
1059 ::TerminateThread(gTimerThreadHandle, 0);
1060 ::CloseHandle(gTimerThreadHandle);
1093 ::SetUnhandledExceptionFilter(ExceptionFilter);
1101 typedef UINT (WINAPI* LPTIMEBEGINPERIOD)( UINT uPeriod );
1102 HINSTANCE hInstWinMM = LoadLibrary(
"winmm.dll" );
1104 LPTIMEBEGINPERIOD pTimeBeginPeriod = (LPTIMEBEGINPERIOD)GetProcAddress( hInstWinMM,
"timeBeginPeriod" );
1105 if( NULL != pTimeBeginPeriod )
1106 pTimeBeginPeriod(1);
1107 FreeLibrary(hInstWinMM);
1109 gTimerThreadHandle = ::CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)
ThreadStub,
1112 gGlobalEvent = ::CreateEvent(NULL,
TRUE,
FALSE, NULL);
1115 char *buf =
new char[MAX_MODULE_NAME32 + 1];
1116 HMODULE hModCore = ::GetModuleHandle(
"libCore.dll");
1119 char *pLibName = strstr(buf,
"libCore.dll");
1126 SetConsoleWindowName();
1150 const char *symbol=
name;
1153 while ( (*symbol ==
' ' || *symbol ==
'\t') && *symbol) symbol++;
1156 if (isalpha(symbol[idx]) && symbol[idx+1] ==
':') idx = 2;
1157 if ( (symbol[idx] ==
'/' || symbol[idx] ==
'\\') && symbol[idx+1] ==
'\0') {
1162 Error(
"BaseName",
"name = 0");
1166 char *bslash = (
char *)strrchr(&symbol[idx],
'\\');
1167 char *rslash = (
char *)strrchr(&symbol[idx],
'/');
1168 if (cp = (std::max)(rslash, bslash)) {
1173 return &symbol[idx];
1175 Error(
"BaseName",
"name = 0");
1186 char *dot =
nullptr;
1188 char *fullname =
nullptr;
1192 if (
name && namelen > 0) {
1194 fullname =
new char[namelen+5];
1195 strlcpy(fullname,
name,namelen+5);
1196 if ( !strrchr(fullname,
'.') )
1197 strlcat(fullname,
".exe",namelen+5);
1200 dot = strrchr(progname,
'.');
1201 idot = dot ? (
ULong_t)(dot - progname) : strlen(progname);
1203 char *which =
nullptr;
1206 which =
StrDup(fullname);
1217 dirname.
Form(
"%c:%s", driveletter,
d.Data());
1232 progname[idot] =
'\0';
1234 if (which)
delete [] which;
1238 if (::NeedSplash()) {
1251 if (err < 0 || err >= sys_nerr) {
1253 error_msg.
Form(
"errno out of range %d", err);
1256 return sys_errlist[err];
1269 DWORD il =
sizeof(hn);
1270 ::GetComputerName(hn, &il);
1286 if (freq < 37) freq = 440;
1287 if (duration < 0) duration = 100;
1296 gGUIThreadMsgFunc = func;
1319 int fd =
h->GetFd();
1322 if (
h->HasReadInterest()) {
1325 if (
h->HasWriteInterest()) {
1337 if (!
h)
return nullptr;
1357 set_console =
kTRUE;
1370 ::SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleSigHandler,
TRUE);
1381 if (!
h)
return nullptr;
1383 int sig =
h->GetSignal();
1396 ::SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleSigHandler,
FALSE);
1440 HANDLE snapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,::GetCurrentProcessId());
1445 if (!InitImagehlpFunctions()) {
1446 std::cerr <<
"No stack trace: cannot find (functions in) dbghelp.dll!" << std::endl;
1451 SYSTEM_INFO sysInfo;
1452 ::GetSystemInfo(&sysInfo);
1453 DWORD machineType = IMAGE_FILE_MACHINE_I386;
1454 switch (sysInfo.wProcessorArchitecture) {
1455 case PROCESSOR_ARCHITECTURE_AMD64:
1456 machineType = IMAGE_FILE_MACHINE_AMD64;
1458 case PROCESSOR_ARCHITECTURE_IA64:
1459 machineType = IMAGE_FILE_MACHINE_IA64;
1463 DWORD currentThreadID = ::GetCurrentThreadId();
1464 DWORD currentProcessID = ::GetCurrentProcessId();
1468 THREADENTRY32 threadentry;
1469 threadentry.dwSize =
sizeof(THREADENTRY32);
1470 if (!::Thread32First(snapshot, &threadentry))
return;
1472 std::cerr << std::endl <<
"==========================================" << std::endl;
1473 std::cerr <<
"=============== STACKTRACE ===============" << std::endl;
1474 std::cerr <<
"==========================================" << std::endl << std::endl;
1477 if (threadentry.th32OwnerProcessID != currentProcessID)
1479 HANDLE thread = ::OpenThread(THREAD_GET_CONTEXT|THREAD_SUSPEND_RESUME|THREAD_QUERY_INFORMATION,
1480 FALSE, threadentry.th32ThreadID);
1482 memset(&context, 0,
sizeof(CONTEXT));
1484 if (threadentry.th32ThreadID != currentThreadID) {
1485 ::SuspendThread(thread);
1486 context.ContextFlags = CONTEXT_ALL;
1487 ::GetThreadContext(thread, &context);
1488 ::ResumeThread(thread);
1490 if (fgXcptContext) {
1491 context = *fgXcptContext;
1493 typedef void (WINAPI *RTLCCTXT)(PCONTEXT);
1494 RTLCCTXT p2RtlCCtxt = (RTLCCTXT) ::GetProcAddress(
1495 GetModuleHandle(
"kernel32.dll"),
"RtlCaptureContext");
1497 context.ContextFlags = CONTEXT_ALL;
1498 p2RtlCCtxt(&context);
1504 ::ZeroMemory(&frame,
sizeof(frame));
1506 frame.AddrPC.Mode = AddrModeFlat;
1507 frame.AddrFrame.Mode = AddrModeFlat;
1508 frame.AddrStack.Mode = AddrModeFlat;
1510 frame.AddrPC.Offset = context.Eip;
1511 frame.AddrFrame.Offset = context.Ebp;
1512 frame.AddrStack.Offset = context.Esp;
1513#elif defined(_M_X64)
1514 frame.AddrPC.Offset = context.Rip;
1515 frame.AddrFrame.Offset = context.Rsp;
1516 frame.AddrStack.Offset = context.Rsp;
1517#elif defined(_M_IA64)
1518 frame.AddrPC.Offset = context.StIIP;
1519 frame.AddrFrame.Offset = context.IntSp;
1520 frame.AddrStack.Offset = context.IntSp;
1521 frame.AddrBStore.Offset= context.RsBSP;
1523 std::cerr <<
"Stack traces not supported on your architecture yet." << std::endl;
1528 while (_StackWalk64(machineType, (HANDLE)::GetCurrentProcess(), thread, (LPSTACKFRAME64)&frame,
1529 (LPVOID)&context, (PREAD_PROCESS_MEMORY_ROUTINE)NULL, (PFUNCTION_TABLE_ACCESS_ROUTINE)_SymFunctionTableAccess64,
1530 (PGET_MODULE_BASE_ROUTINE)_SymGetModuleBase64, NULL)) {
1532 std::cerr << std::endl <<
"================ Thread " << iThread++ <<
" ================" << std::endl;
1533 if (!bFirst || threadentry.th32ThreadID != currentThreadID) {
1534 const std::string moduleName = GetModuleName(frame.AddrPC.Offset);
1535 const std::string functionName = GetFunctionName(frame.AddrPC.Offset);
1536 std::cerr <<
" " << moduleName << functionName << std::endl;
1540 ::CloseHandle(thread);
1541 }
while (::Thread32Next(snapshot, &threadentry));
1543 std::cerr << std::endl <<
"==========================================" << std::endl;
1544 std::cerr <<
"============= END STACKTRACE =============" << std::endl;
1545 std::cerr <<
"==========================================" << std::endl << std::endl;
1546 ::CloseHandle(snapshot);
1547 _SymCleanup(GetCurrentProcess());
1556 UInt_t oldmask = _statusfp( );
1558 if (oldmask & _EM_INVALID ) mask |=
kInvalid;
1559 if (oldmask & _EM_ZERODIVIDE) mask |=
kDivByZero;
1560 if (oldmask & _EM_OVERFLOW ) mask |=
kOverflow;
1561 if (oldmask & _EM_UNDERFLOW) mask |=
kUnderflow;
1562 if (oldmask & _EM_INEXACT ) mask |=
kInexact;
1576 if (mask &
kInvalid ) newm |= _EM_INVALID;
1577 if (mask &
kDivByZero) newm |= _EM_ZERODIVIDE;
1578 if (mask &
kOverflow ) newm |= _EM_OVERFLOW;
1579 if (mask &
kUnderflow) newm |= _EM_UNDERFLOW;
1580 if (mask &
kInexact ) newm |= _EM_INEXACT;
1584 ::_controlfp(
cm , _MCW_EM);
1603 if (pendingOnly && gGlobalEvent) ::SetEvent(gGlobalEvent);
1605 Bool_t pollOnce = pendingOnly;
1609 if (
gROOT->GetApplication()) {
1625 ::WaitForSingleObject(gGlobalEvent, 1);
1626 ::ResetEvent(gGlobalEvent);
1652 if (pendingOnly && !pollOnce)
1691 if (!pendingOnly && gGlobalEvent) {
1692 ::WaitForSingleObject(gGlobalEvent, 1);
1693 ::ResetEvent(gGlobalEvent);
1707 for (i = 0; i <
fReadmask->GetCount(); i++) {
1712 rc = WinNTSelect(&t, 0, 0);
1713 if (rc < 0 && rc != -2) {
1714 ::SysError(
"DispatchOneEvent",
"select: read error on %d\n", fd);
1720 for (i = 0; i <
fWritemask->GetCount(); i++) {
1726 rc = WinNTSelect(0, &t, 0);
1727 if (rc < 0 && rc != -2) {
1728 ::SysError(
"DispatchOneEvent",
"select: write error on %d\n", fd);
1790 if (sync == sh->
IsSync()) {
1792 if ((
fSignals->IsSet(sig) && sigdone == -1) || sigdone == sig) {
1793 if (sigdone == -1) {
1803 if (sigdone != -1)
return kTRUE;
1824 if ((
fReadready->IsSet(fd) && fddone == -1) ||
1825 (fddone == fd && read)) {
1835 (fddone == fd && !read)) {
1845 if (fddone != -1)
return kTRUE;
1862 if (dirname.
Length() == 0) {
1879 if (res)
return res;
1899 const char *
proto = (strstr(
name,
"file:///")) ?
"file://" :
"file:";
1902 if (!
name)
return 0;
1906 if (!
name)
return 0;
1938 HANDLE searchFile = (HANDLE)dirp;
1972 return (psz[0] == TEXT(
'\\') && psz[1] == TEXT(
'\\'));
1992#pragma data_seg(".text", "CODE")
2007 if (!IsDBCSLeadByte(*pPath)) {
2012 if ((*pPath == TEXT(
'\\')) && (*(pPath + 1) == 0))
2018 int cBackslashes = 0;
2019 for (p = pPath + 2; *p; p = CharNext(p)) {
2020 if (*p == TEXT(
'\\') && (++cBackslashes > 1))
2040 const char *
proto = (strstr(fdir,
"file:///")) ?
"file://" :
"file:";
2043 char *dir =
new char[MAX_PATH];
2044 if (IsShortcut(sdir)) {
2045 if (!ResolveShortCut(sdir, dir, MAX_PATH))
2046 strlcpy(dir, sdir,MAX_PATH);
2049 strlcpy(dir, sdir,MAX_PATH);
2051 int nche = strlen(dir)+3;
2052 char *entry =
new char[nche];
2053 struct _stati64 finfo;
2056 strlcpy(entry, dir,nche);
2057 if ((entry[strlen(dir)-1] ==
'/') || (entry[strlen(dir)-1] ==
'\\' )) {
2058 entry[strlen(dir)-1] =
'\0';
2061 strlcat(entry,
"\\",nche);
2063 if (_stati64(entry, &finfo) < 0) {
2069 strlcpy(entry, dir,nche);
2070 if ((entry[strlen(dir)-1] ==
'/') || (entry[strlen(dir)-1] ==
'\\' )) {
2072 entry[strlen(dir)-1] =
'\0';
2074 if (_stati64(entry, &finfo) < 0) {
2081 if (finfo.st_mode & S_IFDIR) {
2082 strlcpy(entry, dir,nche);
2083 if (!(entry[strlen(dir)-1] ==
'/' || entry[strlen(dir)-1] ==
'\\' )) {
2084 strlcat(entry,
"\\",nche);
2086 if (entry[strlen(dir)-1] ==
' ')
2087 entry[strlen(dir)-1] =
'\0';
2088 strlcat(entry,
"*",nche);
2156 char *wdpath =
nullptr;
2157 char drive = driveletter ? toupper( driveletter ) -
'A' + 1 : 0;
2163 if (!(wdpath = ::_getdcwd( (
int)drive, wdpath,
kMAXPATHLEN))) {
2165 Warning(
"WorkingDirectory",
"getcwd() failed");
2189 return std::string(mydir);
2197 const char *
h =
nullptr;
2198 if (!(
h = ::getenv(
"home")))
h = ::getenv(
"HOME");
2205 h = ::getenv(
"HOMESHARE");
2206 if (!
h)
h = ::getenv(
"HOMEDRIVE");
2209 h = ::getenv(
"HOMEPATH");
2214 h = ::getenv(
"USERPROFILE");
2219 if (mydir[1] ==
':')
2220 mydir[0] = toupper(mydir[0]);
2236 if (!dir) dir =
"c:\\";
2252 char tmpName[MAX_PATH];
2256 FILE *fp = fopen(tmpName,
"w+");
2258 if (!fp)
::SysError(
"TempFileName",
"error opening %s", tmpName);
2276 if (!opt || !opt[0]) {
2281 UINT nOldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS);
2285 curdrive = _getdrive();
2286 if (strstr(opt,
"cur")) {
2288 sDrive.
Form(
"%c:", (curdrive +
'A' - 1));
2289 sType.
Form(
"Unknown Drive (%s)", sDrive.
Data());
2290 ::GetVolumeInformation(
Form(
"%s\\", sDrive.
Data()), NULL, 0, NULL, NULL,
2291 NULL, (LPSTR)szFs, 32);
2292 type = ::GetDriveType(sDrive.
Data());
2295 case DRIVE_NO_ROOT_DIR:
2297 case DRIVE_REMOVABLE:
2298 sType.
Form(
"Removable Disk (%s)", sDrive.
Data());
2301 sType.
Form(
"Local Disk (%s)", sDrive.
Data());
2304 sType.
Form(
"Network Drive (%s) (%s)", szFs, sDrive.
Data());
2307 sType.
Form(
"CD/DVD Drive (%s)", sDrive.
Data());
2310 sType.
Form(
"RAM Disk (%s)", sDrive.
Data());
2315 else if (strstr(opt,
"all")) {
2318 if (::GetLogicalDriveStrings(511, szTemp)) {
2319 TCHAR szDrive[3] = TEXT(
" :");
2325 sDrive.
Form(
"%s", szDrive);
2327 if ((sDrive ==
"A:") || (sDrive ==
"B:")) {
2331 sType.
Form(
"Unknown Drive (%s)", sDrive.
Data());
2332 ::GetVolumeInformation(
Form(
"%s\\", sDrive.
Data()), NULL, 0, NULL,
2333 NULL, NULL, (LPSTR)szFs, 32);
2334 type = ::GetDriveType(sDrive.
Data());
2337 case DRIVE_NO_ROOT_DIR:
2339 case DRIVE_REMOVABLE:
2340 sType.
Form(
"Removable Disk (%s)", sDrive.
Data());
2343 sType.
Form(
"Local Disk (%s)", sDrive.
Data());
2346 sType.
Form(
"Network Drive (%s) (%s)", szFs, sDrive.
Data());
2349 sType.
Form(
"CD/DVD Drive (%s)", sDrive.
Data());
2352 sType.
Form(
"RAM Disk (%s)", sDrive.
Data());
2362 ::SetErrorMode(nOldErrorMode);
2385 if (strchr(pathname,
'/') || strchr(pathname,
'\\')) {
2386 const char *rslash = strrchr(pathname,
'/');
2387 const char *bslash = strrchr(pathname,
'\\');
2388 const char *
r = std::max(rslash, bslash);
2389 const char *ptr = pathname;
2399 int len =
r - pathname;
2401 return TString(pathname, len);
2424 if (!pathname)
return 0;
2425 if (!pathname[0])
return 0;
2431 while(*lpchar ==
' ') lpchar++;
2433 if (isalpha((
int)*lpchar) && *(lpchar+1) ==
':') {
2437 if ( (*lpchar ==
'\\' || *lpchar ==
'/' ) &&
2438 (*(lpchar+1) ==
'\\' || *(lpchar+1) ==
'/') )
return 0;
2451 if (strchr(dir,
':')) idx = 2;
2452 return (dir[idx] ==
'/' || dir[idx] ==
'\\');
2485 const int kBufSize = 1024;
2486 TTHREAD_TLS_ARRAY(
char, kBufSize, temp);
2488 strlcpy(temp,
name, kBufSize);
2489 char *currentChar = temp;
2492 while (*currentChar !=
'\0') {
2493 if (*currentChar ==
'\\') *currentChar =
'/';
2511 UINT nOldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS);
2515 const char *
proto = (strstr(path,
"file:///")) ?
"file://" :
"file:";
2518 ::SetErrorMode(nOldErrorMode);
2523 ::SetErrorMode(nOldErrorMode);
2546 if (dir && dir[0]) {
2548 char last = dir[strlen(dir) - 1];
2549 if (last !=
'/' && last !=
'\\') {
2553 name.ReplaceAll(
"/",
"\\");
2570 if (!ret)
return -1;
2579 int ret = ::rename(
f, t);
2596 struct _stati64 sbuf;
2599 const char *
proto = (strstr(path,
"file:///")) ?
"file://" :
"file:";
2601 int l = strlen(newpath);
2603 if (newpath[--
l] !=
'\\' || newpath[--
l] !=
'/') {
2609 if (newpath && ::_stati64(newpath, &sbuf) >= 0) {
2611 buf.
fDev = sbuf.st_dev;
2612 buf.
fIno = sbuf.st_ino;
2613 buf.
fMode = sbuf.st_mode;
2614 buf.
fUid = sbuf.st_uid;
2615 buf.
fGid = sbuf.st_gid;
2616 buf.
fSize = sbuf.st_size;
2617 buf.
fMtime = sbuf.st_mtime;
2618 buf.
fIsLink = IsShortcut(newpath);
2620 char *lpath =
new char[MAX_PATH];
2621 if (IsShortcut(newpath)) {
2622 struct _stati64 sbuf2;
2623 if (ResolveShortCut(newpath, lpath, MAX_PATH)) {
2624 if (::_stati64(lpath, &sbuf2) >= 0) {
2625 buf.
fMode = sbuf2.st_mode;
2651 LPCTSTR lpRootPathName = path;
2654 LPTSTR lpVolumeNameBuffer = 0;
2655 DWORD nVolumeNameSize = 0;
2657 DWORD volumeSerialNumber;
2658 DWORD maximumComponentLength;
2661 DWORD fileSystemFlags;
2664 char fileSystemNameBuffer[512];
2665 DWORD nFileSystemNameSize =
sizeof(fileSystemNameBuffer);
2668 UINT nOldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS);
2669 if (!::GetVolumeInformation(lpRootPathName,
2670 lpVolumeNameBuffer, nVolumeNameSize,
2671 &volumeSerialNumber,
2672 &maximumComponentLength,
2674 fileSystemNameBuffer, nFileSystemNameSize)) {
2676 ::SetErrorMode(nOldErrorMode);
2680 const char *fsNames[] = {
"FAT",
"NTFS" };
2682 for (i = 0; i < 2; i++) {
2683 if (!strncmp(fileSystemNameBuffer, fsNames[i], nFileSystemNameSize))
2688 DWORD sectorsPerCluster;
2689 DWORD bytesPerSector;
2690 DWORD numberOfFreeClusters;
2691 DWORD totalNumberOfClusters;
2693 if (!::GetDiskFreeSpace(lpRootPathName,
2696 &numberOfFreeClusters,
2697 &totalNumberOfClusters)) {
2699 ::SetErrorMode(nOldErrorMode);
2703 ::SetErrorMode(nOldErrorMode);
2705 *bsize = sectorsPerCluster * bytesPerSector;
2706 *blocks = totalNumberOfClusters;
2707 *bfree = numberOfFreeClusters;
2717 struct _stati64 finfo;
2722 char linkname[1024];
2723 LPTSTR lpszFilePart;
2724 TCHAR szPath[MAX_PATH];
2727 typedef BOOL (__stdcall *CREATEHARDLINKPROC)( LPCTSTR, LPCTSTR, LPSECURITY_ATTRIBUTES );
2728 static CREATEHARDLINKPROC _CreateHardLink = 0;
2730 HMODULE hModImagehlp = LoadLibrary(
"Kernel32.dll" );
2735 _CreateHardLink = (CREATEHARDLINKPROC) GetProcAddress( hModImagehlp,
"CreateHardLinkW" );
2737 _CreateHardLink = (CREATEHARDLINKPROC) GetProcAddress( hModImagehlp,
"CreateHardLinkA" );
2739 if (!_CreateHardLink)
2742 dwRet = GetFullPathName(from,
sizeof(szPath) /
sizeof(TCHAR),
2743 szPath, &lpszFilePart);
2745 if (_stati64(szPath, &finfo) < 0)
2748 if (finfo.st_mode & S_IFDIR)
2752 _splitpath(linkname,winDrive,winDir,winName,winExt);
2753 if ((!winDrive[0] ) &&
2755 _splitpath(szPath,winDrive,winDir,winName,winExt);
2756 snprintf(linkname,1024,
"%s\\%s\\%s", winDrive, winDir, to);
2758 else if (!winDrive[0]) {
2759 _splitpath(szPath,winDrive,winDir,winName,winExt);
2760 snprintf(linkname,1024,
"%s\\%s", winDrive, to);
2763 if (!_CreateHardLink(linkname, szPath, NULL))
2776 IShellLink* pShellLink;
2777 IPersistFile* pPersistFile;
2778 WCHAR wszLinkfile[MAX_PATH];
2779 int iWideCharsWritten;
2781 LPTSTR lpszFilePart;
2782 TCHAR szPath[MAX_PATH];
2784 hRes = E_INVALIDARG;
2785 if ((from == NULL) || (!from[0]) || (to == NULL) ||
2791 typedef HRESULT (__stdcall *COINITIALIZEPROC)( LPVOID );
2792 static COINITIALIZEPROC _CoInitialize = 0;
2793 typedef void (__stdcall *COUNINITIALIZEPROC)(
void );
2794 static COUNINITIALIZEPROC _CoUninitialize = 0;
2795 typedef HRESULT (__stdcall *COCREATEINSTANCEPROC)( REFCLSID, LPUNKNOWN, DWORD, REFIID, LPVOID );
2796 static COCREATEINSTANCEPROC _CoCreateInstance = 0;
2798 HMODULE hModImagehlp = LoadLibrary(
"ole32.dll" );
2802 _CoInitialize = (COINITIALIZEPROC) GetProcAddress( hModImagehlp,
"CoInitialize" );
2805 _CoUninitialize = (COUNINITIALIZEPROC) GetProcAddress( hModImagehlp,
"CoUninitialize" );
2806 if (!_CoUninitialize)
2808 _CoCreateInstance = (COCREATEINSTANCEPROC) GetProcAddress( hModImagehlp,
"CoCreateInstance" );
2809 if (!_CoCreateInstance)
2816 _CoInitialize(NULL);
2819 dwRet = GetFullPathName(from,
sizeof(szPath) /
sizeof(TCHAR),
2820 szPath, &lpszFilePart);
2821 hRes = _CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
2822 IID_IShellLink, (LPVOID *)&pShellLink);
2823 if (SUCCEEDED(hRes)) {
2825 hRes = pShellLink->SetPath(szPath);
2827 hRes = pShellLink->QueryInterface(IID_IPersistFile, (
void **)&pPersistFile);
2828 if (SUCCEEDED(hRes)){
2829 iWideCharsWritten = MultiByteToWideChar(CP_ACP, 0, linkname.
Data(), -1,
2830 wszLinkfile, MAX_PATH);
2831 hRes = pPersistFile->Save(wszLinkfile,
TRUE);
2832 pPersistFile->Release();
2834 pShellLink->Release();
2852 struct _stati64 finfo;
2854 if (_stati64(
name, &finfo) < 0) {
2858 if (finfo.st_mode & S_IFDIR) {
2859 return ::_rmdir(
name);
2861 return ::_unlink(
name);
2870 if (::ioctlsocket(fd, FIONBIO, (u_long *)1) == SOCKET_ERROR) {
2889 const char *patbuf = (
const char *)patbuf0;
2891 char *cmd =
nullptr;
2897 const char driveletter =
DriveName(patbuf);
2906 if (!
proto.EqualTo(
"file"))
2914 while (*patbuf ==
' ') {
2919 while (*patbuf ==
':') {
2924 while (*patbuf ==
';') {
2930 for (
q = (
char*)patbuf; *
q;
q++) {
2934 if ( (((
q-2)>patbuf) && ( (*(
q-2)!=
';') || !isalpha(*(
q-1)) )) &&
2941 for (p = patbuf; *p; p++) {
2958 char replacement[4];
2961 for (
int k = 0; k<3; k++) replacement[k] = 0x1;
2963 replacement[3] = 0x0;
2967 while ( (pos = patbuf0.
Index(TildaNum,pos)) !=
kNPOS ) {
2968 patbuf0.
Replace(pos, 1, replacement);
2974 Int_t lbuf = ::ExpandEnvironmentStrings(
2980 cmd =
new char[lbuf+1];
2981 ::ExpandEnvironmentStrings(
3000 char newpath[MAX_PATH];
3001 if (IsShortcut(path)) {
3002 if (!ResolveShortCut(path, newpath, MAX_PATH))
3003 strlcpy(newpath, path, MAX_PATH);
3006 strlcpy(newpath, path, MAX_PATH);
3022 return ::_chmod(
file, mode);
3030 return ::umask(mask);
3040 Error(
"Utime",
"need write permission for %s to change utime",
file);
3043 if (!actime) actime = modtime;
3046 t.actime = (time_t)actime;
3047 t.modtime = (time_t)modtime;
3048 return ::utime(
file, &t);
3067 return infile.
Data();
3075 Int_t lastDelim = -1;
3076 for(
int i=0; i < exsearch.
Length(); ++i) {
3077 switch( exsearch[i] ) {
3080 if (i-lastDelim!=2) exsearch[i] =
';';
3083 case ';': lastDelim = i;
break;
3090 char *lpFilePart =
nullptr;
3092 ::access(
name, mode) == 0 && stat(
name, &finfo) == 0 &&
3093 finfo.st_mode & S_IFREG) {
3098 return infile.
Data();
3112 if ((
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) && (::GetVersion() < 0x80000000)) {
3115 HINSTANCE netapi = ::LoadLibrary(
"netapi32.DLL");
3116 if (!netapi)
return kFALSE;
3118 p2NetApiBufferFree = (pfn1)::GetProcAddress(netapi,
"NetApiBufferFree");
3119 p2NetUserGetInfo = (pfn2)::GetProcAddress(netapi,
"NetUserGetInfo");
3120 p2NetLocalGroupGetMembers = (pfn3)::GetProcAddress(netapi,
"NetLocalGroupGetMembers");
3121 p2NetLocalGroupEnum = (pfn4)::GetProcAddress(netapi,
"NetLocalGroupEnum");
3123 if (!p2NetApiBufferFree || !p2NetUserGetInfo ||
3124 !p2NetLocalGroupGetMembers || !p2NetLocalGroupEnum)
return kFALSE;
3135 ::FreeLibrary(netapi);
3145 NET_API_STATUS NetStatus = NERR_Success;
3147 DWORD
Index = 0, ResumeHandle = 0, Total = 0;
3148 LOCALGROUP_MEMBERS_INFO_1 *MemberInfo;
3149 WCHAR wszGroupName[256];
3151 DWORD dwLastError = 0;
3153 iRetOp = MultiByteToWideChar (
3155 (DWORD)MB_PRECOMPOSED,
3156 (LPCSTR)lpszGroupName,
3158 (LPWSTR)wszGroupName,
3159 (
int)
sizeof(wszGroupName) );
3162 dwLastError = GetLastError();
3164 p2NetApiBufferFree(Data);
3170 NetStatus = p2NetLocalGroupGetMembers (NULL, wszGroupName, 1,
3171 &Data, 8192, &
Index, &Total, &ResumeHandle );
3173 if (NetStatus != NERR_Success || Data == NULL) {
3174 dwLastError = GetLastError();
3176 if (dwLastError == ERROR_ENVVAR_NOT_FOUND) {
3182 NetStatus = p2NetLocalGroupGetMembers ( NULL, wszGroupName, 0,
3183 &Data, 8192, &
Index, &Total, &ResumeHandle );
3187 p2NetApiBufferFree(Data);
3192 MemberInfo = (LOCALGROUP_MEMBERS_INFO_1 *)Data;
3195 p2NetApiBufferFree(Data);
3204 NET_API_STATUS NetStatus = NERR_Success;
3206 DWORD
Index = 0, ResumeHandle = 0, Total = 0, i;
3207 LOCALGROUP_INFO_0 *GroupInfo;
3208 char szAnsiName[256];
3209 DWORD dwLastError = 0;
3212 NetStatus = p2NetLocalGroupEnum(NULL, 0, &Data, 8192, &
Index,
3213 &Total, &ResumeHandle );
3215 if (NetStatus != NERR_Success || Data == NULL) {
3216 dwLastError = GetLastError();
3218 p2NetApiBufferFree(Data);
3223 GroupInfo = (LOCALGROUP_INFO_0 *)Data;
3224 for (i=0; i < Total; i++) {
3226 iRetOp = WideCharToMultiByte (
3229 (LPCWSTR)(GroupInfo->lgrpi0_name),
3232 (
int)(
sizeof(szAnsiName)),
3244 p2NetApiBufferFree(Data);
3256 int &groupIdx,
int &memberIdx)
3258 BOOL bRetOp =
FALSE;
3260 DWORD dwSidSize, dwDomainNameSize;
3263 SID_NAME_USE sidType;
3264 PUCHAR puchar_SubAuthCount = NULL;
3265 SID_IDENTIFIER_AUTHORITY sid_identifier_authority;
3266 PSID_IDENTIFIER_AUTHORITY psid_identifier_authority = NULL;
3267 unsigned char j = 0;
3268 DWORD dwLastError = 0;
3270 pSid = (PSID)bySidBuffer;
3271 dwSidSize =
sizeof(bySidBuffer);
3272 dwDomainNameSize =
sizeof(szDomainName);
3274 bRetOp = LookupAccountName (
3276 (LPCTSTR)lpszAccountName,
3278 (LPDWORD)&dwSidSize,
3279 (LPTSTR)szDomainName,
3280 (LPDWORD)&dwDomainNameSize,
3281 (PSID_NAME_USE)&sidType );
3283 if (bRetOp ==
FALSE) {
3284 dwLastError = GetLastError();
3288 bRetOp = IsValidSid((PSID)pSid);
3290 if (bRetOp ==
FALSE) {
3291 dwLastError = GetLastError();
3296 psid_identifier_authority = GetSidIdentifierAuthority ((PSID)pSid);
3299 memcpy (&sid_identifier_authority, psid_identifier_authority,
3300 sizeof(SID_IDENTIFIER_AUTHORITY));
3303 puchar_SubAuthCount = (PUCHAR)GetSidSubAuthorityCount((PSID)pSid);
3305 j = (
unsigned char)(*puchar_SubAuthCount);
3307 DWORD dwSubAuth = 0;
3308 PDWORD pdwSubAuth = NULL;
3310 pdwSubAuth = (PDWORD)GetSidSubAuthority (
3313 dwSubAuth = *pdwSubAuth;
3332 NET_API_STATUS NetStatus = NERR_Success;
3334 DWORD
Index = 0, ResumeHandle = 0, Total = 0, i;
3335 LOCALGROUP_MEMBERS_INFO_1 *MemberInfo;
3336 char szAnsiMemberName[256];
3337 char szFullMemberName[256];
3338 char szMemberHomeDir[256];
3339 WCHAR wszGroupName[256];
3342 DWORD length =
sizeof (act_name);
3343 DWORD dwLastError = 0;
3344 LPUSER_INFO_11 pUI11Buf = NULL;
3345 NET_API_STATUS nStatus;
3347 iRetOp = MultiByteToWideChar (
3349 (DWORD)MB_PRECOMPOSED,
3350 (LPCSTR)lpszGroupName,
3352 (LPWSTR)wszGroupName,
3353 (
int)
sizeof(wszGroupName) );
3356 dwLastError = GetLastError();
3358 p2NetApiBufferFree(Data);
3362 GetUserName (act_name, &length);
3366 NetStatus = p2NetLocalGroupGetMembers (NULL, wszGroupName, 1,
3367 &Data, 8192, &
Index, &Total, &ResumeHandle );
3369 if (NetStatus != NERR_Success || Data == NULL) {
3370 dwLastError = GetLastError();
3372 if (dwLastError == ERROR_ENVVAR_NOT_FOUND) {
3378 NetStatus = p2NetLocalGroupGetMembers ( NULL, wszGroupName, 0,
3379 &Data, 8192, &
Index, &Total, &ResumeHandle );
3383 p2NetApiBufferFree(Data);
3387 MemberInfo = (LOCALGROUP_MEMBERS_INFO_1 *)Data;
3388 for (i=0; i < Total; i++) {
3389 iRetOp = WideCharToMultiByte (
3392 (LPCWSTR)(MemberInfo->lgrmi1_name),
3394 (LPSTR)szAnsiMemberName,
3395 (
int)(
sizeof(szAnsiMemberName)),
3400 dwLastError = GetLastError();
3411 TCHAR szUserName[255]=TEXT(
"");
3412 MultiByteToWideChar(CP_ACP, 0, szAnsiMemberName, -1, (LPWSTR)szUserName, 255);
3416 nStatus = p2NetUserGetInfo(NULL, (LPCWSTR)szUserName, 11, (LPBYTE *)&pUI11Buf);
3420 if (nStatus == NERR_Success) {
3421 if (pUI11Buf != NULL) {
3422 wsprintf(szFullMemberName,
"%S",pUI11Buf->usri11_full_name);
3424 wsprintf(szMemberHomeDir,
"%S",pUI11Buf->usri11_home_dir);
3435 if (pUI11Buf != NULL) {
3436 p2NetApiBufferFree(pUI11Buf);
3441 if (getenv(
"SHELL") == NULL)
3442 putenv ((GetVersion () & 0x80000000) ?
"SHELL=command" :
"SHELL=cmd");
3455 p2NetApiBufferFree(Data);
3465 NET_API_STATUS NetStatus = NERR_Success;
3467 DWORD
Index = 0, ResumeHandle = 0, Total = 0, i;
3468 LOCALGROUP_INFO_0 *GroupInfo;
3469 char szAnsiName[256];
3470 DWORD dwLastError = 0;
3471 int iRetOp = 0, iGroupIdx = 0, iMemberIdx = 0;
3473 NetStatus = p2NetLocalGroupEnum(NULL, 0, &Data, 8192, &
Index,
3474 &Total, &ResumeHandle );
3476 if (NetStatus != NERR_Success || Data == NULL) {
3477 dwLastError = GetLastError();
3479 p2NetApiBufferFree(Data);
3483 GroupInfo = (LOCALGROUP_INFO_0 *)Data;
3484 for (i=0; i < Total; i++) {
3486 iRetOp = WideCharToMultiByte (
3489 (LPCWSTR)(GroupInfo->lgrpi0_name),
3492 (
int)(
sizeof(szAnsiName)),
3510 p2NetApiBufferFree(Data);
3524 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3527 DWORD length =
sizeof (
name);
3528 if (::GetUserName (
name, &length)) {
3529 if (stricmp (
"administrator",
name) == 0)
3539 if (!user || !user[0])
3565 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3568 DWORD length =
sizeof (
name);
3569 if (::GetUserName (
name, &length)) {
3570 if (stricmp (
"administrator",
name) == 0)
3592 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3595 DWORD length =
sizeof (
name);
3596 if (::GetUserName (
name, &length)) {
3597 if (stricmp (
"administrator",
name) == 0)
3610 struct group *grp =
nullptr;
3633 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3636 DWORD length =
sizeof (
name);
3637 if (::GetUserName (
name, &length)) {
3638 if (stricmp (
"administrator",
name) == 0)
3661 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3663 DWORD length =
sizeof (
name);
3665 if (::GetUserName (
name, &length)) {
3667 if (stricmp (
"administrator",
name) == 0) {
3669 ug->
fGroup =
"administrators";
3678 ug->
fUser =
"unknown";
3691 for (
int i = 0; i <
fNbUsers; i++) {
3735 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3737 DWORD length =
sizeof (
name);
3739 if (::GetUserName (
name, &length)) {
3740 if (stricmp (
"administrator",
name) == 0) {
3741 gr->fGroup =
"administrators";
3745 gr->fGroup =
"users";
3750 gr->fGroup =
"unknown";
3756 struct group *grp =
nullptr;
3800 const char *env = ::getenv(
name);
3802 if (::_stricmp(
name,
"home") == 0 ) {
3804 }
else if (::_stricmp(
name,
"rootsys") == 0 ) {
3818 return ::system(shellcmd);
3826 return ::_popen(command, mode);
3834 return ::_pclose(pipe);
3862 gROOT->CloseFiles();
3863 if (
gROOT->GetListOfBrowsers()) {
3866 if (
gROOT->IsBatch())
3867 gROOT->GetListOfBrowsers()->Delete();
3873 if (((TBrowser*)0x%lx)->GetBrowserImp() &&\
3874 ((TBrowser*)0x%lx)->GetBrowserImp()->GetMainFrame()) \
3875 ((TBrowser*)0x%lx)->GetBrowserImp()->GetMainFrame()->CloseWindow();\
3879 gROOT->EndOfProcessCleanups();
3920 static int fd1=0, fd2=0;
3921 static fpos_t pos1=0, pos2=0;
3931 const char *
m = (mode[0] ==
'a' || mode[0] ==
'w') ? mode :
"a";
3944 fgetpos(stdout, &pos1);
3945 fd1 = _dup(fileno(stdout));
3947 if ((fout = freopen(
file,
m, stdout)) == 0) {
3948 SysError(
"RedirectOutput",
"could not freopen stdout");
3950 _dup2(fd1, fileno(stdout));
3954 fsetpos(stdout, &pos1);
3959 fgetpos(stderr, &pos2);
3960 fd2 = _dup(fileno(stderr));
3961 if ((ferr = freopen(
file,
m, stderr)) == 0) {
3962 SysError(
"RedirectOutput",
"could not freopen stderr");
3964 _dup2(fd1, fileno(stdout));
3968 fsetpos(stdout, &pos1);
3970 _dup2(fd2, fileno(stderr));
3974 fsetpos(stderr, &pos2);
3979 fseek(fout, 0, SEEK_END);
3980 fseek(ferr, 0, SEEK_END);
3987 if (_dup2(fd1, fileno(stdout))) {
3988 SysError(
"RedirectOutput",
"could not restore stdout");
3994 fsetpos(stdout, &pos1);
4001 if (_dup2(fd2, fileno(stderr))) {
4002 SysError(
"RedirectOutput",
"could not restore stderr");
4008 fsetpos(stderr, &pos2);
4063 if (len > 4 && (!stricmp(sLib.
Data()+len-4,
".dll"))) {
4076 Error(
"DynamicPathName",
4077 "%s does not exist in %s,\nor has wrong file extension (.dll)",
4094#pragma warning(push)
4095#pragma warning(disable:4200)
4112 if (!linkedLibs.
IsNull())
4125 HANDLE hFile, hMapping;
4128 if((hFile = CreateFile(exe,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0))==
INVALID_HANDLE_VALUE) {
4132 if(!(hMapping = CreateFileMapping(hFile,0,PAGE_READONLY|SEC_COMMIT,0,0,0))) {
4137 if(!(basepointer = MapViewOfFile(hMapping,FILE_MAP_READ,0,0,0))) {
4138 CloseHandle(hMapping);
4145 IMAGE_DOS_HEADER *dos_head = (IMAGE_DOS_HEADER *)basepointer;
4148 IMAGE_FILE_HEADER _head;
4149 IMAGE_OPTIONAL_HEADER opt_head;
4150 IMAGE_SECTION_HEADER section_header[];
4152 struct header *pheader;
4153 const IMAGE_SECTION_HEADER * section_header;
4155 if(dos_head->e_magic!=
'ZM') {
4160 pheader = (
struct header *)((
char*)dos_head + dos_head->e_lfanew);
4162 if(IsBadReadPtr(pheader,
sizeof(
struct header))) {
4166 if(pheader->signature!=IMAGE_NT_SIGNATURE) {
4167 switch((
unsigned short)pheader->signature) {
4168 case IMAGE_DOS_SIGNATURE:
4171 case IMAGE_OS2_SIGNATURE:
4174 case IMAGE_OS2_SIGNATURE_LE:
4182#define isin(address,start,length) ((address)>=(start) && (address)<(start)+(length))
4185 for(sect=0,section_header=pheader->section_header;
4186 sect<pheader->_head.NumberOfSections;sect++,section_header++) {
4188 const void *
const section_data =
4189 (
char*)basepointer + section_header->PointerToRawData;
4190 for(directory=0;directory<IMAGE_NUMBEROF_DIRECTORY_ENTRIES;directory++) {
4191 if(
isin(pheader->opt_head.DataDirectory[directory].VirtualAddress,
4192 section_header->VirtualAddress,
4193 section_header->SizeOfRawData)) {
4194 const IMAGE_IMPORT_DESCRIPTOR *stuff_start =
4195 (IMAGE_IMPORT_DESCRIPTOR *)((
char*)section_data +
4196 (pheader->opt_head.DataDirectory[directory].VirtualAddress -
4197 section_header->VirtualAddress));
4200 const unsigned stuff_length =
4201 pheader->opt_head.DataDirectory[directory].Size;
4202 if(directory == IMAGE_DIRECTORY_ENTRY_IMPORT) {
4203 while(!IsBadReadPtr(stuff_start,
sizeof(*stuff_start)) &&
4204 stuff_start->Name) {
4205 TString dll = (
char*)section_data +
4206 ((DWORD)(stuff_start->Name)) -
4207 section_header->VirtualAddress;
4211 char *winPath = getenv(
"windir");
4212 _splitpath(winPath,winDrive,winDir,winName,winExt);
4213 if(!strstr(dllPath, winDir)) {
4214 if (!linkedLibs.
IsNull())
4216 linkedLibs += dllPath;
4228 UnmapViewOfFile(basepointer);
4229 CloseHandle(hMapping);
4268 Ssiz_t start, index, end;
4269 start = index = end = 0;
4271 while ((start < libs.
Length()) && (index !=
kNPOS)) {
4276 s = libs(index, end);
4278 if ((
s.Index(
"c:/windows/") !=
kNPOS) ||
4279 (
s.Index(
"python") !=
kNPOS)) {
4283 if (
s.BeginsWith(
"c:/program")) {
4284 in_program_files =
kTRUE;
4288 if (in_program_files) {
4289 if (
s.EndsWith(
".dll"))
4290 in_program_files =
kFALSE;
4294 if (
s.Index(user_dll) !=
kNPOS) {
4295 s.ReplaceAll(
".dll",
".lib");
4297 s.Replace( 0,
s.Last(
'/')+1, 0, 0);
4298 s.Replace( 0,
s.Last(
'\\')+1, 0, 0);
4300 }
else if (
s.Index(user_lib) !=
kNPOS) {
4302 s.Replace( 0,
s.Last(
'/')+1, 0, 0);
4303 s.Replace( 0,
s.Last(
'\\')+1, 0, 0);
4307 if ((
s.Index(
"python") ==
kNPOS) && (
s.Index(
"cppyy") ==
kNPOS) &&
4308 (
s.Index(
"vcruntime") ==
kNPOS) && (
s.Index(
".pyd") ==
kNPOS) &&
4309 (
s.Index(
"lzma") ==
kNPOS) && (
s.Index(
"gdk-1.3") ==
kNPOS) &&
4310 (
s.Index(
"glib-1.3") ==
kNPOS) && (
s.Index(
"iconv-1.3") ==
kNPOS) &&
4311 (
s.Index(
"msvcp") ==
kNPOS))
4340 if (!ti)
return nullptr;
4375 if (mode && t->
IsSync()) {
4379 }
else if (!mode && t->
IsAsync()) {
4397 FILETIME ftFileTime;
4401 ::GetSystemTimeAsFileTime(&ftRealTime.ftFileTime);
4410 OSVERSIONINFO OsVersionInfo;
4419 OsVersionInfo.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
4420 GetVersionEx(&OsVersionInfo);
4421 if (OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
4427 FILETIME ftFileTime;
4432 FILETIME ftFileTime;
4436 HANDLE hThread = GetCurrentThread();
4437 ret = GetThreadTimes (hThread, &ftCreate, &ftExit,
4438 &ftKernel.ftFileTime,
4439 &ftUser.ftFileTime);
4441 ret = ::GetLastError();
4442 ::Error(
"GetCPUTime",
" Error on GetProcessTimes 0x%lx", (
int)ret);
4462 static time_t jan95 = 0;
4473 jan95 = mktime(&tp);
4474 if ((
int)jan95 == -1) {
4475 ::SysError(
"TWinNTSystem::Now",
"error converting 950001 0:00 to time_t");
4482 return TTime((now.time-(
Long_t)jan95)*1000 + now.millitm);
4508 if (
h->HasReadInterest())
4510 if (
h->HasWriteInterest())
4512 h->ResetReadyMask();
4514 rc = WinNTSelect(&rd, &wr, to);
4543 if (
h->HasReadInterest())
4545 if (
h->HasWriteInterest())
4547 h->ResetReadyMask();
4548 rc = WinNTSelect(&rd, &wr, to);
4570 if ((sp = ::getservbyname(servicename,
kProtocolName)) == 0) {
4571 Error(
"GetServiceByName",
"no service \"%s\" with protocol \"%s\"\n",
4575 return ::ntohs(sp->s_port);
4586 if ((sp = ::getservbyport(::htons(port),
kProtocolName)) == 0) {
4587 return Form(
"%d", port);
4597 struct hostent *host_ptr;
4602 if ((addr = ::inet_addr(hostname)) != INADDR_NONE) {
4604 if ((host_ptr = ::gethostbyaddr((
const char *)&addr,
4605 sizeof(addr), AF_INET))) {
4606 host = host_ptr->h_name;
4610 for (i = 1; host_ptr->h_addr_list[i]; i++) {
4611 memcpy(&addr2, host_ptr->h_addr_list[i], host_ptr->h_length);
4612 a.AddAddress(ntohl(addr2));
4614 for (i = 0; host_ptr->h_aliases[i]; i++)
4615 a.AddAlias(host_ptr->h_aliases[i]);
4618 host =
"UnNamedHost";
4620 }
else if ((host_ptr = ::gethostbyname(hostname))) {
4622 if (host_ptr->h_addrtype != AF_INET) {
4623 Error(
"GetHostByName",
"%s is not an internet host\n", hostname);
4626 memcpy(&addr, host_ptr->h_addr, host_ptr->h_length);
4627 host = host_ptr->h_name;
4628 type = host_ptr->h_addrtype;
4632 for (i = 1; host_ptr->h_addr_list[i]; i++) {
4633 memcpy(&addr2, host_ptr->h_addr_list[i], host_ptr->h_length);
4634 a.AddAddress(ntohl(addr2));
4636 for (i = 0; host_ptr->h_aliases[i]; i++)
4637 a.AddAlias(host_ptr->h_aliases[i]);
4640 if (
gDebug > 0)
Error(
"GetHostByName",
"unknown host %s", hostname);
4653 struct sockaddr_in addr;
4654 int len =
sizeof(addr);
4656 if (::getpeername(sock, (
struct sockaddr *)&addr, &len) == SOCKET_ERROR) {
4661 struct hostent *host_ptr;
4662 const char *hostname;
4666 if ((host_ptr = ::gethostbyaddr((
const char *)&addr.sin_addr,
4667 sizeof(addr.sin_addr), AF_INET))) {
4668 memcpy(&iaddr, host_ptr->h_addr, host_ptr->h_length);
4669 hostname = host_ptr->h_name;
4670 family = host_ptr->h_addrtype;
4672 memcpy(&iaddr, &addr.sin_addr,
sizeof(addr.sin_addr));
4677 return TInetAddress(hostname, ::ntohl(iaddr), family, ::ntohs(addr.sin_port));
4686 struct sockaddr_in addr;
4687 int len =
sizeof(addr);
4689 if (::getsockname(sock, (
struct sockaddr *)&addr, &len) == SOCKET_ERROR) {
4694 struct hostent *host_ptr;
4695 const char *hostname;
4699 if ((host_ptr = ::gethostbyaddr((
const char *)&addr.sin_addr,
4700 sizeof(addr.sin_addr), AF_INET))) {
4701 memcpy(&iaddr, host_ptr->h_addr, host_ptr->h_length);
4702 hostname = host_ptr->h_name;
4703 family = host_ptr->h_addrtype;
4705 memcpy(&iaddr, &addr.sin_addr,
sizeof(addr.sin_addr));
4710 return TInetAddress(hostname, ::ntohl(iaddr), family, ::ntohs(addr.sin_port));
4721 if ((sock = ::socket(AF_INET, SOCK_STREAM, 0)) ==
INVALID_SOCKET) {
4722 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"socket");
4726 struct sockaddr_in inserver;
4727 memset(&inserver, 0,
sizeof(inserver));
4728 inserver.sin_family = AF_INET;
4729 inserver.sin_addr.s_addr = ::htonl(INADDR_LOOPBACK);
4730 inserver.sin_port = port;
4734 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver)) == SOCKET_ERROR) {
4735 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"bind");
4740 if (::listen(sock, backlog)) {
4741 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"listen");
4753 if (!sockpath || strlen(sockpath) <= 0) {
4754 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"socket path undefined");
4758 struct sockaddr_in myaddr;
4760 int len =
sizeof myaddr;
4765 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
4766 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"socket");
4770 memset(&myaddr, 0,
sizeof(myaddr));
4771 myaddr.sin_port = 0;
4772 myaddr.sin_family = AF_INET;
4773 myaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
4775 rc = bind(sock, (
struct sockaddr *)&myaddr, len);
4777 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"bind");
4780 rc = getsockname(sock, (
struct sockaddr *)&myaddr, &len);
4782 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"getsockname");
4785 TString socketpath = sockpath;
4787 fp = fopen(socketpath,
"wb");
4789 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"fopen");
4792 fprintf(fp,
"%d", myaddr.sin_port);
4796 if (listen(sock, backlog)) {
4797 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"listen");
4809 if (socket == -1)
return;
4813 ::shutdown(sock, 2);
4815 struct linger linger = {0, 0};
4816 ::setsockopt(sock, SOL_SOCKET, SO_LINGER, (
char *) &linger,
sizeof(linger));
4817 while (
::closesocket(sock) == SOCKET_ERROR && WSAGetLastError() == WSAEINTR) {
4831 if (WinNTRecv(sock, &header,
sizeof(header), 0) > 0) {
4832 int count = ::ntohl(header);
4834 if (count > length) {
4835 Error(
"RecvBuf",
"record header exceeds buffer size");
4837 }
else if (count > 0) {
4838 if (WinNTRecv(sock, buf, count, 0) < 0) {
4839 Error(
"RecvBuf",
"cannot receive buffer");
4854 Int_t header = ::htonl(length);
4856 if (WinNTSend(sock, &header,
sizeof(header), 0) < 0) {
4857 Error(
"SendBuf",
"cannot send header");
4861 if (WinNTSend(sock, buf, length, 0) < 0) {
4862 Error(
"SendBuf",
"cannot send buffer");
4902 if ((
n = WinNTRecv(sock, buf, length, flag)) <= 0) {
4904 Error(
"RecvRaw",
"cannot receive buffer");
4938 if ((
n = WinNTSend(sock, buf, length, flag)) <= 0) {
4940 Error(
"SendRaw",
"cannot send buffer");
4953 if (socket == -1)
return -1;
4958 if (::setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4959 ::SysError(
"SetSockOpt",
"setsockopt(SO_SNDBUF)");
4964 if (::setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4965 ::SysError(
"SetSockOpt",
"setsockopt(SO_RCVBUF)");
4970 if (::setsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4971 SysError(
"SetSockOpt",
"setsockopt(SO_OOBINLINE)");
4976 if (::setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4977 ::SysError(
"SetSockOpt",
"setsockopt(SO_KEEPALIVE)");
4982 if (::setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4983 ::SysError(
"SetSockOpt",
"setsockopt(SO_REUSEADDR)");
4988 if (::setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4989 ::SysError(
"SetSockOpt",
"setsockopt(TCP_NODELAY)");
4994 if (::ioctlsocket(sock, FIONBIO, &val) == SOCKET_ERROR) {
5001 if (::ioctl(sock, SIOCSPGRP, &val) == -1) {
5002 ::SysError(
"SetSockOpt",
"ioctl(SIOCSPGRP)");
5010 Error(
"SetSockOpt",
"illegal option (%d)", opt);
5022 if (socket == -1)
return -1;
5025 int optlen =
sizeof(*val);
5029 if (::getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)val, &optlen) == SOCKET_ERROR) {
5030 ::SysError(
"GetSockOpt",
"getsockopt(SO_SNDBUF)");
5035 if (::getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)val, &optlen) == SOCKET_ERROR) {
5036 ::SysError(
"GetSockOpt",
"getsockopt(SO_RCVBUF)");
5041 if (::getsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)val, &optlen) == SOCKET_ERROR) {
5042 ::SysError(
"GetSockOpt",
"getsockopt(SO_OOBINLINE)");
5047 if (::getsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)val, &optlen) == SOCKET_ERROR) {
5048 ::SysError(
"GetSockOpt",
"getsockopt(SO_KEEPALIVE)");
5053 if (::getsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)val, &optlen) == SOCKET_ERROR) {
5054 ::SysError(
"GetSockOpt",
"getsockopt(SO_REUSEADDR)");
5059 if (::getsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)val, &optlen) == SOCKET_ERROR) {
5060 ::SysError(
"GetSockOpt",
"getsockopt(TCP_NODELAY)");
5076 if (::ioctlsocket(sock, SIOCGPGRP, (u_long*)val) == SOCKET_ERROR) {
5077 ::SysError(
"GetSockOpt",
"ioctl(SIOCGPGRP)");
5083 if (::ioctlsocket(sock, SIOCATMARK, (u_long*)val) == SOCKET_ERROR) {
5084 ::SysError(
"GetSockOpt",
"ioctl(SIOCATMARK)");
5089 if (::ioctlsocket(sock, FIONREAD, (u_long*)val) == SOCKET_ERROR) {
5095 Error(
"GetSockOpt",
"illegal option (%d)", opt);
5107 int tcpwindowsize,
const char *protocol)
5112 if (!strcmp(servername,
"unix")) {
5116 (servername[1] ==
':' && servername[2] ==
'/')) {
5120 if (!strcmp(protocol,
"udp")){
5127 sport = ::htons(port);
5131 if (!addr.
IsValid())
return -1;
5134 struct sockaddr_in server;
5135 memset(&server, 0,
sizeof(server));
5136 memcpy(&server.sin_addr, &adr,
sizeof(adr));
5138 server.sin_port = sport;
5142 if ((sock = ::socket(AF_INET, SOCK_STREAM, 0)) ==
INVALID_SOCKET) {
5143 ::SysError(
"TWinNTSystem::WinNTConnectTcp",
"socket");
5147 if (tcpwindowsize > 0) {
5152 if (::connect(sock, (
struct sockaddr*) &server,
sizeof(server)) ==
INVALID_SOCKET) {
5165 struct sockaddr_in myaddr;
5168 memset(&myaddr, 0,
sizeof(myaddr));
5169 myaddr.sin_family = AF_INET;
5170 myaddr.sin_port = port;
5171 myaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
5174 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
5175 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"socket");
5179 while ((connect(sock, (
struct sockaddr *)&myaddr,
sizeof myaddr)) == -1) {
5183 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"connect");
5199 if (!sockpath || strlen(sockpath) <= 0) {
5200 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"socket path undefined");
5203 TString socketpath = sockpath;
5205 fp = fopen(socketpath.
Data(),
"rb");
5207 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"fopen");
5210 fscanf(fp,
"%d", &port);
5213 if (port < 0 || port > 65535) {
5214 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"invalid port");
5232 sport = htons(port);
5235 if (!addr.
IsValid())
return -1;
5238 struct sockaddr_in server;
5239 memset(&server, 0,
sizeof(server));
5240 memcpy(&server.sin_addr, &adr,
sizeof(adr));
5242 server.sin_port = sport;
5246 if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
5247 ::SysError(
"TWinNTSystem::WinNTUdpConnect",
"socket (%s:%d)",
5252 while (connect(sock, (
struct sockaddr*) &server,
sizeof(server)) == -1) {
5256 ::SysError(
"TWinNTSystem::WinNTUdpConnect",
"connect (%s:%d)",
5274 const char *protocol)
5295 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
5296 short tryport = kSOCKET_MINPORT;
5301 sport = ::htons(port);
5304 if (port == 0 && reuse) {
5305 ::Error(
"TWinNTSystem::WinNTTcpService",
"cannot do a port scan while reuse is true");
5312 sport = ::htons(port);
5317 if ((sock = ::socket(AF_INET, SOCK_STREAM, 0)) < 0) {
5318 ::SysError(
"TWinNTSystem::WinNTTcpService",
"socket");
5326 if (tcpwindowsize > 0) {
5331 struct sockaddr_in inserver;
5332 memset(&inserver, 0,
sizeof(inserver));
5333 inserver.sin_family = AF_INET;
5334 inserver.sin_addr.s_addr = ::htonl(INADDR_ANY);
5335 inserver.sin_port = sport;
5339 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver)) == SOCKET_ERROR) {
5340 ::SysError(
"TWinNTSystem::WinNTTcpService",
"bind");
5346 inserver.sin_port = ::htons(tryport);
5347 bret = ::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
5349 }
while (bret == SOCKET_ERROR && WSAGetLastError() == WSAEADDRINUSE &&
5350 tryport < kSOCKET_MAXPORT);
5351 if (bret == SOCKET_ERROR) {
5352 ::SysError(
"TWinNTSystem::WinNTTcpService",
"bind (port scan)");
5358 if (::listen(sock, backlog) == SOCKET_ERROR) {
5359 ::SysError(
"TWinNTSystem::WinNTTcpService",
"listen");
5376 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
5377 short sport, tryport = kSOCKET_MINPORT;
5383 sport = htons(port);
5387 if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
5388 ::SysError(
"TUnixSystem::UnixUdpService",
"socket");
5392 struct sockaddr_in inserver;
5393 memset(&inserver, 0,
sizeof(inserver));
5394 inserver.sin_family = AF_INET;
5395 inserver.sin_addr.s_addr = htonl(INADDR_ANY);
5396 inserver.sin_port = sport;
5400 if (bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver))) {
5401 ::SysError(
"TWinNTSystem::AnnounceUdpService",
"bind");
5407 inserver.sin_port = htons(tryport);
5408 bret = bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
5410 }
while (bret == SOCKET_ERROR && WSAGetLastError() == WSAEADDRINUSE &&
5411 tryport < kSOCKET_MAXPORT);
5413 ::SysError(
"TWinNTSystem::AnnounceUdpService",
"bind (port scan)");
5419 if (listen(sock, backlog)) {
5420 ::SysError(
"TWinNTSystem::AnnounceUdpService",
"listen");
5438 (::WSAGetLastError() == WSAEINTR)) {
5443 if (::WSAGetLastError() == WSAEWOULDBLOCK) {
5457#define SystemBasicInformation 0
5458#define SystemPerformanceInformation 2
5463 ULONG uKeMaximumIncrement;
5465 ULONG uMmNumberOfPhysicalPages;
5466 ULONG uMmLowestPhysicalPage;
5467 ULONG UMmHighestPhysicalPage;
5468 ULONG uAllocationGranularity;
5469 PVOID pLowestUserAddress;
5470 PVOID pMmHighestUserAddress;
5471 ULONG uKeActiveProcessors;
5472 BYTE bKeNumberProcessors;
5475} SYSTEM_BASIC_INFORMATION;
5479 LARGE_INTEGER liIdleTime;
5481} SYSTEM_PERFORMANCE_INFORMATION;
5483typedef struct _PROCESS_MEMORY_COUNTERS {
5485 DWORD PageFaultCount;
5486 SIZE_T PeakWorkingSetSize;
5487 SIZE_T WorkingSetSize;
5488 SIZE_T QuotaPeakPagedPoolUsage;
5489 SIZE_T QuotaPagedPoolUsage;
5490 SIZE_T QuotaPeakNonPagedPoolUsage;
5491 SIZE_T QuotaNonPagedPoolUsage;
5492 SIZE_T PagefileUsage;
5493 SIZE_T PeakPagefileUsage;
5498#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + (double)((x).LowPart))
5506 LARGE_INTEGER ulFreq, ulTicks, ulValue, ulStartCounter;
5510 if (QueryPerformanceFrequency(&ulFreq)) {
5512 QueryPerformanceCounter(&ulTicks);
5515 ulValue.QuadPart = ulTicks.QuadPart + ulFreq.QuadPart/10;
5516 ulStartCounter.QuadPart =
__rdtsc();
5520 QueryPerformanceCounter(&ulTicks);
5521 }
while (ulTicks.QuadPart <= ulValue.QuadPart);
5523 return (DWORD)((
__rdtsc() - ulStartCounter.QuadPart)/100000);
5531#define SM_SERVERR2 89
5538 OSVERSIONINFOEX osvi;
5541 BOOL bOsVersionInfoEx;
5542 static char *strReturn =
nullptr;
5546 strReturn =
new char[2048];
5550 ZeroMemory(&si,
sizeof(SYSTEM_INFO));
5551 ZeroMemory(&osvi,
sizeof(OSVERSIONINFOEX));
5556 osvi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFOEX);
5558 if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
5560 osvi.dwOSVersionInfoSize =
sizeof (OSVERSIONINFO);
5561 if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
5566 pGNSI = (
PGNSI) GetProcAddress( GetModuleHandle(
"kernel32.dll"),
5567 "GetNativeSystemInfo");
5570 else GetSystemInfo(&si);
5572 switch (osvi.dwPlatformId)
5575 case VER_PLATFORM_WIN32_NT:
5578 if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 )
5580 if( osvi.wProductType == VER_NT_WORKSTATION )
5581 strlcpy(strReturn,
"Microsoft Windows Vista ",2048);
5582 else strlcpy(strReturn,
"Windows Server \"Longhorn\" " ,2048);
5584 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
5587 strlcpy(strReturn,
"Microsoft Windows Server 2003 \"R2\" ",2048);
5588 else if( osvi.wProductType == VER_NT_WORKSTATION &&
5589 si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
5591 strlcpy(strReturn,
"Microsoft Windows XP Professional x64 Edition ",2048);
5593 else strlcpy(strReturn,
"Microsoft Windows Server 2003, ",2048);
5595 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
5596 strlcpy(strReturn,
"Microsoft Windows XP ",2048);
5598 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
5599 strlcpy(strReturn,
"Microsoft Windows 2000 ",2048);
5601 if ( osvi.dwMajorVersion <= 4 )
5602 strlcpy(strReturn,
"Microsoft Windows NT ",2048);
5605 if( bOsVersionInfoEx )
5608 if ( osvi.wProductType == VER_NT_WORKSTATION &&
5609 si.wProcessorArchitecture!=PROCESSOR_ARCHITECTURE_AMD64)
5611 if( osvi.dwMajorVersion == 4 )
5612 strlcat(strReturn,
"Workstation 4.0 ",2048 );
5613 else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
5614 strlcat(strReturn,
"Home Edition " ,2048);
5615 else strlcat(strReturn,
"Professional " ,2048);
5618 else if ( osvi.wProductType == VER_NT_SERVER ||
5619 osvi.wProductType == VER_NT_DOMAIN_CONTROLLER )
5621 if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==2)
5623 if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_IA64 )
5625 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
5626 strlcat(strReturn,
"Datacenter Edition for Itanium-based Systems",2048 );
5627 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5628 strlcat(strReturn,
"Enterprise Edition for Itanium-based Systems" ,2048);
5630 else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
5632 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
5633 strlcat(strReturn,
"Datacenter x64 Edition ",2048 );
5634 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5635 strlcat(strReturn,
"Enterprise x64 Edition ",2048 );
5636 else strlcat(strReturn,
"Standard x64 Edition ",2048 );
5640 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
5641 strlcat(strReturn,
"Datacenter Edition ",2048 );
5642 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5643 strlcat(strReturn,
"Enterprise Edition ",2048 );
5644 else if ( osvi.wSuiteMask == VER_SUITE_BLADE )
5645 strlcat(strReturn,
"Web Edition " ,2048);
5646 else strlcat(strReturn,
"Standard Edition ",2048 );
5649 else if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==0)
5651 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
5652 strlcat(strReturn,
"Datacenter Server ",2048 );
5653 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5654 strlcat(strReturn,
"Advanced Server ",2048 );
5655 else strlcat(strReturn,
"Server ",2048 );
5659 if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5660 strlcat(strReturn,
"Server 4.0, Enterprise Edition " ,2048);
5661 else strlcat(strReturn,
"Server 4.0 ",2048 );
5670 DWORD dwBufLen=
BUFSIZE*
sizeof(TCHAR);
5673 lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
5674 "SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
5675 0, KEY_QUERY_VALUE, &hKey );
5676 if( lRet != ERROR_SUCCESS )
5679 lRet = RegQueryValueEx( hKey,
"ProductType", NULL, NULL,
5680 (LPBYTE) szProductType, &dwBufLen);
5681 RegCloseKey( hKey );
5683 if( (lRet != ERROR_SUCCESS) || (dwBufLen >
BUFSIZE*
sizeof(TCHAR)) )
5686 if ( lstrcmpi(
"WINNT", szProductType) == 0 )
5687 strlcat(strReturn,
"Workstation " ,2048);
5688 if ( lstrcmpi(
"LANMANNT", szProductType) == 0 )
5689 strlcat(strReturn,
"Server " ,2048);
5690 if ( lstrcmpi(
"SERVERNT", szProductType) == 0 )
5691 strlcat(strReturn,
"Advanced Server " ,2048);
5692 snprintf(temp,512,
"%d.%d ", osvi.dwMajorVersion, osvi.dwMinorVersion);
5693 strlcat(strReturn, temp,2048);
5698 if( osvi.dwMajorVersion == 4 &&
5699 lstrcmpi( osvi.szCSDVersion,
"Service Pack 6" ) == 0 )
5705 lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
5706 "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009",
5707 0, KEY_QUERY_VALUE, &hKey );
5708 if( lRet == ERROR_SUCCESS ) {
5709 snprintf(temp, 512,
"Service Pack 6a (Build %d)", osvi.dwBuildNumber & 0xFFFF );
5710 strlcat(strReturn, temp,2048 );
5714 snprintf(temp,512,
"%s (Build %d)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
5715 strlcat(strReturn, temp,2048 );
5718 RegCloseKey( hKey );
5722 snprintf(temp, 512,
"%s (Build %d)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
5723 strlcat(strReturn, temp,2048 );
5729 case VER_PLATFORM_WIN32_WINDOWS:
5731 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
5733 strlcpy(strReturn,
"Microsoft Windows 95 ",2048);
5734 if (osvi.szCSDVersion[1]==
'C' || osvi.szCSDVersion[1]==
'B')
5735 strlcat(strReturn,
"OSR2 " ,2048);
5738 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
5740 strlcpy(strReturn,
"Microsoft Windows 98 ",2048);
5741 if ( osvi.szCSDVersion[1]==
'A' || osvi.szCSDVersion[1]==
'B')
5742 strlcat(strReturn,
"SE ",2048 );
5745 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
5747 strlcpy(strReturn,
"Microsoft Windows Millennium Edition",2048);
5751 case VER_PLATFORM_WIN32s:
5752 strlcpy(strReturn,
"Microsoft Win32s",2048);
5763 unsigned nHighestFeatureEx;
5767 nHighestFeatureEx = (unsigned)nBuff[0];
5769 if (nHighestFeatureEx >= 0x80000006) {
5771 return (((
unsigned)nBuff[2])>>16);
5781 SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
5782 SYSTEM_INFO sysInfo;
5783 MEMORYSTATUSEX statex;
5784 OSVERSIONINFO OsVersionInfo;
5786 char szKeyValueString[80];
5787 DWORD szKeyValueDword;
5792 NtQuerySystemInformation = (
PROCNTQSI)GetProcAddress(
5793 GetModuleHandle(
"ntdll"),
"NtQuerySystemInformation");
5795 if (!NtQuerySystemInformation) {
5797 "Error on GetProcAddress(NtQuerySystemInformation)");
5802 &SysPerfInfo,
sizeof(SysPerfInfo),
5804 OsVersionInfo.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
5805 GetVersionEx(&OsVersionInfo);
5806 GetSystemInfo(&sysInfo);
5807 statex.dwLength =
sizeof(statex);
5808 if (!GlobalMemoryStatusEx(&statex)) {
5809 ::Error(
"GetWinNTSysInfo",
"Error on GlobalMemoryStatusEx()");
5812 sysinfo->
fCpus = sysInfo.dwNumberOfProcessors;
5821 status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"HARDWARE\\DESCRIPTION\\System",
5822 0, KEY_QUERY_VALUE, &hKey);
5823 if (status == ERROR_SUCCESS) {
5824 dwBufLen =
sizeof(szKeyValueString);
5825 RegQueryValueEx(hKey,
"Identifier", NULL, NULL,(LPBYTE)szKeyValueString,
5827 sysinfo->
fModel = szKeyValueString;
5830 status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
5831 "Hardware\\Description\\System\\CentralProcessor\\0",
5832 0, KEY_QUERY_VALUE, &hKey);
5833 if (status == ERROR_SUCCESS) {
5834 dwBufLen =
sizeof(szKeyValueString);
5835 status = RegQueryValueEx(hKey,
"ProcessorNameString", NULL, NULL,
5836 (LPBYTE)szKeyValueString, &dwBufLen);
5837 if (status == ERROR_SUCCESS)
5838 sysinfo->
fCpuType = szKeyValueString;
5839 dwBufLen =
sizeof(DWORD);
5840 status = RegQueryValueEx(hKey,
"~MHz",NULL,NULL,(LPBYTE)&szKeyValueDword,
5842 if ((status == ERROR_SUCCESS) && ((sysinfo->
fCpuSpeed <= 0) ||
5843 (sysinfo->
fCpuSpeed < (szKeyValueDword >> 1))))