70#if defined (_MSC_VER) && (_MSC_VER >= 1400)
72#elif defined (_M_IX86)
73 static void __cpuid(
int* cpuid_data,
int info_type)
101 cpuid_data[0] = 0x00000000;
102 cpuid_data[1] = 0x00000000;
103 cpuid_data[2] = 0x00000000;
104 cpuid_data[3] = 0x00000000;
127 if (
fds_bits->fd_count < FD_SETSIZE-1)
130 ::SysError(
"TFdSet::Set",
"fd_count will exeed FD_SETSIZE");
135 for (i=0; i<
fds_bits->fd_count; i++) {
137 while (i<fds_bits->fd_count-1) {
157 static HANDLE gGlobalEvent;
158 static HANDLE gTimerThreadHandle;
159 typedef NET_API_STATUS (WINAPI *pfn1)(LPVOID);
160 typedef NET_API_STATUS (WINAPI *pfn2)(LPCWSTR, LPCWSTR, DWORD, LPBYTE*);
161 typedef NET_API_STATUS (WINAPI *pfn3)(LPCWSTR, LPCWSTR, DWORD, LPBYTE*,
162 DWORD, LPDWORD, LPDWORD, PDWORD_PTR);
163 typedef NET_API_STATUS (WINAPI *pfn4)(LPCWSTR, DWORD, LPBYTE*, DWORD, LPDWORD,
164 LPDWORD, PDWORD_PTR);
165 static pfn1 p2NetApiBufferFree;
166 static pfn2 p2NetUserGetInfo;
167 static pfn3 p2NetLocalGroupGetMembers;
168 static pfn4 p2NetLocalGroupEnum;
170 static struct signal_map {
176 SIGSEGV, 0,
"segmentation violation",
177 -1 , 0,
"bad argument to system call",
178 -1 , 0,
"write on a pipe with no one to read it",
179 SIGILL, 0,
"illegal instruction",
182 SIGINT, 0,
"interrupt",
183 -1 , 0,
"window size change",
184 -1 , 0,
"alarm clock",
185 -1 , 0,
"death of a child",
186 -1 , 0,
"urgent data arrived on an I/O channel",
187 SIGFPE, 0,
"floating point exception",
188 SIGTERM, 0,
"termination signal",
189 -1 , 0,
"user-defined signal 1",
190 -1 , 0,
"user-defined signal 2"
211 static int WinNTRecv(
int socket,
void *buffer,
int length,
int flag)
213 if (
socket == -1)
return -1;
221 if (flag == MSG_PEEK) {
226 char *buf = (
char *)buffer;
229 if ((nrecv = ::recv(sock, buf+
n,
length-
n, flag)) <= 0) {
233 if (flag == MSG_OOB) {
234 if (::WSAGetLastError() == WSAEWOULDBLOCK) {
236 }
else if (::WSAGetLastError() == WSAEINVAL) {
240 if (::WSAGetLastError() == WSAEWOULDBLOCK) {
243 if (::WSAGetLastError() != WSAEINTR)
244 ::SysError(
"TWinNTSystem::WinNTRecv",
"recv");
245 if (::WSAGetLastError() == EPIPE ||
246 ::WSAGetLastError() == WSAECONNRESET)
265 static int WinNTSend(
int socket,
const void *buffer,
int length,
int flag)
267 if (
socket < 0)
return -1;
277 const char *buf = (
const char *)buffer;
280 if ((nsent = ::send(sock, buf+
n,
length-
n, flag)) <= 0) {
284 if (::WSAGetLastError() == WSAEWOULDBLOCK) {
287 if (::WSAGetLastError() != WSAEINTR)
288 ::SysError(
"TWinNTSystem::WinNTSend",
"send");
289 if (::WSAGetLastError() == EPIPE ||
290 ::WSAGetLastError() == WSAECONNRESET)
310 fd_set* rbits = readready ? (fd_set*)readready->
GetBits() : 0;
311 fd_set* wbits = writeready ? (fd_set*)writeready->
GetBits() : 0;
315 tv.tv_sec = timeout / 1000;
316 tv.tv_usec = (timeout % 1000) * 1000;
318 retcode = ::select(0, rbits, wbits, 0, &tv);
320 retcode = ::select(0, rbits, wbits, 0, 0);
323 if (retcode == SOCKET_ERROR) {
324 int errcode = ::WSAGetLastError();
328 if (errcode == WSAENOTSOCK) {
330 int result = _fstat64( readready->
GetFd(0), &buf );
338 ::WaitForSingleObject(gGlobalEvent, 1);
339 ::ResetEvent(gGlobalEvent);
344 if ( errcode == WSAEINTR) {
348 if (errcode == EBADF) {
363 if (reset || newpath) {
368 }
else if (dynpath ==
"") {
372 if (rdynpath ==
"") {
400 if (signal_map[i].code == sig) {
401 (*signal_map[i].handler)((
ESignals)i);
412 signal_map[sig].handler = handler;
413 if (signal_map[sig].code != -1)
420 static const char *WinNTSigname(
ESignals sig)
422 return signal_map[sig].signame;
428 static BOOL ConsoleSigHandler(DWORD sig)
436 Break(
"TInterruptHandler::Notify",
"keyboard interrupt");
442 case CTRL_BREAK_EVENT:
443 case CTRL_LOGOFF_EVENT:
444 case CTRL_SHUTDOWN_EVENT:
445 case CTRL_CLOSE_EVENT:
447 printf(
"\n *** Break *** keyboard interrupt - ROOT is terminated\n");
453 static CONTEXT *fgXcptContext = 0;
467 LONG WINAPI ExceptionFilter(LPEXCEPTION_POINTERS pXcp)
469 fgXcptContext = pXcp->ContextRecord;
471 return EXCEPTION_CONTINUE_SEARCH;
475#pragma intrinsic(_ReturnAddress)
476#pragma auto_inline(off)
477 DWORD_PTR GetProgramCounter()
482#pragma auto_inline(on)
493 static DWORD WINAPI GUIThreadMessageProcessingLoop(
void *
p)
498 ::PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
503 if (gGlobalEvent) ::SetEvent(gGlobalEvent);
504 erret = ::GetMessage(&msg, NULL, NULL, NULL);
505 if (erret <= 0) endLoop =
kTRUE;
506 if (gGUIThreadMsgFunc)
507 endLoop = (*gGUIThreadMsgFunc)(&msg);
514 erret = ::GetLastError();
515 Error(
"MsgLoop",
"Error in GetMessage");
529 typedef BOOL (__stdcall *SYMINITIALIZEPROC)( HANDLE, LPSTR,
BOOL );
530 typedef BOOL (__stdcall *SYMCLEANUPPROC)( HANDLE );
531 typedef BOOL (__stdcall *STACKWALK64PROC)
532 ( DWORD, HANDLE, HANDLE, LPSTACKFRAME64, LPVOID,
533 PREAD_PROCESS_MEMORY_ROUTINE,PFUNCTION_TABLE_ACCESS_ROUTINE,
534 PGET_MODULE_BASE_ROUTINE, PTRANSLATE_ADDRESS_ROUTINE );
535 typedef LPVOID (__stdcall *SYMFUNCTIONTABLEACCESS64PROC)( HANDLE, DWORD64 );
536 typedef DWORD (__stdcall *SYMGETMODULEBASE64PROC)( HANDLE, DWORD64 );
537 typedef BOOL (__stdcall *SYMGETMODULEINFO64PROC)(HANDLE, DWORD64, PIMAGEHLP_MODULE64);
538 typedef BOOL (__stdcall *SYMGETSYMFROMADDR64PROC)( HANDLE, DWORD64, PDWORD64, PIMAGEHLP_SYMBOL64);
539 typedef BOOL (__stdcall *SYMGETLINEFROMADDR64PROC)(HANDLE, DWORD64, PDWORD, PIMAGEHLP_LINE64);
540 typedef DWORD (__stdcall *UNDECORATESYMBOLNAMEPROC)(PCSTR, PSTR, DWORD, DWORD);
543 static SYMINITIALIZEPROC _SymInitialize = 0;
544 static SYMCLEANUPPROC _SymCleanup = 0;
545 static STACKWALK64PROC _StackWalk64 = 0;
546 static SYMFUNCTIONTABLEACCESS64PROC _SymFunctionTableAccess64 = 0;
547 static SYMGETMODULEBASE64PROC _SymGetModuleBase64 = 0;
548 static SYMGETMODULEINFO64PROC _SymGetModuleInfo64 = 0;
549 static SYMGETSYMFROMADDR64PROC _SymGetSymFromAddr64 = 0;
550 static SYMGETLINEFROMADDR64PROC _SymGetLineFromAddr64 = 0;
551 static UNDECORATESYMBOLNAMEPROC _UnDecorateSymbolName = 0;
553 BOOL InitImagehlpFunctions()
561 HMODULE hModImagehlp = LoadLibrary(
"IMAGEHLP.DLL" );
565 _SymInitialize = (SYMINITIALIZEPROC) GetProcAddress( hModImagehlp,
"SymInitialize" );
569 _SymCleanup = (SYMCLEANUPPROC) GetProcAddress( hModImagehlp,
"SymCleanup" );
573 _StackWalk64 = (STACKWALK64PROC) GetProcAddress( hModImagehlp,
"StackWalk64" );
577 _SymFunctionTableAccess64 = (SYMFUNCTIONTABLEACCESS64PROC) GetProcAddress(hModImagehlp,
"SymFunctionTableAccess64" );
578 if (!_SymFunctionTableAccess64)
581 _SymGetModuleBase64=(SYMGETMODULEBASE64PROC)GetProcAddress(hModImagehlp,
"SymGetModuleBase64");
582 if (!_SymGetModuleBase64)
585 _SymGetModuleInfo64=(SYMGETMODULEINFO64PROC)GetProcAddress(hModImagehlp,
"SymGetModuleInfo64");
586 if (!_SymGetModuleInfo64)
589 _SymGetSymFromAddr64=(SYMGETSYMFROMADDR64PROC)GetProcAddress(hModImagehlp,
"SymGetSymFromAddr64");
590 if (!_SymGetSymFromAddr64)
593 _SymGetLineFromAddr64=(SYMGETLINEFROMADDR64PROC)GetProcAddress(hModImagehlp,
"SymGetLineFromAddr64");
594 if (!_SymGetLineFromAddr64)
597 _UnDecorateSymbolName=(UNDECORATESYMBOLNAMEPROC)GetProcAddress(hModImagehlp,
"UnDecorateSymbolName");
598 if (!_UnDecorateSymbolName)
601 if (!_SymInitialize(GetCurrentProcess(), 0,
TRUE ))
617 std::string GetModuleName(DWORD64 address)
621 std::ostringstream
out;
622 HANDLE process = ::GetCurrentProcess();
624 DWORD lineDisplacement = 0;
625 IMAGEHLP_LINE64
line;
628 if(_SymGetLineFromAddr64(process, address, &lineDisplacement, &
line)) {
629 out <<
line.FileName <<
"(" <<
line.LineNumber <<
"): ";
631 IMAGEHLP_MODULE64 module;
632 ::ZeroMemory(&module,
sizeof(module));
633 module.SizeOfStruct =
sizeof(module);
634 if(_SymGetModuleInfo64(process, address, &module)) {
635 out << module.ModuleName <<
"!";
637 out <<
"0x" << std::hex << address << std::dec <<
" ";
644 std::string GetFunctionName(DWORD64 address)
648 DWORD64 symbolDisplacement = 0;
649 HANDLE process = ::GetCurrentProcess();
651 const unsigned int SYMBOL_BUFFER_SIZE = 8192;
652 char symbolBuffer[SYMBOL_BUFFER_SIZE];
653 PIMAGEHLP_SYMBOL64 symbol =
reinterpret_cast<PIMAGEHLP_SYMBOL64
>(symbolBuffer);
654 ::ZeroMemory(symbol, SYMBOL_BUFFER_SIZE);
655 symbol->SizeOfStruct = SYMBOL_BUFFER_SIZE;
656 symbol->MaxNameLength = SYMBOL_BUFFER_SIZE -
sizeof(IMAGEHLP_SYMBOL64);
658 if(_SymGetSymFromAddr64(process, address, &symbolDisplacement, symbol)) {
660 const unsigned int NAME_SIZE = 8192;
661 char name[NAME_SIZE];
662 _UnDecorateSymbolName(
667 UNDNAME_NO_THISTYPE |
668 UNDNAME_NO_SPECIAL_SYMS |
669 UNDNAME_NO_MEMBER_TYPE |
670 UNDNAME_NO_MS_KEYWORDS |
671 UNDNAME_NO_ACCESS_SPECIFIERS
692 const char *extLnk =
".lnk";
696 if (strfilename.EndsWith(extLnk))
705 static BOOL ResolveShortCut(LPCSTR pszShortcutFile,
char *pszPath,
int maxbuf)
709 char szGotPath[MAX_PATH];
716 typedef HRESULT (__stdcall *COINITIALIZEPROC)( LPVOID );
717 static COINITIALIZEPROC _CoInitialize = 0;
718 typedef void (__stdcall *COUNINITIALIZEPROC)(
void );
719 static COUNINITIALIZEPROC _CoUninitialize = 0;
720 typedef HRESULT (__stdcall *COCREATEINSTANCEPROC)( REFCLSID, LPUNKNOWN,
721 DWORD, REFIID, LPVOID );
722 static COCREATEINSTANCEPROC _CoCreateInstance = 0;
724 HMODULE hModImagehlp = LoadLibrary(
"ole32.dll" );
728 _CoInitialize = (COINITIALIZEPROC) GetProcAddress( hModImagehlp,
"CoInitialize" );
731 _CoUninitialize = (COUNINITIALIZEPROC) GetProcAddress( hModImagehlp,
"CoUninitialize");
732 if (!_CoUninitialize)
734 _CoCreateInstance = (COCREATEINSTANCEPROC) GetProcAddress( hModImagehlp,
"CoCreateInstance" );
735 if (!_CoCreateInstance)
740 hres = _CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
741 IID_IShellLink, (
void **) &psl);
742 if (SUCCEEDED(hres)) {
745 hres = psl->QueryInterface(IID_IPersistFile, (
void **) &ppf);
746 if (SUCCEEDED(hres)) {
748 MultiByteToWideChar(CP_ACP, 0, pszShortcutFile, -1, wsz, MAX_PATH);
750 hres = ppf->Load(wsz, STGM_READ);
751 if (SUCCEEDED(hres)) {
752 hres = psl->Resolve(HWND_DESKTOP, SLR_ANY_MATCH | SLR_NO_UI | SLR_UPDATE);
753 if (SUCCEEDED(hres)) {
754 strlcpy(szGotPath, pszShortcutFile,MAX_PATH);
755 hres = psl->GetPath(szGotPath, MAX_PATH, (WIN32_FIND_DATA *)&wfd,
756 SLGP_UNCPRIORITY | SLGP_RAWPATH);
757 strlcpy(pszPath,szGotPath, maxbuf);
758 if (maxbuf) pszPath[maxbuf-1] = 0;
767 return SUCCEEDED(hres);
773 if (strcmp(sys->TWinNTSystem::BaseName(buf),
"root.exe"))
776 if (!::RegOpenKeyEx(HKEY_CURRENT_USER,
"Software", 0, KEY_READ, ®CUS) == ERROR_SUCCESS)
779 if (!::RegOpenKeyEx(regCUS,
"Classes", 0, KEY_READ, ®CUSC) == ERROR_SUCCESS) {
780 ::RegCloseKey(regCUS);
785 bool regROOTwrite =
false;
789 if (::RegOpenKeyEx(regCUSC,
"ROOTDEV.ROOT", 0, KEY_READ, ®ROOT) != ERROR_SUCCESS) {
790 ::RegCloseKey(regCUSC);
791 if (::RegOpenKeyEx(regCUS,
"Classes", 0, KEY_READ | KEY_WRITE, ®CUSC) == ERROR_SUCCESS &&
792 ::RegCreateKeyEx(regCUSC,
"ROOTDEV.ROOT", 0, NULL, 0, KEY_READ | KEY_WRITE,
793 NULL, ®ROOT, NULL) == ERROR_SUCCESS) {
798 if (::RegOpenKeyEx(regROOT,
"DefaultIcon", 0, KEY_READ, ®ROOTIcon) == ERROR_SUCCESS) {
799 char bufIconLoc[1024];
801 DWORD dwSize =
sizeof(bufIconLoc);
803 if (::RegQueryValueEx(regROOTIcon, NULL, NULL, &dwType, (BYTE*)bufIconLoc, &dwSize) == ERROR_SUCCESS)
804 regROOTwrite = (iconloc != bufIconLoc);
807 ::RegCloseKey(regROOTIcon);
812 ::RegCloseKey(regCUSC);
813 ::RegCloseKey(regROOT);
814 if (::RegOpenKeyEx(regCUS,
"Classes", 0, KEY_READ | KEY_WRITE, ®CUSC) != ERROR_SUCCESS) {
816 regROOTwrite =
false;
818 if (::RegOpenKeyEx(regCUSC,
"ROOTDEV.ROOT", 0, KEY_WRITE, ®ROOT) != ERROR_SUCCESS) {
820 regROOTwrite =
false;
821 ::RegCloseKey(regCUSC);
828 TString fileopen =
"fileopen.C";
829 TString rootmacrodir =
"macros";
839 ::RegCloseKey(regROOT);
840 ::RegCloseKey(regCUSC);
841 ::RegCloseKey(regCUS);
845 static const char apptitle[] =
"ROOT data file";
846 ::RegSetValueEx(regROOT, NULL, 0, REG_SZ, (BYTE*)apptitle,
sizeof(apptitle));
847 DWORD editflags = 0x00010000;
848 ::RegSetValueEx(regROOT,
"EditFlags", 0, REG_DWORD, (BYTE*)&editflags,
sizeof(editflags));
851 if (::RegCreateKeyEx(regROOT,
"DefaultIcon", 0, NULL, 0, KEY_READ | KEY_WRITE,
852 NULL, ®ROOTIcon, NULL) == ERROR_SUCCESS) {
855 ::RegSetValueEx(regROOTIcon, NULL, 0, REG_SZ, (BYTE*)iconloc.Data(), iconloc.Length() + 1);
856 ::RegCloseKey(regROOTIcon);
861 if (::RegCreateKeyEx(regROOT,
"shell", 0, NULL, 0, KEY_READ | KEY_WRITE,
862 NULL, ®ROOTshell, NULL) == ERROR_SUCCESS) {
864 if (::RegCreateKeyEx(regROOTshell,
"open", 0, NULL, 0, KEY_READ | KEY_WRITE,
865 NULL, ®ShellOpen, NULL) == ERROR_SUCCESS) {
866 HKEY regShellOpenCmd;
867 if (::RegCreateKeyEx(regShellOpen,
"command", 0, NULL, 0, KEY_READ | KEY_WRITE,
868 NULL, ®ShellOpenCmd, NULL) == ERROR_SUCCESS) {
870 cmd +=
" -l \"%1\" \"";
873 ::RegSetValueEx(regShellOpenCmd, NULL, 0, REG_SZ, (BYTE*)cmd.Data(), cmd.Length() + 1);
874 ::RegCloseKey(regShellOpenCmd);
876 ::RegCloseKey(regShellOpen);
878 ::RegCloseKey(regROOTshell);
880 ::RegCloseKey(regROOT);
882 if (::RegCreateKeyEx(regCUSC,
".root", 0, NULL, 0, KEY_READ | KEY_WRITE,
883 NULL, ®ROOT, NULL) == ERROR_SUCCESS) {
884 static const char appname[] =
"ROOTDEV.ROOT";
885 ::RegSetValueEx(regROOT, NULL, 0, REG_SZ, (BYTE*)appname,
sizeof(appname));
887 ::RegCloseKey(regCUSC);
888 ::RegCloseKey(regCUS);
891 ::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
899 static bool once =
true;
902 if (!once ||
gROOT->IsBatch())
return false;
903 TString cmdline(::GetCommandLine());
904 Int_t i = 0, from = 0;
905 while (cmdline.Tokenize(arg, from,
" ")) {
907 if (i == 0 && ((arg !=
"root") && (arg !=
"rootn") &&
908 (arg !=
"root.exe") && (arg !=
"rootn.exe")))
return false;
909 else if ((arg ==
"-l") || (arg ==
"-b"))
return false;
921 static void SetConsoleWindowName()
923 char pszNewWindowTitle[1024];
924 char pszOldWindowTitle[1024];
926 CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
928 if (!::GetConsoleTitle(pszOldWindowTitle, 1024))
931 wsprintf(pszNewWindowTitle,
"%d/%d", ::GetTickCount(), ::GetCurrentProcessId());
933 if (!::SetConsoleTitle(pszNewWindowTitle))
943 ::SetConsoleTitle(
"ROOT session");
945 hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
948 ::SetConsoleMode(hStdout, ENABLE_PROCESSED_OUTPUT |
949 ENABLE_WRAP_AT_EOL_OUTPUT);
950 if (!::GetConsoleScreenBufferInfo(hStdout, &csbiInfo))
993 if (initwinsock = ::WSAStartup(MAKEWORD(2, 0), &WSAData)) {
994 Error(
"TWinNTSystem()",
"Starting sockets failed");
1005 char *buf =
new char[MAX_MODULE_NAME32 + 1];
1011 HMODULE hModCore = ::GetModuleHandle(
"libCore.dll");
1013 ::GetModuleFileName(hModCore, buf, MAX_MODULE_NAME32 + 1);
1014 char *pLibName = strstr(buf,
"libCore.dll");
1017 while (--pLibName >= buf && *pLibName !=
'\\' && *pLibName !=
'/');
1020 check_path +=
"\\etc";
1022 while (buf[0] && GetFileAttributes(check_path.
Data()) == INVALID_FILE_ATTRIBUTES) {
1023 while (--pLibName >= buf && *pLibName !=
'\\' && *pLibName !=
'/');
1026 check_path +=
"\\etc";
1041 UpdateRegistry(
this, buf);
1052 typedef UINT (WINAPI* LPTIMEENDPERIOD)( UINT uPeriod );
1053 HINSTANCE hInstWinMM = LoadLibrary(
"winmm.dll" );
1055 LPTIMEENDPERIOD pTimeEndPeriod = (LPTIMEENDPERIOD)GetProcAddress( hInstWinMM,
"timeEndPeriod" );
1056 if( NULL != pTimeEndPeriod )
1058 FreeLibrary(hInstWinMM);
1064 ::ResetEvent(gGlobalEvent);
1065 ::CloseHandle(gGlobalEvent);
1068 if (gTimerThreadHandle) {
1069 ::TerminateThread(gTimerThreadHandle, 0);
1070 ::CloseHandle(gTimerThreadHandle);
1103 ::SetUnhandledExceptionFilter(ExceptionFilter);
1111 typedef UINT (WINAPI* LPTIMEBEGINPERIOD)( UINT uPeriod );
1112 HINSTANCE hInstWinMM = LoadLibrary(
"winmm.dll" );
1114 LPTIMEBEGINPERIOD pTimeBeginPeriod = (LPTIMEBEGINPERIOD)GetProcAddress( hInstWinMM,
"timeBeginPeriod" );
1115 if( NULL != pTimeBeginPeriod )
1116 pTimeBeginPeriod(1);
1117 FreeLibrary(hInstWinMM);
1119 gTimerThreadHandle = ::CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)
ThreadStub,
1122 gGlobalEvent = ::CreateEvent(NULL,
TRUE,
FALSE, NULL);
1125 char *buf =
new char[MAX_MODULE_NAME32 + 1];
1126 HMODULE hModCore = ::GetModuleHandle(
"libCore.dll");
1128 ::GetModuleFileName(hModCore, buf, MAX_MODULE_NAME32 + 1);
1129 char *pLibName = strstr(buf,
"libCore.dll");
1136 std::this_thread::sleep_for(std::chrono::duration<double, std::nano>(10));
1137 SetConsoleWindowName();
1160 const char *symbol=
name;
1163 while ( (*symbol ==
' ' || *symbol ==
'\t') && *symbol) symbol++;
1166 if (isalpha(symbol[idx]) && symbol[idx+1] ==
':') idx = 2;
1167 if ( (symbol[idx] ==
'/' || symbol[idx] ==
'\\') && symbol[idx+1] ==
'\0') {
1172 Error(
"BaseName",
"name = 0");
1176 char *bslash = (
char *)strrchr(&symbol[idx],
'\\');
1177 char *rslash = (
char *)strrchr(&symbol[idx],
'/');
1178 if (cp = (std::max)(rslash, bslash)) {
1183 return &symbol[idx];
1185 Error(
"BaseName",
"name = 0");
1196 char *dot =
nullptr;
1198 char *fullname =
nullptr;
1201 size_t namelen =
name ? strlen(
name) : 0;
1202 if (
name && namelen > 0) {
1204 fullname =
new char[namelen+5];
1205 strlcpy(fullname,
name,namelen+5);
1206 if ( !strrchr(fullname,
'.') )
1207 strlcat(fullname,
".exe",namelen+5);
1210 dot = strrchr(progname,
'.');
1211 idot = dot ? (size_t)(dot - progname) : strlen(progname);
1213 char *which =
nullptr;
1216 which =
StrDup(fullname);
1227 dirname.
Form(
"%c:%s", driveletter,
d.Data());
1242 progname[idot] =
'\0';
1244 if (which)
delete [] which;
1248 if (::NeedSplash()) {
1261 if (err < 0 || err >= sys_nerr) {
1263 error_msg.
Form(
"errno out of range %d", err);
1266 return sys_errlist[err];
1276 auto res = BCryptGenRandom((BCRYPT_ALG_HANDLE) NULL, (PUCHAR) buf, (ULONG)
len, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
1277 return !res ?
len : -1;
1290 DWORD il =
sizeof(hn);
1291 ::GetComputerName(hn, &il);
1307 if (freq < 37) freq = 440;
1308 if (duration < 0) duration = 100;
1317 gGUIThreadMsgFunc = func;
1340 int fd =
h->GetFd();
1343 if (
h->HasReadInterest()) {
1346 if (
h->HasWriteInterest()) {
1358 if (!
h)
return nullptr;
1378 set_console =
kTRUE;
1391 ::SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleSigHandler,
TRUE);
1402 if (!
h)
return nullptr;
1417 ::SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleSigHandler,
FALSE);
1461 HANDLE snapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,::GetCurrentProcessId());
1466 if (!InitImagehlpFunctions()) {
1467 std::cerr <<
"No stack trace: cannot find (functions in) dbghelp.dll!" << std::endl;
1472 SYSTEM_INFO sysInfo;
1473 ::GetSystemInfo(&sysInfo);
1474 DWORD machineType = IMAGE_FILE_MACHINE_I386;
1475 switch (sysInfo.wProcessorArchitecture) {
1476 case PROCESSOR_ARCHITECTURE_AMD64:
1477 machineType = IMAGE_FILE_MACHINE_AMD64;
1479 case PROCESSOR_ARCHITECTURE_IA64:
1480 machineType = IMAGE_FILE_MACHINE_IA64;
1484 DWORD currentThreadID = ::GetCurrentThreadId();
1485 DWORD currentProcessID = ::GetCurrentProcessId();
1489 THREADENTRY32 threadentry;
1490 threadentry.dwSize =
sizeof(THREADENTRY32);
1491 if (!::Thread32First(snapshot, &threadentry))
return;
1493 std::cerr << std::endl <<
"==========================================" << std::endl;
1494 std::cerr <<
"=============== STACKTRACE ===============" << std::endl;
1495 std::cerr <<
"==========================================" << std::endl << std::endl;
1498 if (threadentry.th32OwnerProcessID != currentProcessID)
1500 HANDLE thread = ::OpenThread(THREAD_GET_CONTEXT|THREAD_SUSPEND_RESUME|THREAD_QUERY_INFORMATION,
1501 FALSE, threadentry.th32ThreadID);
1503 memset(&context, 0,
sizeof(CONTEXT));
1505 if (threadentry.th32ThreadID != currentThreadID) {
1506 ::SuspendThread(thread);
1507 context.ContextFlags = CONTEXT_ALL;
1508 ::GetThreadContext(thread, &context);
1509 ::ResumeThread(thread);
1511 if (fgXcptContext) {
1512 context = *fgXcptContext;
1514 typedef void (WINAPI *RTLCCTXT)(PCONTEXT);
1515 RTLCCTXT p2RtlCCtxt = (RTLCCTXT) ::GetProcAddress(
1516 GetModuleHandle(
"kernel32.dll"),
"RtlCaptureContext");
1518 context.ContextFlags = CONTEXT_ALL;
1519 p2RtlCCtxt(&context);
1525 ::ZeroMemory(&frame,
sizeof(frame));
1527 frame.AddrPC.Mode = AddrModeFlat;
1528 frame.AddrFrame.Mode = AddrModeFlat;
1529 frame.AddrStack.Mode = AddrModeFlat;
1531 frame.AddrPC.Offset = context.Eip;
1532 frame.AddrFrame.Offset = context.Ebp;
1533 frame.AddrStack.Offset = context.Esp;
1534#elif defined(_M_X64)
1535 frame.AddrPC.Offset = context.Rip;
1536 frame.AddrFrame.Offset = context.Rsp;
1537 frame.AddrStack.Offset = context.Rsp;
1538#elif defined(_M_IA64)
1539 frame.AddrPC.Offset = context.StIIP;
1540 frame.AddrFrame.Offset = context.IntSp;
1541 frame.AddrStack.Offset = context.IntSp;
1542 frame.AddrBStore.Offset= context.RsBSP;
1544 std::cerr <<
"Stack traces not supported on your architecture yet." << std::endl;
1549 while (_StackWalk64(machineType, (HANDLE)::GetCurrentProcess(), thread, (LPSTACKFRAME64)&frame,
1550 (LPVOID)&context, (PREAD_PROCESS_MEMORY_ROUTINE)NULL, (PFUNCTION_TABLE_ACCESS_ROUTINE)_SymFunctionTableAccess64,
1551 (PGET_MODULE_BASE_ROUTINE)_SymGetModuleBase64, NULL)) {
1553 std::cerr << std::endl <<
"================ Thread " << iThread++ <<
" ================" << std::endl;
1554 if (!bFirst || threadentry.th32ThreadID != currentThreadID) {
1555 const std::string moduleName = GetModuleName(frame.AddrPC.Offset);
1556 const std::string functionName = GetFunctionName(frame.AddrPC.Offset);
1557 std::cerr <<
" " << moduleName << functionName << std::endl;
1561 ::CloseHandle(thread);
1562 }
while (::Thread32Next(snapshot, &threadentry));
1564 std::cerr << std::endl <<
"==========================================" << std::endl;
1565 std::cerr <<
"============= END STACKTRACE =============" << std::endl;
1566 std::cerr <<
"==========================================" << std::endl << std::endl;
1567 ::CloseHandle(snapshot);
1568 _SymCleanup(GetCurrentProcess());
1577 UInt_t oldmask = _statusfp( );
1603 UInt_t cm = ::_statusfp();
1605 ::_controlfp(cm , _MCW_EM);
1624 if (pendingOnly && gGlobalEvent) ::SetEvent(gGlobalEvent);
1626 Bool_t pollOnce = pendingOnly;
1630 if (
gROOT->GetApplication()) {
1646 ::WaitForSingleObject(gGlobalEvent, 1);
1647 ::ResetEvent(gGlobalEvent);
1673 if (pendingOnly && !pollOnce)
1712 if (!pendingOnly && gGlobalEvent) {
1713 ::WaitForSingleObject(gGlobalEvent, 1);
1714 ::ResetEvent(gGlobalEvent);
1733 rc = WinNTSelect(&t, 0, 0);
1734 if (rc < 0 && rc != -2) {
1735 ::SysError(
"DispatchOneEvent",
"select: read error on %d\n", fd);
1747 rc = WinNTSelect(0, &t, 0);
1748 if (rc < 0 && rc != -2) {
1749 ::SysError(
"DispatchOneEvent",
"select: write error on %d\n", fd);
1811 if (sync == sh->
IsSync()) {
1813 if ((
fSignals->
IsSet(sig) && sigdone == -1) || sigdone == sig) {
1814 if (sigdone == -1) {
1824 if (sigdone != -1)
return kTRUE;
1846 (fddone == fd && read)) {
1856 (fddone == fd && !read)) {
1866 if (fddone != -1)
return kTRUE;
1883 if (dirname.
Length() == 0) {
1900 if (res)
return res;
1920 const char *
proto = (strstr(
name,
"file:///")) ?
"file://" :
"file:";
1923 if (!
name)
return 0;
1927 if (!
name)
return 0;
1950 helper->FreeDirectory(dirp);
1954 ::FindClose(tsfd->fSearchFile);
1966 return helper->GetDirEntry(dirp);
1969 if (tsfd->fFirstFile) {
1974 return (
const char *)tsfd->fFindFileData.cFileName;
1976 if (::FindNextFile(tsfd->fSearchFile, &tsfd->fFindFileData)) {
1977 return (
const char *)tsfd->fFindFileData.cFileName;
2001 return (psz[0] == TEXT(
'\\') && psz[1] == TEXT(
'\\'));
2021#pragma data_seg(".text", "CODE")
2036 if (!IsDBCSLeadByte(*pPath)) {
2041 if ((*pPath == TEXT(
'\\')) && (*(pPath + 1) == 0))
2047 int cBackslashes = 0;
2048 for (
p = pPath + 2; *
p;
p = CharNext(
p)) {
2049 if (*
p == TEXT(
'\\') && (++cBackslashes > 1))
2069 const char *
proto = (strstr(fdir,
"file:///")) ?
"file://" :
"file:";
2072 char *dir =
new char[MAX_PATH];
2073 if (IsShortcut(sdir)) {
2074 if (!ResolveShortCut(sdir, dir, MAX_PATH))
2075 strlcpy(dir, sdir,MAX_PATH);
2078 strlcpy(dir, sdir,MAX_PATH);
2080 size_t nche = strlen(dir)+3;
2081 char *entry =
new char[nche];
2082 struct _stati64 finfo;
2085 strlcpy(entry, dir,nche);
2086 if ((entry[strlen(dir)-1] ==
'/') || (entry[strlen(dir)-1] ==
'\\' )) {
2087 entry[strlen(dir)-1] =
'\0';
2090 strlcat(entry,
"\\",nche);
2092 if (_stati64(entry, &finfo) < 0) {
2098 strlcpy(entry, dir,nche);
2099 if ((entry[strlen(dir)-1] ==
'/') || (entry[strlen(dir)-1] ==
'\\' )) {
2101 entry[strlen(dir)-1] =
'\0';
2103 if (_stati64(entry, &finfo) < 0) {
2110 if (finfo.st_mode & S_IFDIR) {
2111 strlcpy(entry, dir,nche);
2112 if (!(entry[strlen(dir)-1] ==
'/' || entry[strlen(dir)-1] ==
'\\' )) {
2113 strlcat(entry,
"\\",nche);
2115 if (entry[strlen(dir)-1] ==
' ')
2116 entry[strlen(dir)-1] =
'\0';
2117 strlcat(entry,
"*",nche);
2186 char *wdpath =
nullptr;
2187 char drive = driveletter ? toupper( driveletter ) -
'A' + 1 : 0;
2193 if (!(wdpath = ::_getdcwd( (
int)drive, wdpath,
kMAXPATHLEN))) {
2195 Warning(
"WorkingDirectory",
"getcwd() failed");
2219 return std::string(mydir);
2227 const char *
h =
nullptr;
2228 if (!(
h = ::getenv(
"home")))
h = ::getenv(
"HOME");
2235 h = ::getenv(
"HOMESHARE");
2236 if (!
h)
h = ::getenv(
"HOMEDRIVE");
2239 h = ::getenv(
"HOMEPATH");
2244 h = ::getenv(
"USERPROFILE");
2249 if (mydir[1] ==
':')
2250 mydir[0] = toupper(mydir[0]);
2266 if (!dir) dir =
"c:\\";
2284 char tmpName[MAX_PATH];
2286 auto res = ::GetTempFileName(dir ? dir :
TempDirectory(), base.
Data(), 0, tmpName);
2288 ::SysError(
"TempFileName",
"Fail to generate temporary file name");
2293 if (suffix && *suffix) {
2297 ::SysError(
"TempFileName",
"Temporary file %s already exists", base.
Data());
2304 ::SysError(
"TempFileName",
"Fail to rename temporary file to %s", base.
Data());
2310 FILE *fp = fopen(base.
Data(),
"w+");
2312 if (!fp)
::SysError(
"TempFileName",
"error opening %s", base.
Data());
2330 if (!opt || !opt[0]) {
2335 UINT nOldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS);
2339 curdrive = _getdrive();
2340 if (strstr(opt,
"cur")) {
2342 sDrive.
Form(
"%c:", (curdrive +
'A' - 1));
2343 sType.
Form(
"Unknown Drive (%s)", sDrive.
Data());
2344 ::GetVolumeInformation(
Form(
"%s\\", sDrive.
Data()), NULL, 0, NULL, NULL,
2345 NULL, (LPSTR)szFs, 32);
2346 type = ::GetDriveType(sDrive.
Data());
2349 case DRIVE_NO_ROOT_DIR:
2351 case DRIVE_REMOVABLE:
2352 sType.
Form(
"Removable Disk (%s)", sDrive.
Data());
2355 sType.
Form(
"Local Disk (%s)", sDrive.
Data());
2358 sType.
Form(
"Network Drive (%s) (%s)", szFs, sDrive.
Data());
2361 sType.
Form(
"CD/DVD Drive (%s)", sDrive.
Data());
2364 sType.
Form(
"RAM Disk (%s)", sDrive.
Data());
2369 else if (strstr(opt,
"all")) {
2372 if (::GetLogicalDriveStrings(511, szTemp)) {
2373 TCHAR szDrive[3] = TEXT(
" :");
2379 sDrive.
Form(
"%s", szDrive);
2381 if ((sDrive ==
"A:") || (sDrive ==
"B:")) {
2385 sType.
Form(
"Unknown Drive (%s)", sDrive.
Data());
2386 ::GetVolumeInformation(
Form(
"%s\\", sDrive.
Data()), NULL, 0, NULL,
2387 NULL, NULL, (LPSTR)szFs, 32);
2388 type = ::GetDriveType(sDrive.
Data());
2391 case DRIVE_NO_ROOT_DIR:
2393 case DRIVE_REMOVABLE:
2394 sType.
Form(
"Removable Disk (%s)", sDrive.
Data());
2397 sType.
Form(
"Local Disk (%s)", sDrive.
Data());
2400 sType.
Form(
"Network Drive (%s) (%s)", szFs, sDrive.
Data());
2403 sType.
Form(
"CD/DVD Drive (%s)", sDrive.
Data());
2406 sType.
Form(
"RAM Disk (%s)", sDrive.
Data());
2416 ::SetErrorMode(nOldErrorMode);
2439 if (strchr(pathname,
'/') || strchr(pathname,
'\\')) {
2440 const char *rslash = strrchr(pathname,
'/');
2441 const char *bslash = strrchr(pathname,
'\\');
2442 const char *
r = std::max(rslash, bslash);
2443 const char *ptr = pathname;
2453 int len =
r - pathname;
2478 if (!pathname)
return 0;
2479 if (!pathname[0])
return 0;
2485 while(*lpchar ==
' ') lpchar++;
2487 if (isalpha((
int)*lpchar) && *(lpchar+1) ==
':') {
2491 if ( (*lpchar ==
'\\' || *lpchar ==
'/' ) &&
2492 (*(lpchar+1) ==
'\\' || *(lpchar+1) ==
'/') )
return 0;
2505 if (strchr(dir,
':')) idx = 2;
2506 return (dir[idx] ==
'/' || dir[idx] ==
'\\');
2539 const int kBufSize = 1024;
2540 TTHREAD_TLS_ARRAY(
char, kBufSize, temp);
2542 strlcpy(temp,
name, kBufSize);
2543 char *currentChar = temp;
2546 while (*currentChar !=
'\0') {
2547 if (*currentChar ==
'\\') *currentChar =
'/';
2565 UINT nOldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS);
2569 const char *
proto = (strstr(path,
"file:///")) ?
"file://" :
"file:";
2572 ::SetErrorMode(nOldErrorMode);
2577 ::SetErrorMode(nOldErrorMode);
2600 if (dir && dir[0]) {
2602 char last = dir[strlen(dir) - 1];
2603 if (last !=
'/' && last !=
'\\') {
2607 name.ReplaceAll(
"/",
"\\");
2624 if (!ret)
return -1;
2633 int ret = std::rename(
f, t);
2650 struct _stati64 sbuf;
2653 const char *
proto = (strstr(path,
"file:///")) ?
"file://" :
"file:";
2655 size_t l = strlen(newpath);
2657 if (newpath[--
l] !=
'\\' || newpath[--
l] !=
'/') {
2663 if (newpath && ::_stati64(newpath, &sbuf) >= 0) {
2665 buf.
fDev = sbuf.st_dev;
2666 buf.
fIno = sbuf.st_ino;
2667 buf.
fMode = sbuf.st_mode;
2668 buf.
fUid = sbuf.st_uid;
2669 buf.
fGid = sbuf.st_gid;
2670 buf.
fSize = sbuf.st_size;
2671 buf.
fMtime = sbuf.st_mtime;
2672 buf.
fIsLink = IsShortcut(newpath);
2674 char *lpath =
new char[MAX_PATH];
2675 if (IsShortcut(newpath)) {
2676 struct _stati64 sbuf2;
2677 if (ResolveShortCut(newpath, lpath, MAX_PATH)) {
2678 if (::_stati64(lpath, &sbuf2) >= 0) {
2679 buf.
fMode = sbuf2.st_mode;
2705 LPCTSTR lpRootPathName = path;
2708 LPTSTR lpVolumeNameBuffer = 0;
2709 DWORD nVolumeNameSize = 0;
2711 DWORD volumeSerialNumber;
2712 DWORD maximumComponentLength;
2715 DWORD fileSystemFlags;
2718 char fileSystemNameBuffer[512];
2719 DWORD nFileSystemNameSize =
sizeof(fileSystemNameBuffer);
2722 UINT nOldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS);
2723 if (!::GetVolumeInformation(lpRootPathName,
2724 lpVolumeNameBuffer, nVolumeNameSize,
2725 &volumeSerialNumber,
2726 &maximumComponentLength,
2728 fileSystemNameBuffer, nFileSystemNameSize)) {
2730 ::SetErrorMode(nOldErrorMode);
2734 const char *fsNames[] = {
"FAT",
"NTFS" };
2736 for (i = 0; i < 2; i++) {
2737 if (!strncmp(fileSystemNameBuffer, fsNames[i], nFileSystemNameSize))
2742 DWORD sectorsPerCluster;
2743 DWORD bytesPerSector;
2744 DWORD numberOfFreeClusters;
2745 DWORD totalNumberOfClusters;
2747 if (!::GetDiskFreeSpace(lpRootPathName,
2750 &numberOfFreeClusters,
2751 &totalNumberOfClusters)) {
2753 ::SetErrorMode(nOldErrorMode);
2757 ::SetErrorMode(nOldErrorMode);
2759 *bsize = sectorsPerCluster * bytesPerSector;
2760 *blocks = totalNumberOfClusters;
2761 *bfree = numberOfFreeClusters;
2771 struct _stati64 finfo;
2776 char linkname[1024];
2777 LPTSTR lpszFilePart;
2778 TCHAR szPath[MAX_PATH];
2781 typedef BOOL (__stdcall *CREATEHARDLINKPROC)( LPCTSTR, LPCTSTR, LPSECURITY_ATTRIBUTES );
2782 static CREATEHARDLINKPROC _CreateHardLink = 0;
2784 HMODULE hModImagehlp = LoadLibrary(
"Kernel32.dll" );
2789 _CreateHardLink = (CREATEHARDLINKPROC) GetProcAddress( hModImagehlp,
"CreateHardLinkW" );
2791 _CreateHardLink = (CREATEHARDLINKPROC) GetProcAddress( hModImagehlp,
"CreateHardLinkA" );
2793 if (!_CreateHardLink)
2796 dwRet = GetFullPathName(from,
sizeof(szPath) /
sizeof(TCHAR),
2797 szPath, &lpszFilePart);
2799 if (_stati64(szPath, &finfo) < 0)
2802 if (finfo.st_mode & S_IFDIR)
2806 _splitpath(linkname,winDrive,winDir,winName,winExt);
2807 if ((!winDrive[0] ) &&
2809 _splitpath(szPath,winDrive,winDir,winName,winExt);
2810 snprintf(linkname,1024,
"%s\\%s\\%s", winDrive, winDir, to);
2812 else if (!winDrive[0]) {
2813 _splitpath(szPath,winDrive,winDir,winName,winExt);
2814 snprintf(linkname,1024,
"%s\\%s", winDrive, to);
2817 if (!_CreateHardLink(linkname, szPath, NULL))
2830 IShellLink* pShellLink;
2831 IPersistFile* pPersistFile;
2832 WCHAR wszLinkfile[MAX_PATH];
2833 int iWideCharsWritten;
2835 LPTSTR lpszFilePart;
2836 TCHAR szPath[MAX_PATH];
2838 hRes = E_INVALIDARG;
2839 if ((from == NULL) || (!from[0]) || (to == NULL) ||
2845 typedef HRESULT (__stdcall *COINITIALIZEPROC)( LPVOID );
2846 static COINITIALIZEPROC _CoInitialize = 0;
2847 typedef void (__stdcall *COUNINITIALIZEPROC)( void );
2848 static COUNINITIALIZEPROC _CoUninitialize = 0;
2849 typedef HRESULT (__stdcall *COCREATEINSTANCEPROC)( REFCLSID, LPUNKNOWN, DWORD, REFIID, LPVOID );
2850 static COCREATEINSTANCEPROC _CoCreateInstance = 0;
2852 HMODULE hModImagehlp = LoadLibrary(
"ole32.dll" );
2856 _CoInitialize = (COINITIALIZEPROC) GetProcAddress( hModImagehlp,
"CoInitialize" );
2859 _CoUninitialize = (COUNINITIALIZEPROC) GetProcAddress( hModImagehlp,
"CoUninitialize" );
2860 if (!_CoUninitialize)
2862 _CoCreateInstance = (COCREATEINSTANCEPROC) GetProcAddress( hModImagehlp,
"CoCreateInstance" );
2863 if (!_CoCreateInstance)
2870 _CoInitialize(NULL);
2873 dwRet = GetFullPathName(from,
sizeof(szPath) /
sizeof(TCHAR),
2874 szPath, &lpszFilePart);
2875 hRes = _CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
2876 IID_IShellLink, (LPVOID *)&pShellLink);
2877 if (SUCCEEDED(hRes)) {
2879 hRes = pShellLink->SetPath(szPath);
2881 hRes = pShellLink->QueryInterface(IID_IPersistFile, (
void **)&pPersistFile);
2882 if (SUCCEEDED(hRes)){
2883 iWideCharsWritten = MultiByteToWideChar(CP_ACP, 0, linkname.
Data(), -1,
2884 wszLinkfile, MAX_PATH);
2885 hRes = pPersistFile->Save(wszLinkfile,
TRUE);
2886 pPersistFile->Release();
2888 pShellLink->Release();
2906 struct _stati64 finfo;
2908 if (_stati64(
name, &finfo) < 0) {
2912 if (finfo.st_mode & S_IFDIR) {
2913 return ::_rmdir(
name);
2915 return ::_unlink(
name);
2924 if (::ioctlsocket(fd, FIONBIO, (u_long *)1) == SOCKET_ERROR) {
2943 const char *patbuf = (
const char *)patbuf0;
2945 char *cmd =
nullptr;
2951 const char driveletter =
DriveName(patbuf);
2960 if (!
proto.EqualTo(
"file"))
2968 while (*patbuf ==
' ') {
2973 while (*patbuf ==
':') {
2978 while (*patbuf ==
';') {
2984 for (
q = (
char*)patbuf; *
q;
q++) {
2988 if ( (((
q-2)>patbuf) && ( (*(
q-2)!=
';') || !isalpha(*(
q-1)) )) &&
2995 for (
p = patbuf; *
p;
p++) {
3012 char replacement[4];
3015 for (
int k = 0; k<3; k++) replacement[k] = 0x1;
3017 replacement[3] = 0x0;
3021 while ( (pos = patbuf0.
Index(TildaNum,pos)) !=
kNPOS ) {
3022 patbuf0.
Replace(pos, 1, replacement);
3028 Int_t lbuf = ::ExpandEnvironmentStrings(
3034 cmd =
new char[lbuf+1];
3035 ::ExpandEnvironmentStrings(
3054 char newpath[MAX_PATH];
3055 if (IsShortcut(path)) {
3056 if (!ResolveShortCut(path, newpath, MAX_PATH))
3057 strlcpy(newpath, path, MAX_PATH);
3060 strlcpy(newpath, path, MAX_PATH);
3076 return ::_chmod(file,
mode);
3084 return ::umask(
mask);
3094 Error(
"Utime",
"need write permission for %s to change utime", file);
3097 if (!actime) actime = modtime;
3100 t.actime = (time_t)actime;
3101 t.modtime = (time_t)modtime;
3102 return ::utime(file, &t);
3121 return infile.
Data();
3129 Int_t lastDelim = -1;
3130 for(
int i=0; i < exsearch.
Length(); ++i) {
3131 switch( exsearch[i] ) {
3134 if (i-lastDelim!=2) exsearch[i] =
';';
3137 case ';': lastDelim = i;
break;
3144 char *lpFilePart =
nullptr;
3146 ::access(
name,
mode) == 0 && stat(
name, &finfo) == 0 &&
3147 finfo.st_mode & S_IFREG) {
3152 return infile.
Data();
3166 if ((
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) && (::GetVersion() < 0x80000000)) {
3169 HINSTANCE netapi = ::LoadLibrary(
"netapi32.DLL");
3170 if (!netapi)
return kFALSE;
3172 p2NetApiBufferFree = (pfn1)::GetProcAddress(netapi,
"NetApiBufferFree");
3173 p2NetUserGetInfo = (pfn2)::GetProcAddress(netapi,
"NetUserGetInfo");
3174 p2NetLocalGroupGetMembers = (pfn3)::GetProcAddress(netapi,
"NetLocalGroupGetMembers");
3175 p2NetLocalGroupEnum = (pfn4)::GetProcAddress(netapi,
"NetLocalGroupEnum");
3177 if (!p2NetApiBufferFree || !p2NetUserGetInfo ||
3178 !p2NetLocalGroupGetMembers || !p2NetLocalGroupEnum)
return kFALSE;
3189 ::FreeLibrary(netapi);
3199 NET_API_STATUS NetStatus = NERR_Success;
3201 DWORD Index = 0, Total = 0;
3202 DWORD_PTR ResumeHandle = 0;
3203 LOCALGROUP_MEMBERS_INFO_1 *MemberInfo;
3204 WCHAR wszGroupName[256];
3206 DWORD dwLastError = 0;
3208 iRetOp = MultiByteToWideChar (
3210 (DWORD)MB_PRECOMPOSED,
3211 (LPCSTR)lpszGroupName,
3213 (LPWSTR)wszGroupName,
3214 (
int)
sizeof(wszGroupName) );
3217 dwLastError = GetLastError();
3219 p2NetApiBufferFree(Data);
3225 NetStatus = p2NetLocalGroupGetMembers (NULL, wszGroupName, 1,
3226 &Data, 8192, &Index, &Total, &ResumeHandle );
3228 if (NetStatus != NERR_Success || Data == NULL) {
3229 dwLastError = GetLastError();
3231 if (dwLastError == ERROR_ENVVAR_NOT_FOUND) {
3237 NetStatus = p2NetLocalGroupGetMembers ( NULL, wszGroupName, 0,
3238 &Data, 8192, &Index, &Total, &ResumeHandle );
3242 p2NetApiBufferFree(Data);
3247 MemberInfo = (LOCALGROUP_MEMBERS_INFO_1 *)Data;
3250 p2NetApiBufferFree(Data);
3259 NET_API_STATUS NetStatus = NERR_Success;
3261 DWORD Index = 0, Total = 0, i;
3262 DWORD_PTR ResumeHandle = 0;
3263 LOCALGROUP_INFO_0 *GroupInfo;
3264 char szAnsiName[256];
3265 DWORD dwLastError = 0;
3268 NetStatus = p2NetLocalGroupEnum(NULL, 0, &Data, 8192, &Index,
3269 &Total, &ResumeHandle );
3271 if (NetStatus != NERR_Success || Data == NULL) {
3272 dwLastError = GetLastError();
3274 p2NetApiBufferFree(Data);
3279 GroupInfo = (LOCALGROUP_INFO_0 *)Data;
3280 for (i=0; i < Total; i++) {
3282 iRetOp = WideCharToMultiByte (
3285 (LPCWSTR)(GroupInfo->lgrpi0_name),
3288 (
int)(
sizeof(szAnsiName)),
3300 p2NetApiBufferFree(Data);
3312 int &groupIdx,
int &memberIdx)
3314 BOOL bRetOp =
FALSE;
3316 DWORD dwSidSize, dwDomainNameSize;
3319 SID_NAME_USE sidType;
3320 PUCHAR puchar_SubAuthCount = NULL;
3321 SID_IDENTIFIER_AUTHORITY sid_identifier_authority;
3322 PSID_IDENTIFIER_AUTHORITY psid_identifier_authority = NULL;
3323 unsigned char j = 0;
3324 DWORD dwLastError = 0;
3326 pSid = (PSID)bySidBuffer;
3327 dwSidSize =
sizeof(bySidBuffer);
3328 dwDomainNameSize =
sizeof(szDomainName);
3330 bRetOp = LookupAccountName (
3332 (LPCTSTR)lpszAccountName,
3334 (LPDWORD)&dwSidSize,
3335 (LPTSTR)szDomainName,
3336 (LPDWORD)&dwDomainNameSize,
3337 (PSID_NAME_USE)&sidType );
3339 if (bRetOp ==
FALSE) {
3340 dwLastError = GetLastError();
3344 bRetOp = IsValidSid((PSID)pSid);
3346 if (bRetOp ==
FALSE) {
3347 dwLastError = GetLastError();
3352 psid_identifier_authority = GetSidIdentifierAuthority ((PSID)pSid);
3355 memcpy (&sid_identifier_authority, psid_identifier_authority,
3356 sizeof(SID_IDENTIFIER_AUTHORITY));
3359 puchar_SubAuthCount = (PUCHAR)GetSidSubAuthorityCount((PSID)pSid);
3361 j = (
unsigned char)(*puchar_SubAuthCount);
3363 DWORD dwSubAuth = 0;
3364 PDWORD pdwSubAuth = NULL;
3366 pdwSubAuth = (PDWORD)GetSidSubAuthority (
3369 dwSubAuth = *pdwSubAuth;
3388 NET_API_STATUS NetStatus = NERR_Success;
3390 DWORD Index = 0, Total = 0, i;
3391 DWORD_PTR ResumeHandle = 0;
3392 LOCALGROUP_MEMBERS_INFO_1 *MemberInfo;
3393 char szAnsiMemberName[256];
3394 char szFullMemberName[256];
3395 char szMemberHomeDir[256];
3396 WCHAR wszGroupName[256];
3399 DWORD
length =
sizeof (act_name);
3400 DWORD dwLastError = 0;
3401 LPUSER_INFO_11 pUI11Buf = NULL;
3402 NET_API_STATUS nStatus;
3404 iRetOp = MultiByteToWideChar (
3406 (DWORD)MB_PRECOMPOSED,
3407 (LPCSTR)lpszGroupName,
3409 (LPWSTR)wszGroupName,
3410 (
int)
sizeof(wszGroupName) );
3413 dwLastError = GetLastError();
3415 p2NetApiBufferFree(Data);
3419 GetUserName (act_name, &
length);
3423 NetStatus = p2NetLocalGroupGetMembers (NULL, wszGroupName, 1,
3424 &Data, 8192, &Index, &Total, &ResumeHandle );
3426 if (NetStatus != NERR_Success || Data == NULL) {
3427 dwLastError = GetLastError();
3429 if (dwLastError == ERROR_ENVVAR_NOT_FOUND) {
3435 NetStatus = p2NetLocalGroupGetMembers ( NULL, wszGroupName, 0,
3436 &Data, 8192, &Index, &Total, &ResumeHandle );
3440 p2NetApiBufferFree(Data);
3444 MemberInfo = (LOCALGROUP_MEMBERS_INFO_1 *)Data;
3445 for (i=0; i < Total; i++) {
3446 iRetOp = WideCharToMultiByte (
3449 (LPCWSTR)(MemberInfo->lgrmi1_name),
3451 (LPSTR)szAnsiMemberName,
3452 (
int)(
sizeof(szAnsiMemberName)),
3457 dwLastError = GetLastError();
3468 TCHAR szUserName[255]=TEXT(
"");
3469 MultiByteToWideChar(CP_ACP, 0, szAnsiMemberName, -1, (LPWSTR)szUserName, 255);
3473 nStatus = p2NetUserGetInfo(NULL, (LPCWSTR)szUserName, 11, (LPBYTE *)&pUI11Buf);
3477 if (nStatus == NERR_Success) {
3478 if (pUI11Buf != NULL) {
3479 wsprintf(szFullMemberName,
"%S",pUI11Buf->usri11_full_name);
3481 wsprintf(szMemberHomeDir,
"%S",pUI11Buf->usri11_home_dir);
3492 if (pUI11Buf != NULL) {
3493 p2NetApiBufferFree(pUI11Buf);
3498 if (getenv(
"SHELL") == NULL)
3499 putenv ((GetVersion () & 0x80000000) ?
"SHELL=command" :
"SHELL=cmd");
3512 p2NetApiBufferFree(Data);
3522 NET_API_STATUS NetStatus = NERR_Success;
3524 DWORD Index = 0, Total = 0, i;
3525 DWORD_PTR ResumeHandle = 0;
3526 LOCALGROUP_INFO_0 *GroupInfo;
3527 char szAnsiName[256];
3528 DWORD dwLastError = 0;
3529 int iRetOp = 0, iGroupIdx = 0, iMemberIdx = 0;
3531 NetStatus = p2NetLocalGroupEnum(NULL, 0, &Data, 8192, &Index,
3532 &Total, &ResumeHandle );
3534 if (NetStatus != NERR_Success || Data == NULL) {
3535 dwLastError = GetLastError();
3537 p2NetApiBufferFree(Data);
3541 GroupInfo = (LOCALGROUP_INFO_0 *)Data;
3542 for (i=0; i < Total; i++) {
3544 iRetOp = WideCharToMultiByte (
3547 (LPCWSTR)(GroupInfo->lgrpi0_name),
3550 (
int)(
sizeof(szAnsiName)),
3568 p2NetApiBufferFree(Data);
3582 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3587 if (stricmp (
"administrator",
name) == 0)
3597 if (!user || !user[0])
3602 if (!stricmp (user,
fPasswords[i].pw_name)) {
3623 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3628 if (stricmp (
"administrator",
name) == 0)
3650 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3655 if (stricmp (
"administrator",
name) == 0)
3668 struct group *grp =
nullptr;
3691 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3696 if (stricmp (
"administrator",
name) == 0)
3719 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3725 if (stricmp (
"administrator",
name) == 0) {
3727 ug->
fGroup =
"administrators";
3736 ug->
fUser =
"unknown";
3749 for (
int i = 0; i <
fNbUsers; i++) {
3793 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3798 if (stricmp (
"administrator",
name) == 0) {
3799 gr->fGroup =
"administrators";
3803 gr->fGroup =
"users";
3808 gr->fGroup =
"unknown";
3814 struct group *grp =
nullptr;
3816 if (gid ==
fGroups[i].gr_gid) {
3858 const char *env = ::getenv(
name);
3860 if (::_stricmp(
name,
"home") == 0 ) {
3862 }
else if (::_stricmp(
name,
"rootsys") == 0 ) {
3876 return ::system(shellcmd);
3884 return ::_popen(command,
mode);
3892 return ::_pclose(pipe);
3920 gROOT->CloseFiles();
3921 if (
gROOT->GetListOfBrowsers()) {
3924 if (
gROOT->IsBatch())
3925 gROOT->GetListOfBrowsers()->Delete();
3930 if (
b->GetBrowserImp() &&
b->GetBrowserImp()->GetMainFrame())
3932 (((TBrowser*)0x%zx)->GetBrowserImp()->GetMainFrame()->CloseWindow();",
3974 static int fd1=0, fd2=0;
3975 static fpos_t pos1=0, pos2=0;
3985 const char *
m = (
mode[0] ==
'a' ||
mode[0] ==
'w') ?
mode :
"a";
3998 fgetpos(stdout, &pos1);
3999 fd1 = _dup(fileno(stdout));
4001 if ((fout = freopen(file,
m, stdout)) == 0) {
4002 SysError(
"RedirectOutput",
"could not freopen stdout");
4004 _dup2(fd1, fileno(stdout));
4008 fsetpos(stdout, &pos1);
4013 fgetpos(stderr, &pos2);
4014 fd2 = _dup(fileno(stderr));
4015 if ((ferr = freopen(file,
m, stderr)) == 0) {
4016 SysError(
"RedirectOutput",
"could not freopen stderr");
4018 _dup2(fd1, fileno(stdout));
4022 fsetpos(stdout, &pos1);
4024 _dup2(fd2, fileno(stderr));
4028 fsetpos(stderr, &pos2);
4033 fseek(fout, 0, SEEK_END);
4034 fseek(ferr, 0, SEEK_END);
4041 if (_dup2(fd1, fileno(stdout))) {
4042 SysError(
"RedirectOutput",
"could not restore stdout");
4048 fsetpos(stdout, &pos1);
4055 if (_dup2(fd2, fileno(stderr))) {
4056 SysError(
"RedirectOutput",
"could not restore stderr");
4062 fsetpos(stderr, &pos2);
4117 if (
len > 4 && (!stricmp(sLib.
Data()+
len-4,
".dll"))) {
4130 Error(
"DynamicPathName",
4131 "%s does not exist in %s,\nor has wrong file extension (.dll)",
4148#pragma warning(push)
4149#pragma warning(disable:4200)
4166 if (!linkedLibs.
IsNull())
4179 HANDLE hFile, hMapping;
4182 if((hFile = CreateFile(exe,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0))==
INVALID_HANDLE_VALUE) {
4186 if(!(hMapping = CreateFileMapping(hFile,0,PAGE_READONLY|SEC_COMMIT,0,0,0))) {
4191 if(!(basepointer = MapViewOfFile(hMapping,FILE_MAP_READ,0,0,0))) {
4192 CloseHandle(hMapping);
4199 IMAGE_DOS_HEADER *dos_head = (IMAGE_DOS_HEADER *)basepointer;
4202 IMAGE_FILE_HEADER _head;
4203 IMAGE_OPTIONAL_HEADER opt_head;
4204 IMAGE_SECTION_HEADER section_header[];
4206 struct header *pheader;
4207 const IMAGE_SECTION_HEADER * section_header;
4209 if(dos_head->e_magic!=
'ZM') {
4214 pheader = (
struct header *)((
char*)dos_head + dos_head->e_lfanew);
4216 if(IsBadReadPtr(pheader,
sizeof(
struct header))) {
4220 if(pheader->signature!=IMAGE_NT_SIGNATURE) {
4221 switch((
unsigned short)pheader->signature) {
4222 case IMAGE_DOS_SIGNATURE:
4225 case IMAGE_OS2_SIGNATURE:
4228 case IMAGE_OS2_SIGNATURE_LE:
4236#define isin(address,start,length) ((address)>=(start) && (address)<(start)+(length))
4239 for(sect=0,section_header=pheader->section_header;
4240 sect<pheader->_head.NumberOfSections;sect++,section_header++) {
4242 const void *
const section_data =
4243 (
char*)basepointer + section_header->PointerToRawData;
4244 for(directory=0;directory<IMAGE_NUMBEROF_DIRECTORY_ENTRIES;directory++) {
4245 if(
isin(pheader->opt_head.DataDirectory[directory].VirtualAddress,
4246 section_header->VirtualAddress,
4247 section_header->SizeOfRawData)) {
4248 const IMAGE_IMPORT_DESCRIPTOR *stuff_start =
4249 (IMAGE_IMPORT_DESCRIPTOR *)((
char*)section_data +
4250 (pheader->opt_head.DataDirectory[directory].VirtualAddress -
4251 section_header->VirtualAddress));
4254 const unsigned stuff_length =
4255 pheader->opt_head.DataDirectory[directory].Size;
4256 if(directory == IMAGE_DIRECTORY_ENTRY_IMPORT) {
4257 while(!IsBadReadPtr(stuff_start,
sizeof(*stuff_start)) &&
4258 stuff_start->Name) {
4259 TString dll = (
char*)section_data +
4260 ((DWORD)(stuff_start->Name)) -
4261 section_header->VirtualAddress;
4265 char *winPath = getenv(
"windir");
4266 _splitpath(winPath,winDrive,winDir,winName,winExt);
4267 if(!strstr(dllPath, winDir)) {
4268 if (!linkedLibs.
IsNull())
4270 linkedLibs += dllPath;
4282 UnmapViewOfFile(basepointer);
4283 CloseHandle(hMapping);
4314 char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];
4317 std::vector<std::string> all_libs, libpaths;
4323 while (getline(libenv, str,
';')) {
4324 libpaths.push_back(str);
4327 std::stringstream libraries(libs.
Data());
4328 while (getline(libraries, str,
' ')) {
4329 std::string::size_type first, last;
4332 if (str.rfind(
"-L", 0) == 0) {
4333 first = str.find_first_of(
'%');
4334 last = str.find_last_of(
'%');
4335 if ((first != std::string::npos) && (last != std::string::npos) &&
4340 std::string var = str.substr(first+1, last-first-1);
4345 env += str.substr(last+1);
4346 libpaths.push_back(env);
4350 ntlibs.
Append(str.c_str());
4355 last = str.rfind(
".dll");
4356 if (last != std::string::npos)
4357 str.replace(last, 4,
".lib");
4358 last = str.rfind(
".DLL");
4359 if (last != std::string::npos)
4360 str.replace(last, 4,
".lib");
4361 if (str.rfind(
".lib") != std::string::npos ||
4362 str.rfind(
".LIB") != std::string::npos) {
4364 if (_stat( str.c_str(), &buf ) == 0) {
4366 ntlibs.
Append(str.c_str());
4376 size_t requiredSize;
4377 getenv_s( &requiredSize, NULL, 0,
"WinDir");
4378 if (requiredSize == 0) {
4379 windir = strdup(
":\\WINDOWS");
4381 windir = (
char*)
malloc(requiredSize *
sizeof(
char));
4383 windir = strdup(
":\\WINDOWS");
4385 getenv_s( &requiredSize, windir, requiredSize,
"WinDir" );
4388 if (str.find(windir) == std::string::npos) {
4389 _splitpath(str.c_str(), drive, dir, fname, ext);
4390 std::string libname(fname);
4392 all_libs.push_back(libname);
4396 for (
auto lib : all_libs) {
4398 for (
auto libpath : libpaths) {
4400 std::string path_lib(libpath);
4403 if (_stat( path_lib.c_str(), &buf ) == 0) {
4405 ntlibs.
Append(lib.c_str());
4434 if (!ti)
return nullptr;
4491 FILETIME ftFileTime;
4495 ::GetSystemTimeAsFileTime(&ftRealTime.ftFileTime);
4504 OSVERSIONINFO OsVersionInfo;
4513 OsVersionInfo.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
4514 GetVersionEx(&OsVersionInfo);
4515 if (OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
4521 FILETIME ftFileTime;
4526 FILETIME ftFileTime;
4530 HANDLE hThread = GetCurrentThread();
4531 ret = GetThreadTimes (hThread, &ftCreate, &ftExit,
4532 &ftKernel.ftFileTime,
4533 &ftUser.ftFileTime);
4535 ret = ::GetLastError();
4536 ::Error(
"GetCPUTime",
" Error on GetProcessTimes 0x%lx", (
int)ret);
4556 static time_t jan95 = 0;
4567 jan95 = mktime(&tp);
4568 if ((
int)jan95 == -1) {
4569 ::SysError(
"TWinNTSystem::Now",
"error converting 950001 0:00 to time_t");
4576 return TTime((now.time-(
Long_t)jan95)*1000 + now.millitm);
4586 std::this_thread::sleep_for(std::chrono::milliseconds(milliSec));
4602 if (
h->HasReadInterest())
4604 if (
h->HasWriteInterest())
4606 h->ResetReadyMask();
4608 rc = WinNTSelect(&rd, &wr, to);
4637 if (
h->HasReadInterest())
4639 if (
h->HasWriteInterest())
4641 h->ResetReadyMask();
4642 rc = WinNTSelect(&rd, &wr, to);
4664 if ((sp = ::getservbyname(servicename,
kProtocolName)) == 0) {
4665 Error(
"GetServiceByName",
"no service \"%s\" with protocol \"%s\"\n",
4669 return ::ntohs(sp->s_port);
4680 if ((sp = ::getservbyport(::htons(port),
kProtocolName)) == 0) {
4681 return Form(
"%d", port);
4691 struct hostent *host_ptr;
4696 if ((addr = ::inet_addr(hostname)) != INADDR_NONE) {
4698 if ((host_ptr = ::gethostbyaddr((
const char *)&addr,
4699 sizeof(addr), AF_INET))) {
4700 host = host_ptr->h_name;
4704 for (i = 1; host_ptr->h_addr_list[i]; i++) {
4705 memcpy(&addr2, host_ptr->h_addr_list[i], host_ptr->h_length);
4706 a.AddAddress(ntohl(addr2));
4708 for (i = 0; host_ptr->h_aliases[i]; i++)
4709 a.AddAlias(host_ptr->h_aliases[i]);
4712 host =
"UnNamedHost";
4714 }
else if ((host_ptr = ::gethostbyname(hostname))) {
4716 if (host_ptr->h_addrtype != AF_INET) {
4717 Error(
"GetHostByName",
"%s is not an internet host\n", hostname);
4720 memcpy(&addr, host_ptr->h_addr, host_ptr->h_length);
4721 host = host_ptr->h_name;
4722 type = host_ptr->h_addrtype;
4726 for (i = 1; host_ptr->h_addr_list[i]; i++) {
4727 memcpy(&addr2, host_ptr->h_addr_list[i], host_ptr->h_length);
4728 a.AddAddress(ntohl(addr2));
4730 for (i = 0; host_ptr->h_aliases[i]; i++)
4731 a.AddAlias(host_ptr->h_aliases[i]);
4734 if (
gDebug > 0)
Error(
"GetHostByName",
"unknown host %s", hostname);
4747 struct sockaddr_in addr;
4748 int len =
sizeof(addr);
4750 if (::getpeername(sock, (
struct sockaddr *)&addr, &
len) == SOCKET_ERROR) {
4755 struct hostent *host_ptr;
4756 const char *hostname;
4760 if ((host_ptr = ::gethostbyaddr((
const char *)&addr.sin_addr,
4761 sizeof(addr.sin_addr), AF_INET))) {
4762 memcpy(&iaddr, host_ptr->h_addr, host_ptr->h_length);
4763 hostname = host_ptr->h_name;
4764 family = host_ptr->h_addrtype;
4766 memcpy(&iaddr, &addr.sin_addr,
sizeof(addr.sin_addr));
4771 return TInetAddress(hostname, ::ntohl(iaddr), family, ::ntohs(addr.sin_port));
4780 struct sockaddr_in addr;
4781 int len =
sizeof(addr);
4783 if (::getsockname(sock, (
struct sockaddr *)&addr, &
len) == SOCKET_ERROR) {
4788 struct hostent *host_ptr;
4789 const char *hostname;
4793 if ((host_ptr = ::gethostbyaddr((
const char *)&addr.sin_addr,
4794 sizeof(addr.sin_addr), AF_INET))) {
4795 memcpy(&iaddr, host_ptr->h_addr, host_ptr->h_length);
4796 hostname = host_ptr->h_name;
4797 family = host_ptr->h_addrtype;
4799 memcpy(&iaddr, &addr.sin_addr,
sizeof(addr.sin_addr));
4804 return TInetAddress(hostname, ::ntohl(iaddr), family, ::ntohs(addr.sin_port));
4816 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"socket");
4820 struct sockaddr_in inserver;
4821 memset(&inserver, 0,
sizeof(inserver));
4822 inserver.sin_family = AF_INET;
4823 inserver.sin_addr.s_addr = ::htonl(INADDR_LOOPBACK);
4824 inserver.sin_port = port;
4828 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver)) == SOCKET_ERROR) {
4829 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"bind");
4834 if (::listen(sock, backlog)) {
4835 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"listen");
4847 if (!sockpath || strlen(sockpath) <= 0) {
4848 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"socket path undefined");
4852 struct sockaddr_in myaddr;
4854 int len =
sizeof myaddr;
4859 if ((sock =
socket(AF_INET, SOCK_STREAM, 0)) < 0) {
4860 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"socket");
4864 memset(&myaddr, 0,
sizeof(myaddr));
4865 myaddr.sin_port = 0;
4866 myaddr.sin_family = AF_INET;
4867 myaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
4869 rc = bind(sock, (
struct sockaddr *)&myaddr,
len);
4871 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"bind");
4874 rc = getsockname(sock, (
struct sockaddr *)&myaddr, &
len);
4876 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"getsockname");
4879 TString socketpath = sockpath;
4881 fp = fopen(socketpath,
"wb");
4883 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"fopen");
4886 fprintf(fp,
"%d", myaddr.sin_port);
4890 if (listen(sock, backlog)) {
4891 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"listen");
4903 if (
socket == -1)
return;
4907 ::shutdown(sock, 2);
4909 struct linger linger = {0, 0};
4910 ::setsockopt(sock, SOL_SOCKET, SO_LINGER, (
char *) &linger,
sizeof(linger));
4911 while (
::closesocket(sock) == SOCKET_ERROR && WSAGetLastError() == WSAEINTR) {
4925 if (WinNTRecv(sock, &header,
sizeof(header), 0) > 0) {
4926 int count = ::ntohl(header);
4929 Error(
"RecvBuf",
"record header exceeds buffer size");
4931 }
else if (count > 0) {
4932 if (WinNTRecv(sock, buf, count, 0) < 0) {
4933 Error(
"RecvBuf",
"cannot receive buffer");
4950 if (WinNTSend(sock, &header,
sizeof(header), 0) < 0) {
4951 Error(
"SendBuf",
"cannot send header");
4955 if (WinNTSend(sock, buf,
length, 0) < 0) {
4956 Error(
"SendBuf",
"cannot send buffer");
4996 if ((
n = WinNTRecv(sock, buf,
length, flag)) <= 0) {
4998 Error(
"RecvRaw",
"cannot receive buffer");
5032 if ((
n = WinNTSend(sock, buf,
length, flag)) <= 0) {
5034 Error(
"SendRaw",
"cannot send buffer");
5047 if (
socket == -1)
return -1;
5052 if (::setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
5053 ::SysError(
"SetSockOpt",
"setsockopt(SO_SNDBUF)");
5058 if (::setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
5059 ::SysError(
"SetSockOpt",
"setsockopt(SO_RCVBUF)");
5064 if (::setsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
5065 SysError(
"SetSockOpt",
"setsockopt(SO_OOBINLINE)");
5070 if (::setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
5071 ::SysError(
"SetSockOpt",
"setsockopt(SO_KEEPALIVE)");
5076 if (::setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
5077 ::SysError(
"SetSockOpt",
"setsockopt(SO_REUSEADDR)");
5082 if (::setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
5083 ::SysError(
"SetSockOpt",
"setsockopt(TCP_NODELAY)");
5088 if (::ioctlsocket(sock, FIONBIO, &val) == SOCKET_ERROR) {
5095 if (::ioctl(sock, SIOCSPGRP, &val) == -1) {
5096 ::SysError(
"SetSockOpt",
"ioctl(SIOCSPGRP)");
5104 Error(
"SetSockOpt",
"illegal option (%d)", opt);
5116 if (
socket == -1)
return -1;
5119 int optlen =
sizeof(*val);
5123 if (::getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)val, &optlen) == SOCKET_ERROR) {
5124 ::SysError(
"GetSockOpt",
"getsockopt(SO_SNDBUF)");
5129 if (::getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)val, &optlen) == SOCKET_ERROR) {
5130 ::SysError(
"GetSockOpt",
"getsockopt(SO_RCVBUF)");
5135 if (::getsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)val, &optlen) == SOCKET_ERROR) {
5136 ::SysError(
"GetSockOpt",
"getsockopt(SO_OOBINLINE)");
5141 if (::getsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)val, &optlen) == SOCKET_ERROR) {
5142 ::SysError(
"GetSockOpt",
"getsockopt(SO_KEEPALIVE)");
5147 if (::getsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)val, &optlen) == SOCKET_ERROR) {
5148 ::SysError(
"GetSockOpt",
"getsockopt(SO_REUSEADDR)");
5153 if (::getsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)val, &optlen) == SOCKET_ERROR) {
5154 ::SysError(
"GetSockOpt",
"getsockopt(TCP_NODELAY)");
5170 if (::ioctlsocket(sock, SIOCGPGRP, (u_long*)val) == SOCKET_ERROR) {
5171 ::SysError(
"GetSockOpt",
"ioctl(SIOCGPGRP)");
5177 if (::ioctlsocket(sock, SIOCATMARK, (u_long*)val) == SOCKET_ERROR) {
5178 ::SysError(
"GetSockOpt",
"ioctl(SIOCATMARK)");
5183 if (::ioctlsocket(sock, FIONREAD, (u_long*)val) == SOCKET_ERROR) {
5189 Error(
"GetSockOpt",
"illegal option (%d)", opt);
5201 int tcpwindowsize,
const char *protocol)
5206 if (!strcmp(servername,
"unix")) {
5210 (servername[1] ==
':' && servername[2] ==
'/')) {
5214 if (!strcmp(protocol,
"udp")){
5221 sport = ::htons(port);
5225 if (!addr.
IsValid())
return -1;
5228 struct sockaddr_in server;
5229 memset(&server, 0,
sizeof(server));
5230 memcpy(&server.sin_addr, &adr,
sizeof(adr));
5232 server.sin_port = sport;
5237 ::SysError(
"TWinNTSystem::WinNTConnectTcp",
"socket");
5241 if (tcpwindowsize > 0) {
5246 if (::connect(sock, (
struct sockaddr*) &server,
sizeof(server)) ==
INVALID_SOCKET) {
5259 struct sockaddr_in myaddr;
5262 memset(&myaddr, 0,
sizeof(myaddr));
5263 myaddr.sin_family = AF_INET;
5264 myaddr.sin_port = port;
5265 myaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
5268 if ((sock =
socket(AF_INET, SOCK_STREAM, 0)) < 0) {
5269 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"socket");
5273 while ((connect(sock, (
struct sockaddr *)&myaddr,
sizeof myaddr)) == -1) {
5277 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"connect");
5293 if (!sockpath || strlen(sockpath) <= 0) {
5294 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"socket path undefined");
5297 TString socketpath = sockpath;
5299 fp = fopen(socketpath.
Data(),
"rb");
5301 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"fopen");
5304 fscanf(fp,
"%d", &port);
5307 if (port < 0 || port > 65535) {
5308 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"invalid port");
5326 sport = htons(port);
5329 if (!addr.
IsValid())
return -1;
5332 struct sockaddr_in server;
5333 memset(&server, 0,
sizeof(server));
5334 memcpy(&server.sin_addr, &adr,
sizeof(adr));
5336 server.sin_port = sport;
5340 if ((sock =
socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
5341 ::SysError(
"TWinNTSystem::WinNTUdpConnect",
"socket (%s:%d)",
5346 while (connect(sock, (
struct sockaddr*) &server,
sizeof(server)) == -1) {
5350 ::SysError(
"TWinNTSystem::WinNTUdpConnect",
"connect (%s:%d)",
5368 const char *protocol)
5389 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
5390 short tryport = kSOCKET_MINPORT;
5395 sport = ::htons(port);
5398 if (port == 0 && reuse) {
5399 ::Error(
"TWinNTSystem::WinNTTcpService",
"cannot do a port scan while reuse is true");
5406 sport = ::htons(port);
5411 if ((sock =
::socket(AF_INET, SOCK_STREAM, 0)) < 0) {
5412 ::SysError(
"TWinNTSystem::WinNTTcpService",
"socket");
5420 if (tcpwindowsize > 0) {
5425 struct sockaddr_in inserver;
5426 memset(&inserver, 0,
sizeof(inserver));
5427 inserver.sin_family = AF_INET;
5428 inserver.sin_addr.s_addr = ::htonl(INADDR_ANY);
5429 inserver.sin_port = sport;
5433 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver)) == SOCKET_ERROR) {
5434 ::SysError(
"TWinNTSystem::WinNTTcpService",
"bind");
5440 inserver.sin_port = ::htons(tryport);
5441 bret = ::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
5443 }
while (bret == SOCKET_ERROR && WSAGetLastError() == WSAEADDRINUSE &&
5444 tryport < kSOCKET_MAXPORT);
5445 if (bret == SOCKET_ERROR) {
5446 ::SysError(
"TWinNTSystem::WinNTTcpService",
"bind (port scan)");
5452 if (::listen(sock, backlog) == SOCKET_ERROR) {
5453 ::SysError(
"TWinNTSystem::WinNTTcpService",
"listen");
5470 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
5471 short sport, tryport = kSOCKET_MINPORT;
5477 sport = htons(port);
5481 if ((sock =
socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
5482 ::SysError(
"TUnixSystem::UnixUdpService",
"socket");
5486 struct sockaddr_in inserver;
5487 memset(&inserver, 0,
sizeof(inserver));
5488 inserver.sin_family = AF_INET;
5489 inserver.sin_addr.s_addr = htonl(INADDR_ANY);
5490 inserver.sin_port = sport;
5494 if (bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver))) {
5495 ::SysError(
"TWinNTSystem::AnnounceUdpService",
"bind");
5501 inserver.sin_port = htons(tryport);
5502 bret = bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
5504 }
while (bret == SOCKET_ERROR && WSAGetLastError() == WSAEADDRINUSE &&
5505 tryport < kSOCKET_MAXPORT);
5507 ::SysError(
"TWinNTSystem::AnnounceUdpService",
"bind (port scan)");
5513 if (listen(sock, backlog)) {
5514 ::SysError(
"TWinNTSystem::AnnounceUdpService",
"listen");
5532 (::WSAGetLastError() == WSAEINTR)) {
5537 if (::WSAGetLastError() == WSAEWOULDBLOCK) {
5551#define SystemBasicInformation 0
5552#define SystemPerformanceInformation 2
5592#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + (double)((x).LowPart))
5600 LARGE_INTEGER ulFreq, ulTicks, ulValue, ulStartCounter;
5604 if (QueryPerformanceFrequency(&ulFreq)) {
5606 QueryPerformanceCounter(&ulTicks);
5609 ulValue.QuadPart = ulTicks.QuadPart + ulFreq.QuadPart/10;
5610 ulStartCounter.QuadPart =
__rdtsc();
5614 QueryPerformanceCounter(&ulTicks);
5615 }
while (ulTicks.QuadPart <= ulValue.QuadPart);
5617 return (DWORD)((
__rdtsc() - ulStartCounter.QuadPart)/100000);
5625#define SM_SERVERR2 89
5626typedef void (WINAPI *
PGNSI)(LPSYSTEM_INFO);
5632 OSVERSIONINFOEX osvi;
5635 BOOL bOsVersionInfoEx;
5636 static char *strReturn =
nullptr;
5640 strReturn =
new char[2048];
5644 ZeroMemory(&si,
sizeof(SYSTEM_INFO));
5645 ZeroMemory(&osvi,
sizeof(OSVERSIONINFOEX));
5650 osvi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFOEX);
5652 if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
5654 osvi.dwOSVersionInfoSize =
sizeof (OSVERSIONINFO);
5655 if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
5660 pGNSI = (
PGNSI) GetProcAddress( GetModuleHandle(
"kernel32.dll"),
5661 "GetNativeSystemInfo");
5664 else GetSystemInfo(&si);
5666 switch (osvi.dwPlatformId)
5669 case VER_PLATFORM_WIN32_NT:
5672 if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 )
5674 if( osvi.wProductType == VER_NT_WORKSTATION )
5675 strlcpy(strReturn,
"Microsoft Windows Vista ",2048);
5676 else strlcpy(strReturn,
"Windows Server \"Longhorn\" " ,2048);
5678 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
5681 strlcpy(strReturn,
"Microsoft Windows Server 2003 \"R2\" ",2048);
5682 else if( osvi.wProductType == VER_NT_WORKSTATION &&
5683 si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
5685 strlcpy(strReturn,
"Microsoft Windows XP Professional x64 Edition ",2048);
5687 else strlcpy(strReturn,
"Microsoft Windows Server 2003, ",2048);
5689 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
5690 strlcpy(strReturn,
"Microsoft Windows XP ",2048);
5692 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
5693 strlcpy(strReturn,
"Microsoft Windows 2000 ",2048);
5695 if ( osvi.dwMajorVersion <= 4 )
5696 strlcpy(strReturn,
"Microsoft Windows NT ",2048);
5699 if( bOsVersionInfoEx )
5702 if ( osvi.wProductType == VER_NT_WORKSTATION &&
5703 si.wProcessorArchitecture!=PROCESSOR_ARCHITECTURE_AMD64)
5705 if( osvi.dwMajorVersion == 4 )
5706 strlcat(strReturn,
"Workstation 4.0 ",2048 );
5707 else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
5708 strlcat(strReturn,
"Home Edition " ,2048);
5709 else strlcat(strReturn,
"Professional " ,2048);
5712 else if ( osvi.wProductType == VER_NT_SERVER ||
5713 osvi.wProductType == VER_NT_DOMAIN_CONTROLLER )
5715 if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==2)
5717 if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_IA64 )
5719 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
5720 strlcat(strReturn,
"Datacenter Edition for Itanium-based Systems",2048 );
5721 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5722 strlcat(strReturn,
"Enterprise Edition for Itanium-based Systems" ,2048);
5724 else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
5726 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
5727 strlcat(strReturn,
"Datacenter x64 Edition ",2048 );
5728 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5729 strlcat(strReturn,
"Enterprise x64 Edition ",2048 );
5730 else strlcat(strReturn,
"Standard x64 Edition ",2048 );
5734 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
5735 strlcat(strReturn,
"Datacenter Edition ",2048 );
5736 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5737 strlcat(strReturn,
"Enterprise Edition ",2048 );
5738 else if ( osvi.wSuiteMask == VER_SUITE_BLADE )
5739 strlcat(strReturn,
"Web Edition " ,2048);
5740 else strlcat(strReturn,
"Standard Edition ",2048 );
5743 else if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==0)
5745 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
5746 strlcat(strReturn,
"Datacenter Server ",2048 );
5747 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5748 strlcat(strReturn,
"Advanced Server ",2048 );
5749 else strlcat(strReturn,
"Server ",2048 );
5753 if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5754 strlcat(strReturn,
"Server 4.0, Enterprise Edition " ,2048);
5755 else strlcat(strReturn,
"Server 4.0 ",2048 );
5764 DWORD dwBufLen=
BUFSIZE*
sizeof(TCHAR);
5767 lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
5768 "SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
5769 0, KEY_QUERY_VALUE, &hKey );
5770 if( lRet != ERROR_SUCCESS )
5773 lRet = RegQueryValueEx( hKey,
"ProductType", NULL, NULL,
5774 (LPBYTE) szProductType, &dwBufLen);
5775 RegCloseKey( hKey );
5777 if( (lRet != ERROR_SUCCESS) || (dwBufLen >
BUFSIZE*
sizeof(TCHAR)) )
5780 if ( lstrcmpi(
"WINNT", szProductType) == 0 )
5781 strlcat(strReturn,
"Workstation " ,2048);
5782 if ( lstrcmpi(
"LANMANNT", szProductType) == 0 )
5783 strlcat(strReturn,
"Server " ,2048);
5784 if ( lstrcmpi(
"SERVERNT", szProductType) == 0 )
5785 strlcat(strReturn,
"Advanced Server " ,2048);
5786 snprintf(temp,512,
"%d.%d ", osvi.dwMajorVersion, osvi.dwMinorVersion);
5787 strlcat(strReturn, temp,2048);
5792 if( osvi.dwMajorVersion == 4 &&
5793 lstrcmpi( osvi.szCSDVersion,
"Service Pack 6" ) == 0 )
5799 lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
5800 "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009",
5801 0, KEY_QUERY_VALUE, &hKey );
5802 if( lRet == ERROR_SUCCESS ) {
5803 snprintf(temp, 512,
"Service Pack 6a (Build %d)", osvi.dwBuildNumber & 0xFFFF );
5804 strlcat(strReturn, temp,2048 );
5808 snprintf(temp,512,
"%s (Build %d)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
5809 strlcat(strReturn, temp,2048 );
5812 RegCloseKey( hKey );
5816 snprintf(temp, 512,
"%s (Build %d)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
5817 strlcat(strReturn, temp,2048 );
5823 case VER_PLATFORM_WIN32_WINDOWS:
5825 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
5827 strlcpy(strReturn,
"Microsoft Windows 95 ",2048);
5828 if (osvi.szCSDVersion[1]==
'C' || osvi.szCSDVersion[1]==
'B')
5829 strlcat(strReturn,
"OSR2 " ,2048);
5832 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
5834 strlcpy(strReturn,
"Microsoft Windows 98 ",2048);
5835 if ( osvi.szCSDVersion[1]==
'A' || osvi.szCSDVersion[1]==
'B')
5836 strlcat(strReturn,
"SE ",2048 );
5839 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
5841 strlcpy(strReturn,
"Microsoft Windows Millennium Edition",2048);
5845 case VER_PLATFORM_WIN32s:
5846 strlcpy(strReturn,
"Microsoft Win32s",2048);
5857 unsigned nHighestFeatureEx;
5861 nHighestFeatureEx = (unsigned)nBuff[0];
5863 if (nHighestFeatureEx >= 0x80000006) {
5865 return (((
unsigned)nBuff[2])>>16);
5876 SYSTEM_INFO sysInfo;
5877 MEMORYSTATUSEX statex;
5878 OSVERSIONINFO OsVersionInfo;
5880 char szKeyValueString[80];
5881 DWORD szKeyValueDword;
5886 NtQuerySystemInformation = (
PROCNTQSI)GetProcAddress(
5887 GetModuleHandle(
"ntdll"),
"NtQuerySystemInformation");
5889 if (!NtQuerySystemInformation) {
5891 "Error on GetProcAddress(NtQuerySystemInformation)");
5896 &SysPerfInfo,
sizeof(SysPerfInfo),
5898 OsVersionInfo.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
5899 GetVersionEx(&OsVersionInfo);
5900 GetSystemInfo(&sysInfo);
5901 statex.dwLength =
sizeof(statex);
5902 if (!GlobalMemoryStatusEx(&statex)) {
5903 ::Error(
"GetWinNTSysInfo",
"Error on GlobalMemoryStatusEx()");
5906 sysinfo->
fCpus = sysInfo.dwNumberOfProcessors;
5915 status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"HARDWARE\\DESCRIPTION\\System",
5916 0, KEY_QUERY_VALUE, &hKey);
5917 if (status == ERROR_SUCCESS) {
5918 dwBufLen =
sizeof(szKeyValueString);
5919 RegQueryValueEx(hKey,
"Identifier", NULL, NULL,(LPBYTE)szKeyValueString,
5921 sysinfo->
fModel = szKeyValueString;
5924 status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
5925 "Hardware\\Description\\System\\CentralProcessor\\0",
5926 0, KEY_QUERY_VALUE, &hKey);
5927 if (status == ERROR_SUCCESS) {
5928 dwBufLen =
sizeof(szKeyValueString);
5929 status = RegQueryValueEx(hKey,
"ProcessorNameString", NULL, NULL,
5930 (LPBYTE)szKeyValueString, &dwBufLen);
5931 if (status == ERROR_SUCCESS)
5932 sysinfo->
fCpuType = szKeyValueString;
5933 dwBufLen =
sizeof(DWORD);
5934 status = RegQueryValueEx(hKey,
"~MHz",NULL,NULL,(LPBYTE)&szKeyValueDword,
5936 if ((status == ERROR_SUCCESS) && ((sysinfo->
fCpuSpeed <= 0) ||
5937 (sysinfo->
fCpuSpeed < (szKeyValueDword >> 1))))
5951 SYSTEM_INFO sysInfo;
5952 Float_t idle_ratio, kernel_ratio, user_ratio, total_ratio;
5953 FILETIME ft_sys_idle, ft_sys_kernel, ft_sys_user, ft_fun_time;
5954 SYSTEMTIME st_fun_time;
5956 ULARGE_INTEGER ul_sys_idle, ul_sys_kernel, ul_sys_user;
5957 static ULARGE_INTEGER ul_sys_idleold = {0, 0};
5958 static ULARGE_INTEGER ul_sys_kernelold = {0, 0};
5959 static ULARGE_INTEGER ul_sys_userold = {0, 0};
5960 ULARGE_INTEGER ul_sys_idle_diff, ul_sys_kernel_diff, ul_sys_user_diff;
5962 ULARGE_INTEGER ul_fun_time;
5963 ULARGE_INTEGER ul_fun_timeold = {0, 0};
5964 ULARGE_INTEGER ul_fun_time_diff;
5966 typedef BOOL (__stdcall *GetSystemTimesProc)( LPFILETIME lpIdleTime,
5967 LPFILETIME lpKernelTime, LPFILETIME lpUserTime );
5968 static GetSystemTimesProc pGetSystemTimes = 0;
5970 HMODULE hModImagehlp = LoadLibrary(
"Kernel32.dll" );
5971 if (!hModImagehlp) {
5972 ::Error(
"GetWinNTCpuInfo",
"Error on LoadLibrary(Kernel32.dll)");
5976 pGetSystemTimes = (GetSystemTimesProc) GetProcAddress( hModImagehlp,
5978 if (!pGetSystemTimes) {
5979 ::Error(
"GetWinNTCpuInfo",
"Error on GetProcAddress(GetSystemTimes)");
5982 GetSystemInfo(&sysInfo);
5985 pGetSystemTimes(&ft_sys_idle,&ft_sys_kernel,&ft_sys_user);
5986 GetSystemTime(&st_fun_time);
5987 SystemTimeToFileTime(&st_fun_time,&ft_fun_time);
5989 memcpy(&ul_sys_idle, &ft_sys_idle,
sizeof(FILETIME));
5990 memcpy(&ul_sys_kernel, &ft_sys_kernel,
sizeof(FILETIME));
5991 memcpy(&ul_sys_user, &ft_sys_user,
sizeof(FILETIME));
5992 memcpy(&ul_fun_time, &ft_fun_time,
sizeof(FILETIME));
5994 ul_sys_idle_diff.QuadPart = ul_sys_idle.QuadPart -
5995 ul_sys_idleold.QuadPart;
5996 ul_sys_kernel_diff.QuadPart = ul_sys_kernel.QuadPart -
5997 ul_sys_kernelold.QuadPart;
5998 ul_sys_user_diff.QuadPart = ul_sys_user.QuadPart -
5999 ul_sys_userold.QuadPart;
6001 ul_fun_time_diff.QuadPart = ul_fun_time.QuadPart -
6002 ul_fun_timeold.QuadPart;
6004 ul_sys_idleold.QuadPart = ul_sys_idle.QuadPart;
6005 ul_sys_kernelold.QuadPart = ul_sys_kernel.QuadPart;
6006 ul_sys_userold.QuadPart = ul_sys_user.QuadPart;
6008 if (ul_fun_timeold.QuadPart == 0) {
6010 ul_fun_timeold.QuadPart = ul_fun_time.QuadPart;
6013 ul_fun_timeold.QuadPart = ul_fun_time.QuadPart;
6021 idle_ratio /= (
Float_t)sysInfo.dwNumberOfProcessors;
6022 user_ratio /= (
Float_t)sysInfo.dwNumberOfProcessors;
6023 kernel_ratio /= (
Float_t)sysInfo.dwNumberOfProcessors;
6024 total_ratio = 100.0 - idle_ratio;
6029 cpuinfo->
fUser = user_ratio;
6030 cpuinfo->
fSys = kernel_ratio;
6031 cpuinfo->
fTotal = total_ratio;
6032 cpuinfo->
fIdle = idle_ratio;
6041 MEMORYSTATUSEX statex;
6042 statex.dwLength =
sizeof(statex);
6043 if (!GlobalMemoryStatusEx(&statex)) {
6044 ::Error(
"GetWinNTMemInfo",
"Error on GlobalMemoryStatusEx()");
6047 used = (
Long64_t)(statex.ullTotalPhys - statex.ullAvailPhys);
6055 swap_total = (
Long64_t)(statex.ullTotalPageFile - statex.ullTotalPhys);
6056 swap_avail = (
Long64_t)(statex.ullAvailPageFile - statex.ullAvailPhys);
6057 swap_used = swap_total - swap_avail;
6070 FILETIME starttime, exittime, kerneltime, usertime;
6071 timeval ru_stime, ru_utime;
6074 typedef BOOL (__stdcall *GetProcessMemoryInfoProc)( HANDLE Process,
6076 static GetProcessMemoryInfoProc pGetProcessMemoryInfo = 0;
6078 HMODULE hModImagehlp = LoadLibrary(
"Psapi.dll" );
6079 if (!hModImagehlp) {
6080 ::Error(
"GetWinNTProcInfo",
"Error on LoadLibrary(Psapi.dll)");
6084 pGetProcessMemoryInfo = (GetProcessMemoryInfoProc) GetProcAddress(
6085 hModImagehlp,
"GetProcessMemoryInfo" );
6086 if (!pGetProcessMemoryInfo) {
6088 "Error on GetProcAddress(GetProcessMemoryInfo)");
6092 if ( pGetProcessMemoryInfo( GetCurrentProcess(), &pmc,
sizeof(pmc)) ) {
6096 if ( GetProcessTimes(GetCurrentProcess(), &starttime, &exittime,
6097 &kerneltime, &usertime)) {
6100 memcpy(&li, &kerneltime,
sizeof(FILETIME));
6102 ru_stime.tv_sec = li.QuadPart / 1000000L;
6103 ru_stime.tv_usec = li.QuadPart % 1000000L;
6105 memcpy(&li, &usertime,
sizeof(FILETIME));
6107 ru_utime.tv_sec = li.QuadPart / 1000000L;
6108 ru_utime.tv_usec = li.QuadPart % 1000000L;
6111 ((
Float_t)(ru_utime.tv_usec) / 1000000.);
6113 ((
Float_t)(ru_stime.tv_usec) / 1000000.);
6124 if (!info)
return -1;
6136 if (!info)
return -1;
6147 if (!info)
return -1;
6158 if (!info)
return -1;
The file contains utilities which are foundational and could be used across the core component of ROO...
R__EXTERN TApplication * gApplication
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void SysError(const char *location, const char *msgfmt,...)
Use this function in case a system (OS or GUI) related error occurred.
void Break(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Int_t gErrorIgnoreLevel
Error handling routines.
R__EXTERN TExceptionHandler * gExceptionHandler
R__EXTERN void Throw(int code)
If an exception context has been set (using the TRY and RETRY macros) jump back to where it was set.
static unsigned int total
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
#define INVALID_HANDLE_VALUE
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
char * StrDup(const char *str)
Duplicate the string str.
@ kSigSegmentationViolation
R__EXTERN const char * gProgName
R__EXTERN const char * gRootDir
R__EXTERN TSystem * gSystem
R__EXTERN TFileHandler * gXDisplay
R__EXTERN const char * gProgPath
static void sighandler(int sig)
Call the signal handler associated with the signal.
static const char * DynamicPath(const char *newpath=nullptr, Bool_t reset=kFALSE)
Get shared library search path. Static utility function.
static void SigHandler(ESignals sig)
Unix signal handler.
const char * kProtocolName
void(* SigHandler_t)(ESignals)
R__EXTERN TWin32SplashThread * gSplash
static void __cpuid(int *cpuid_data, int)
static const char * shellMeta
BOOL PathIsRoot(LPCTSTR pPath)
check if a path is a root
static void GetWinNTProcInfo(ProcInfo_t *procinfo)
Get process info for this process on Windows NT.
static int GetL2CacheSize()
Use assembly to retrieve the L2 cache information ...
struct _PROCESS_MEMORY_COUNTERS * PPROCESS_MEMORY_COUNTERS
static void GetWinNTCpuInfo(CpuInfo_t *cpuinfo, Int_t sampleTime)
Get CPU stat for Window.
void Gl_setwidth(int width)
void(WINAPI * PGNSI)(LPSYSTEM_INFO)
#define SystemPerformanceInformation
ULongptr_t gConsoleWindow
BOOL PathIsUNC(LPCTSTR pszPath)
Returns TRUE if the given string is a UNC path.
static const char shellEscape
const TCHAR c_szColonSlash[]
static void GetWinNTMemInfo(MemInfo_t *meminfo)
Get VM stat for Windows NT.
static DWORD GetCPUSpeed()
Calculate the CPU clock speed using the 'rdtsc' instruction.
struct _PROCESS_MEMORY_COUNTERS PROCESS_MEMORY_COUNTERS
#define isin(address, start, length)
static const char * shellStuff
__inline BOOL DBL_BSLASH(LPCTSTR psz)
Inline function to check for a double-backslash at the beginning of a string.
static void GetWinNTSysInfo(SysInfo_t *sysinfo)
Get system info for Windows NT.
static const char * GetWindowsVersion()
void * _ReturnAddress(void)
LONG(WINAPI * PROCNTQSI)(UINT, PVOID, ULONG, PULONG)
virtual Bool_t HandleTermInput()
Using a TBrowser one can browse all ROOT objects.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
virtual void HandleException(int sig)=0
ULong_t fds_bits[(((kFDSETSIZE)+((kNFDBITS) -1))/(kNFDBITS))]
TFdSet & operator=(const TFdSet &fd)
void Copy(TFdSet &fd) const
virtual Bool_t WriteNotify()
Notify when something can be written to the descriptor associated with this handler.
virtual Bool_t ReadNotify()
Notify when something can be read from the descriptor associated with this handler.
Bool_t Notify() override
Notify when event occurred on descriptor associated with this handler.
This class represents an Internet Protocol (IP) address.
UInt_t GetAddress() const
TObject * Next() override
Return next object in the list. Returns 0 when no more objects in list.
void Add(TObject *obj) override
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Iterator of ordered collection.
TObject * Next() override
Return next object in collection.
static const TString & GetBinDir()
Get the binary directory in the installation. Static utility function.
static void ShutDown()
Shut down ROOT.
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
static const TString & GetLibDir()
Get the library directory in the installation. Static utility function.
Regular expression class.
Bool_t Notify() override
Notify when signal occurs.
ESignals GetSignal() const
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Ssiz_t First(char c) const
Find first occurrence of a character c.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TString & Prepend(const char *cs)
TString & Swap(TString &other)
TString & Remove(Ssiz_t pos)
TString & Append(const char *cs)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Abstract base class defining a generic interface to the underlying Operating System.
TSeqCollection * fFileHandler
virtual void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
TString & GetLastErrorString()
Return the thread local storage for the custom last error message.
void Beep(Int_t freq=-1, Int_t duration=-1, Bool_t setDefault=kFALSE)
Beep for duration milliseconds with a tone of frequency freq.
static void ResetErrno()
Static function resetting system error number.
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
static Int_t GetErrno()
Static function returning system error number.
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
virtual Long_t NextTimeOut(Bool_t mode)
Time when next timer of mode (synchronous=kTRUE or asynchronous=kFALSE) will time-out (in ms).
virtual int SetSockOpt(int sock, int kind, int val)
Set socket option.
virtual const char * Getenv(const char *env)
Get environment variable.
TFdSet * fWritemask
Files that should be checked for read events.
TFdSet * fSignals
Files with writes waiting.
virtual Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in 'path' points to the local file system.
virtual const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists)
Find location of file in a search path.
virtual int MakeDirectory(const char *name)
Make a directory.
virtual const char * ExpandFileName(const char *fname)
Expand a pathname getting rid of special shell characters like ~.
virtual TFileHandler * RemoveFileHandler(TFileHandler *fh)
Remove a file handler from the list of file handlers.
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
virtual void ExitLoop()
Exit from event loop.
virtual Bool_t Init()
Initialize the OS interface.
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
TFdSet * fWriteready
Files with reads waiting.
virtual void AddSignalHandler(TSignalHandler *sh)
Add a signal handler to list of system signal handlers.
TSeqCollection * fSignalHandler
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
TFdSet * fReadready
Files that should be checked for write events.
TSystem * FindHelper(const char *path, void *dirptr=nullptr)
Create helper TSystem to handle file and directory operations that might be special for remote file a...
Int_t fNfd
Signals that were trapped.
std::atomic< Bool_t > fInsideNotify
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
virtual const char * GetLibraries(const char *regexp="", const char *option="", Bool_t isRegexp=kTRUE)
Return a space separated list of loaded shared libraries.
virtual TSignalHandler * RemoveSignalHandler(TSignalHandler *sh)
Remove a signal handler from list of signal handlers.
static const char * StripOffProto(const char *path, const char *proto)
Strip off protocol string from specified path.
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
virtual TTimer * RemoveTimer(TTimer *t)
Remove timer from list of system timers.
virtual int Unlink(const char *name)
Unlink, i.e.
virtual void StackTrace()
Print a stack trace.
char * DynamicPathName(const char *lib, Bool_t quiet=kFALSE)
Find a dynamic library called lib using the system search paths.
Basic time type with millisecond precision.
Handles synchronous and a-synchronous timer events.
Bool_t CheckTimer(const TTime &now)
Check if timer timed out.
This class represents a WWW compatible URL.
const char * GetProtocol() const
void CloseConnection(int sock, Bool_t force=kFALSE) override
Close socket.
TList * GetVolumes(Option_t *opt="") const override
Get list of volumes (drives) mounted on the system.
FILE * OpenPipe(const char *shellcmd, const char *mode) override
Open a pipe.
void IgnoreSignal(ESignals sig, Bool_t ignore=kTRUE) override
If ignore is true ignore the specified signal, else restore previous behaviour.
Bool_t HandleConsoleEvent()
int Utime(const char *file, Long_t modtime, Long_t actime) override
Set a files modification and access times.
void Sleep(UInt_t milliSec) override
Sleep milliSec milli seconds.
TTime Now() override
Get current time in milliseconds since 0:00 Jan 1 1995.
const char * HostName() override
Return the system's host name.
virtual ~TWinNTSystem()
dtor
FILE * TempFileName(TString &base, const char *dir=nullptr, const char *suffix=nullptr) override
Create a secure temporary file by appending a unique 6 letter string to base.
void ExitLoop() override
Exit from event loop.
int SetNonBlock(int fd)
Make descriptor fd non-blocking.
int AnnounceUnixService(int port, int backlog) override
Announce unix domain service.
const char * GetLinkedLibraries() override
Get list of shared libraries loaded at the start of the executable.
void AddSignalHandler(TSignalHandler *sh) override
Add a signal handler to list of system signal handlers.
const char * PrependPathName(const char *dir, TString &name) override
Concatenate a directory and a file name.
void SetGUIThreadMsgHandler(ThreadMsgFunc_t func)
Set the (static part of) the event handler func for GUI messages.
Bool_t ProcessEvents() override
process pending events, i.e. DispatchOneEvent(kTRUE)
const char DriveName(const char *pathname="/")
Return the drive letter in pathname.
int SetSockOpt(int sock, int opt, int val) override
Set socket option.
struct passwd * fPasswords
Int_t GetCpuInfo(CpuInfo_t *info, Int_t sampleTime=1000) const override
Returns cpu load average and load info into the CpuInfo_t structure.
Int_t SetFPEMask(Int_t mask=kDefaultMask) override
Set which conditions trigger a floating point exception.
int GetPathInfo(const char *path, FileStat_t &buf) override
Get info about a file.
static void ThreadStub(void *Parameter)
void FreeDirectory(void *dirp) override
Close a WinNT file system directory.
static int WinNTUdpConnect(const char *hostname, int port)
Creates a UDP socket connection Is called via the TSocket constructor.
Int_t GetSysInfo(SysInfo_t *info) const override
Returns static system info, like OS type, CPU type, number of CPUs RAM size, etc into the SysInfo_t s...
void * OpenDirectory(const char *name) override
Open a directory. Returns 0 if directory does not exist.
int AnnounceTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize=-1) override
Announce TCP/IP service.
const char * Getenv(const char *name) override
Get environment variable.
UserGroup_t * GetGroupInfo(Int_t gid) override
Returns all group info in the UserGroup_t structure.
void AddTimer(TTimer *ti) override
Add timer to list of system timers.
int RecvBuf(int sock, void *buffer, int length) override
Receive a buffer headed by a length indicator.
void DoBeep(Int_t freq=-1, Int_t duration=-1) const override
Beep.
void TimerThread()
Special Thread to check asynchronous timers.
const char * GetDynamicPath() override
Return the dynamic path (used to find shared libraries).
Bool_t ExpandPathName(TString &patbuf) override
Expand a pathname getting rid of special shell characaters like ~.$, etc.
int GetServiceByName(const char *service) override
Get port # of internet service.
int OpenConnection(const char *server, int port, int tcpwindowsize=-1, const char *protocol="tcp") override
Open a connection to a service on a server.
int ConnectService(const char *servername, int port, int tcpwindowsize, const char *protocol="tcp")
Connect to service servicename on server servername.
TString GetDirName(const char *pathname) override
Return the directory name in pathname.
int SendRaw(int sock, const void *buffer, int length, int flag) override
Send exactly length bytes from buffer.
const char * TempDirectory() const override
Return a user configured or systemwide directory to create temporary files in.
void DispatchSignals(ESignals sig)
Handle and dispatch signals.
int AnnounceUdpService(int port, int backlog) override
Announce UDP service.
int Exec(const char *shellcmd) override
Execute a command.
Long_t LookupSID(const char *lpszAccountName, int what, int &groupIdx, int &memberIdx)
Take the name and look up a SID so that we can get full domain/user information.
Int_t GetEffectiveUid() override
Returns the effective user id.
void NotifyApplicationCreated() override
Hook to tell TSystem that the TApplication object has been created.
void Abort(int code=0) override
Abort the application.
Int_t Select(TList *active, Long_t timeout) override
Select on file descriptors. The timeout to is in millisec.
Int_t GetMemInfo(MemInfo_t *info) const override
Returns ram and swap memory usage info into the MemInfo_t structure.
Int_t GetProcInfo(ProcInfo_t *info) const override
Returns cpu and memory used by this process into the ProcInfo_t structure.
TFileHandler * RemoveFileHandler(TFileHandler *fh) override
Remove a file handler from the list of file handlers.
Bool_t DispatchTimers(Bool_t mode)
Handle and dispatch timers.
const char * DirName(const char *pathname) override
Return the directory name in pathname.
Bool_t IsPathLocal(const char *path) override
Returns TRUE if the url in 'path' points to the local file system.
int SendBuf(int sock, const void *buffer, int length) override
Send a buffer headed by a length indicator.
TInetAddress GetHostByName(const char *server) override
Get Internet Protocol (IP) address of host.
Bool_t ChangeDirectory(const char *path) override
Change directory.
int AcceptConnection(int sock) override
Accept a connection.
int GetPid() override
Get process id.
const char * WorkingDirectory() override
Return the working directory for the default drive.
void SetProgname(const char *name) override
Set the application name (from command line, argv[0]) and copy it in gProgName.
int GetSockOpt(int sock, int opt, int *val) override
Get socket option.
int GetFsInfo(const char *path, Long_t *id, Long_t *bsize, Long_t *blocks, Long_t *bfree) override
Get info about a file system: id, bsize, bfree, blocks.
int CopyFile(const char *from, const char *to, Bool_t overwrite=kFALSE) override
Copy a file.
Int_t RedirectOutput(const char *name, const char *mode="a", RedirectHandle_t *h=nullptr) override
Redirect standard output (stdout, stderr) to the specified file.
Bool_t IsAbsoluteFileName(const char *dir) override
Return true if dir is an absolute pathname.
int mkdir(const char *name, Bool_t recursive=kFALSE) override
Make a file system directory.
const char * UnixPathName(const char *unixpathname) override
Convert a pathname to a unix pathname.
Bool_t CheckSignals(Bool_t sync)
Check if some signals were raised and call their Notify() member.
int Symlink(const char *from, const char *to) override
Create a symlink from file1 to file2.
void DispatchOneEvent(Bool_t pendingOnly=kFALSE) override
Dispatch a single event in TApplication::Run() loop.
int Load(const char *module, const char *entry="", Bool_t system=kFALSE) override
Load a shared library.
TSignalHandler * RemoveSignalHandler(TSignalHandler *sh) override
Remove a signal handler from list of signal handlers.
const char * GetError() override
Return system error string.
void StackTrace() override
Print a stack trace, if gEnv entry "Root.Stacktrace" is unset or 1, and if the image helper functions...
int Unlink(const char *name) override
Unlink, i.e.
void ResetSignals() override
Reset signals handlers to previous behaviour.
int RecvRaw(int sock, void *buffer, int length, int flag) override
Receive exactly length bytes into buffer.
const char * BaseName(const char *name) override
Base name of a file name.
TTimer * RemoveTimer(TTimer *ti) override
Remove timer from list of system timers.
void Exit(int code, Bool_t mode=kTRUE) override
Exit the application.
void AddDynamicPath(const char *dir) override
Add a new directory to the dynamic path.
int Umask(Int_t mask) override
Set the process file creation mode mask.
void AddFileHandler(TFileHandler *fh) override
Add a file handler to the list of system file handlers.
std::string fDirNameBuffer
Bool_t CheckDescriptors()
Check if there is activity on some file descriptors and call their Notify() member.
static int WinNTUnixConnect(int port)
Connect to a Unix domain socket.
int Chmod(const char *file, UInt_t mode) override
Set the file permission bits.
Bool_t Init() override
Initialize WinNT system interface.
const char * GetDirEntry(void *dirp) override
Returns the next directory entry.
TInetAddress GetSockName(int sock) override
Get Internet Protocol (IP) address of host and port #.
Bool_t(* ThreadMsgFunc_t)(MSG *)
TInetAddress GetPeerName(int sock) override
Get Internet Protocol (IP) address of remote host and port #.
Int_t GetUid(const char *user=nullptr) override
Returns the user's id. If user = 0, returns current user's id.
const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists) override
Find location of file in a search path.
const char * FindDynamicLibrary(TString &lib, Bool_t quiet=kFALSE) override
Returns and updates sLib to the path of a dynamic library (searches for library in the dynamic librar...
void ResetSignal(ESignals sig, Bool_t reset=kTRUE) override
If reset is true reset the signal handler for the specified signal to the default handler,...
Bool_t CollectMembers(const char *lpszGroupName, int &groupIdx, int &memberIdx)
Bool_t CountMembers(const char *lpszGroupName)
std::string GetHomeDirectory(const char *userName=nullptr) const override
Return the user's home directory.
Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists) override
Returns FALSE if one can access a file using the specified access mode.
void FillWithHomeDirectory(const char *userName, char *mydir) const
Fill buffer with user's home directory.
char * GetServiceByPort(int port) override
Get name of internet service.
Bool_t InitUsersGroups()
Collect local users and groups accounts information.
Int_t GetGid(const char *group=nullptr) override
Returns the group's id. If group = 0, returns current user's group.
const char * HomeDirectory(const char *userName=0) override
Return the user's home directory.
Int_t GetEffectiveGid() override
Returns the effective group id.
void Setenv(const char *name, const char *value) override
Set environment variable.
void SetDynamicPath(const char *path) override
Set the dynamic path to a new value.
std::string GetWorkingDirectory() const override
Return the working directory for the default drive.
HANDLE GetProcess()
Get current process handle.
UserGroup_t * GetUserInfo(Int_t uid) override
Returns all user info in the UserGroup_t structure.
int Rename(const char *from, const char *to) override
Rename a file. Returns 0 when successful, -1 in case of failure.
int MakeDirectory(const char *name) override
Make a WinNT file system directory.
int Link(const char *from, const char *to) override
Create a link from file1 to file2.
const char * GetLibraries(const char *regexp="", const char *option="", Bool_t isRegexp=kTRUE) override
Return a space separated list of loaded shared libraries.
int ClosePipe(FILE *pipe) override
Close the pipe.
Int_t GetFPEMask() override
Return the bitmap of conditions that trigger a floating point exception.
Int_t GetCryptoRandom(void *buf, Int_t len) override
Return cryptographic random number Fill provided buffer with random values Returns number of bytes wr...
const std::string & GetFallbackRootSys()
void(off) SmallVectorTemplateBase< T
Struct used to pass information between OpenDirectory and GetDirEntry in a thread safe way (each thre...
WIN32_FIND_DATA fFindFileData
SIZE_T QuotaNonPagedPoolUsage
SIZE_T PeakWorkingSetSize
SIZE_T QuotaPeakNonPagedPoolUsage
SIZE_T QuotaPeakPagedPoolUsage
SIZE_T QuotaPagedPoolUsage