42 #include <sys/utime.h> 43 #include <sys/timeb.h> 62 #if defined (_MSC_VER) && (_MSC_VER >= 1400) 64 #elif defined (_M_IX86) 65 static void __cpuid(
int* cpuid_data,
int info_type)
92 static void __cpuid(
int* cpuid_data,
int) {
93 cpuid_data[0] = 0x00000000;
94 cpuid_data[1] = 0x00000000;
95 cpuid_data[2] = 0x00000000;
96 cpuid_data[3] = 0x00000000;
111 TFdSet() { fds_bits =
new fd_set; fds_bits->fd_count = 0; }
112 virtual ~TFdSet() {
delete fds_bits; }
113 void Copy(TFdSet &fd)
const { memcpy((
void*)fd.fds_bits, fds_bits,
sizeof(fd_set)); }
114 TFdSet(
const TFdSet& fd) { fd.Copy(*
this); }
115 TFdSet&
operator=(
const TFdSet& fd) { fd.Copy(*
this);
return *
this; }
116 void Zero() { fds_bits->fd_count = 0; }
119 if (fds_bits->fd_count < FD_SETSIZE-1)
120 fds_bits->fd_array[fds_bits->fd_count++] = (
SOCKET)fd;
122 ::SysError(
"TFdSet::Set",
"fd_count will exeed FD_SETSIZE");
127 for (i=0; i<fds_bits->fd_count; i++) {
128 if (fds_bits->fd_array[i]==(
SOCKET)fd) {
129 while (i<fds_bits->fd_count-1) {
130 fds_bits->fd_array[i] = fds_bits->fd_array[i+1];
133 fds_bits->fd_count--;
139 Int_t *GetBits() {
return fds_bits && fds_bits->fd_count ? (
Int_t*)fds_bits : 0; }
140 UInt_t GetCount() {
return (
UInt_t)fds_bits->fd_count; }
141 Int_t GetFd(
Int_t i) {
return i<fds_bits->fd_count ? fds_bits->fd_array[i] : 0; }
149 static HANDLE gGlobalEvent;
150 static HANDLE gTimerThreadHandle;
151 typedef NET_API_STATUS (WINAPI *pfn1)(LPVOID);
152 typedef NET_API_STATUS (WINAPI *pfn2)(LPCWSTR, LPCWSTR, DWORD, LPBYTE*);
153 typedef NET_API_STATUS (WINAPI *pfn3)(LPCWSTR, LPCWSTR, DWORD, LPBYTE*,
154 DWORD, LPDWORD, LPDWORD, PDWORD);
155 typedef NET_API_STATUS (WINAPI *pfn4)(LPCWSTR, DWORD, LPBYTE*, DWORD, LPDWORD,
157 static pfn1 p2NetApiBufferFree;
158 static pfn2 p2NetUserGetInfo;
159 static pfn3 p2NetLocalGroupGetMembers;
160 static pfn4 p2NetLocalGroupEnum;
162 static struct signal_map {
168 SIGSEGV, 0,
"segmentation violation",
169 -1 , 0,
"bad argument to system call",
170 -1 , 0,
"write on a pipe with no one to read it",
171 SIGILL, 0,
"illegal instruction",
173 SIGINT, 0,
"interrupt",
174 -1 , 0,
"window size change",
175 -1 , 0,
"alarm clock",
176 -1 , 0,
"death of a child",
177 -1 , 0,
"urgent data arrived on an I/O channel",
178 SIGFPE, 0,
"floating point exception",
179 SIGTERM, 0,
"termination signal",
180 -1 , 0,
"user-defined signal 1",
181 -1 , 0,
"user-defined signal 2" 202 static int WinNTRecv(
int socket,
void *buffer,
int length,
int flag)
204 if (socket == -1)
return -1;
212 if (flag == MSG_PEEK) {
217 char *buf = (
char *)buffer;
219 for (n = 0; n < length; n += nrecv) {
220 if ((nrecv = ::recv(sock, buf+n, length-n, flag)) <= 0) {
224 if (flag == MSG_OOB) {
225 if (::WSAGetLastError() == WSAEWOULDBLOCK) {
227 }
else if (::WSAGetLastError() == WSAEINVAL) {
231 if (::WSAGetLastError() == WSAEWOULDBLOCK) {
234 if (::WSAGetLastError() != WSAEINTR)
235 ::
SysError(
"TWinNTSystem::WinNTRecv",
"recv");
236 if (::WSAGetLastError() == EPIPE ||
237 ::WSAGetLastError() == WSAECONNRESET)
256 static int WinNTSend(
int socket,
const void *buffer,
int length,
int flag)
258 if (socket < 0)
return -1;
268 const char *buf = (
const char *)buffer;
270 for (n = 0; n < length; n += nsent) {
271 if ((nsent = ::send(sock, buf+n, length-n, flag)) <= 0) {
275 if (::WSAGetLastError() == WSAEWOULDBLOCK) {
278 if (::WSAGetLastError() != WSAEINTR)
279 ::
SysError(
"TWinNTSystem::WinNTSend",
"send");
280 if (::WSAGetLastError() == EPIPE ||
281 ::WSAGetLastError() == WSAECONNRESET)
298 static int WinNTSelect(TFdSet *readready, TFdSet *writeready,
Long_t timeout)
301 fd_set* rbits = readready ? (fd_set*)readready->GetBits() : 0;
302 fd_set* wbits = writeready ? (fd_set*)writeready->GetBits() : 0;
306 tv.tv_sec = timeout / 1000;
307 tv.tv_usec = (timeout % 1000) * 1000;
309 retcode = ::select(0, rbits, wbits, 0, &tv);
311 retcode = ::select(0, rbits, wbits, 0, 0);
314 if (retcode == SOCKET_ERROR) {
315 int errcode = ::WSAGetLastError();
319 if (errcode == WSAENOTSOCK) {
321 int result = _fstat64( readready->GetFd(0), &buf );
329 ::WaitForSingleObject(gGlobalEvent, 1);
330 ::ResetEvent(gGlobalEvent);
335 if ( errcode == WSAEINTR) {
339 if (errcode == EBADF) {
354 if (reset || newpath) {
361 }
else if (dynpath ==
"") {
364 if (rdynpath ==
"") {
371 dynpath = path; dynpath +=
";"; dynpath += rdynpath;
389 if (signal_map[i].code == sig) {
390 (*signal_map[i].handler)((
ESignals)i);
401 signal_map[sig].handler = handler;
402 if (signal_map[sig].code != -1)
409 static char *WinNTSigname(
ESignals sig)
411 return signal_map[sig].signame;
417 static BOOL ConsoleSigHandler(DWORD sig)
425 Break(
"TInterruptHandler::Notify",
"keyboard interrupt");
431 case CTRL_BREAK_EVENT:
432 case CTRL_LOGOFF_EVENT:
433 case CTRL_SHUTDOWN_EVENT:
434 case CTRL_CLOSE_EVENT:
436 printf(
"\n *** Break *** keyboard interrupt - ROOT is terminated\n");
442 static CONTEXT *fgXcptContext = 0;
456 LONG WINAPI ExceptionFilter(LPEXCEPTION_POINTERS pXcp)
458 fgXcptContext = pXcp->ContextRecord;
460 return EXCEPTION_CONTINUE_SEARCH;
464 #pragma intrinsic(_ReturnAddress) 465 #pragma auto_inline(off) 466 DWORD_PTR GetProgramCounter()
471 #pragma auto_inline(on) 482 static DWORD WINAPI GUIThreadMessageProcessingLoop(
void *p)
487 ::PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
492 if (gGlobalEvent) ::SetEvent(gGlobalEvent);
493 erret = ::GetMessage(&msg, NULL, NULL, NULL);
494 if (erret <= 0) endLoop =
kTRUE;
495 if (gGUIThreadMsgFunc)
496 endLoop = (*gGUIThreadMsgFunc)(&msg);
503 erret = ::GetLastError();
504 Error(
"MsgLoop",
"Error in GetMessage");
518 typedef BOOL (__stdcall *SYMINITIALIZEPROC)( HANDLE, LPSTR, BOOL );
519 typedef BOOL (__stdcall *SYMCLEANUPPROC)( HANDLE );
520 typedef BOOL (__stdcall *STACKWALK64PROC)
521 ( DWORD, HANDLE, HANDLE, LPSTACKFRAME64, LPVOID,
522 PREAD_PROCESS_MEMORY_ROUTINE,PFUNCTION_TABLE_ACCESS_ROUTINE,
523 PGET_MODULE_BASE_ROUTINE, PTRANSLATE_ADDRESS_ROUTINE );
524 typedef LPVOID (__stdcall *SYMFUNCTIONTABLEACCESS64PROC)( HANDLE, DWORD64 );
525 typedef DWORD (__stdcall *SYMGETMODULEBASE64PROC)( HANDLE, DWORD64 );
526 typedef BOOL (__stdcall *SYMGETMODULEINFO64PROC)(HANDLE, DWORD64, PIMAGEHLP_MODULE64);
527 typedef BOOL (__stdcall *SYMGETSYMFROMADDR64PROC)( HANDLE, DWORD64, PDWORD64, PIMAGEHLP_SYMBOL64);
528 typedef BOOL (__stdcall *SYMGETLINEFROMADDR64PROC)(HANDLE, DWORD64, PDWORD, PIMAGEHLP_LINE64);
529 typedef DWORD (__stdcall *UNDECORATESYMBOLNAMEPROC)(PCSTR, PSTR, DWORD, DWORD);
532 static SYMINITIALIZEPROC _SymInitialize = 0;
533 static SYMCLEANUPPROC _SymCleanup = 0;
534 static STACKWALK64PROC _StackWalk64 = 0;
535 static SYMFUNCTIONTABLEACCESS64PROC _SymFunctionTableAccess64 = 0;
536 static SYMGETMODULEBASE64PROC _SymGetModuleBase64 = 0;
537 static SYMGETMODULEINFO64PROC _SymGetModuleInfo64 = 0;
538 static SYMGETSYMFROMADDR64PROC _SymGetSymFromAddr64 = 0;
539 static SYMGETLINEFROMADDR64PROC _SymGetLineFromAddr64 = 0;
540 static UNDECORATESYMBOLNAMEPROC _UnDecorateSymbolName = 0;
542 BOOL InitImagehlpFunctions()
550 HMODULE hModImagehlp = LoadLibrary(
"IMAGEHLP.DLL" );
554 _SymInitialize = (SYMINITIALIZEPROC) GetProcAddress( hModImagehlp,
"SymInitialize" );
558 _SymCleanup = (SYMCLEANUPPROC) GetProcAddress( hModImagehlp,
"SymCleanup" );
562 _StackWalk64 = (STACKWALK64PROC) GetProcAddress( hModImagehlp,
"StackWalk64" );
566 _SymFunctionTableAccess64 = (SYMFUNCTIONTABLEACCESS64PROC) GetProcAddress(hModImagehlp,
"SymFunctionTableAccess64" );
567 if (!_SymFunctionTableAccess64)
570 _SymGetModuleBase64=(SYMGETMODULEBASE64PROC)GetProcAddress(hModImagehlp,
"SymGetModuleBase64");
571 if (!_SymGetModuleBase64)
574 _SymGetModuleInfo64=(SYMGETMODULEINFO64PROC)GetProcAddress(hModImagehlp,
"SymGetModuleInfo64");
575 if (!_SymGetModuleInfo64)
578 _SymGetSymFromAddr64=(SYMGETSYMFROMADDR64PROC)GetProcAddress(hModImagehlp,
"SymGetSymFromAddr64");
579 if (!_SymGetSymFromAddr64)
582 _SymGetLineFromAddr64=(SYMGETLINEFROMADDR64PROC)GetProcAddress(hModImagehlp,
"SymGetLineFromAddr64");
583 if (!_SymGetLineFromAddr64)
586 _UnDecorateSymbolName=(UNDECORATESYMBOLNAMEPROC)GetProcAddress(hModImagehlp,
"UnDecorateSymbolName");
587 if (!_UnDecorateSymbolName)
590 if (!_SymInitialize(GetCurrentProcess(), 0,
TRUE ))
606 std::string GetModuleName(DWORD64 address)
610 std::ostringstream out;
611 HANDLE process = ::GetCurrentProcess();
613 DWORD lineDisplacement = 0;
614 IMAGEHLP_LINE64
line;
615 ::ZeroMemory(&line,
sizeof(line));
616 line.SizeOfStruct =
sizeof(
line);
617 if(_SymGetLineFromAddr64(process, address, &lineDisplacement, &line)) {
618 out << line.FileName <<
"(" << line.LineNumber <<
"): ";
620 IMAGEHLP_MODULE64 module;
621 ::ZeroMemory(&module,
sizeof(module));
622 module.SizeOfStruct =
sizeof(module);
623 if(_SymGetModuleInfo64(process, address, &module)) {
624 out << module.ModuleName <<
"!";
626 out <<
"0x" << std::hex << address << std::dec <<
" ";
633 std::string GetFunctionName(DWORD64 address)
637 DWORD64 symbolDisplacement = 0;
638 HANDLE process = ::GetCurrentProcess();
640 const unsigned int SYMBOL_BUFFER_SIZE = 8192;
641 char symbolBuffer[SYMBOL_BUFFER_SIZE];
642 PIMAGEHLP_SYMBOL64 symbol =
reinterpret_cast<PIMAGEHLP_SYMBOL64
>(symbolBuffer);
643 ::ZeroMemory(symbol, SYMBOL_BUFFER_SIZE);
644 symbol->SizeOfStruct = SYMBOL_BUFFER_SIZE;
645 symbol->MaxNameLength = SYMBOL_BUFFER_SIZE -
sizeof(IMAGEHLP_SYMBOL64);
647 if(_SymGetSymFromAddr64(process, address, &symbolDisplacement, symbol)) {
649 const unsigned int NAME_SIZE = 8192;
650 char name[NAME_SIZE];
651 _UnDecorateSymbolName(
656 UNDNAME_NO_THISTYPE |
657 UNDNAME_NO_SPECIAL_SYMS |
658 UNDNAME_NO_MEMBER_TYPE |
659 UNDNAME_NO_MS_KEYWORDS |
660 UNDNAME_NO_ACCESS_SPECIFIERS
678 static BOOL IsShortcut(
const char *filename)
681 const char *extLnk =
".lnk";
682 if (filename != NULL) {
694 static BOOL ResolveShortCut(LPCSTR pszShortcutFile,
char *pszPath,
int maxbuf)
698 char szGotPath[MAX_PATH];
705 typedef HRESULT (__stdcall *COINITIALIZEPROC)( LPVOID );
706 static COINITIALIZEPROC _CoInitialize = 0;
707 typedef void (__stdcall *COUNINITIALIZEPROC)(
void );
708 static COUNINITIALIZEPROC _CoUninitialize = 0;
709 typedef HRESULT (__stdcall *COCREATEINSTANCEPROC)( REFCLSID, LPUNKNOWN,
710 DWORD, REFIID, LPVOID );
711 static COCREATEINSTANCEPROC _CoCreateInstance = 0;
713 HMODULE hModImagehlp = LoadLibrary(
"ole32.dll" );
717 _CoInitialize = (COINITIALIZEPROC) GetProcAddress( hModImagehlp,
"CoInitialize" );
720 _CoUninitialize = (COUNINITIALIZEPROC) GetProcAddress( hModImagehlp,
"CoUninitialize");
721 if (!_CoUninitialize)
723 _CoCreateInstance = (COCREATEINSTANCEPROC) GetProcAddress( hModImagehlp,
"CoCreateInstance" );
724 if (!_CoCreateInstance)
729 hres = _CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
730 IID_IShellLink, (
void **) &psl);
731 if (SUCCEEDED(hres)) {
734 hres = psl->QueryInterface(IID_IPersistFile, (
void **) &ppf);
735 if (SUCCEEDED(hres)) {
737 MultiByteToWideChar(CP_ACP, 0, pszShortcutFile, -1, wsz, MAX_PATH);
739 hres = ppf->Load(wsz, STGM_READ);
740 if (SUCCEEDED(hres)) {
741 hres = psl->Resolve(HWND_DESKTOP, SLR_ANY_MATCH | SLR_NO_UI | SLR_UPDATE);
742 if (SUCCEEDED(hres)) {
743 strlcpy(szGotPath, pszShortcutFile,MAX_PATH);
744 hres = psl->GetPath(szGotPath, MAX_PATH, (WIN32_FIND_DATA *)&wfd,
745 SLGP_UNCPRIORITY | SLGP_RAWPATH);
746 strlcpy(pszPath,szGotPath, maxbuf);
747 if (maxbuf) pszPath[maxbuf-1] = 0;
756 return SUCCEEDED(hres);
761 GetModuleFileName(0, buf, MAX_MODULE_NAME32 + 1);
762 if (strcmp(sys->TWinNTSystem::BaseName(buf),
"root.exe"))
765 if (!::RegOpenKeyEx(HKEY_CURRENT_USER,
"Software", 0, KEY_READ, ®CUS) == ERROR_SUCCESS)
768 if (!::RegOpenKeyEx(regCUS,
"Classes", 0, KEY_READ, ®CUSC) == ERROR_SUCCESS) {
769 ::RegCloseKey(regCUS);
774 bool regROOTwrite =
false;
778 if (::RegOpenKeyEx(regCUSC,
"ROOTDEV.ROOT", 0, KEY_READ, ®ROOT) != ERROR_SUCCESS) {
779 ::RegCloseKey(regCUSC);
780 if (::RegOpenKeyEx(regCUS,
"Classes", 0, KEY_READ | KEY_WRITE, ®CUSC) == ERROR_SUCCESS &&
781 ::RegCreateKeyEx(regCUSC,
"ROOTDEV.ROOT", 0, NULL, 0, KEY_READ | KEY_WRITE,
782 NULL, ®ROOT, NULL) == ERROR_SUCCESS) {
787 if (::RegOpenKeyEx(regROOT,
"DefaultIcon", 0, KEY_READ, ®ROOTIcon) == ERROR_SUCCESS) {
788 char bufIconLoc[1024];
790 DWORD dwSize =
sizeof(bufIconLoc);
792 if (::RegQueryValueEx(regROOTIcon, NULL, NULL, &dwType, (BYTE*)bufIconLoc, &dwSize) == ERROR_SUCCESS)
793 regROOTwrite = (iconloc != bufIconLoc);
796 ::RegCloseKey(regROOTIcon);
801 ::RegCloseKey(regCUSC);
802 ::RegCloseKey(regROOT);
803 if (::RegOpenKeyEx(regCUS,
"Classes", 0, KEY_READ | KEY_WRITE, ®CUSC) != ERROR_SUCCESS) {
805 regROOTwrite =
false;
807 if (::RegOpenKeyEx(regCUSC,
"ROOTDEV.ROOT", 0, KEY_WRITE, ®ROOT) != ERROR_SUCCESS) {
809 regROOTwrite =
false;
810 ::RegCloseKey(regCUSC);
817 TString fileopen =
"fileopen.C";
818 TString rootmacrodir =
"macros";
828 ::RegCloseKey(regROOT);
829 ::RegCloseKey(regCUSC);
830 ::RegCloseKey(regCUS);
834 static const char apptitle[] =
"ROOT data file";
835 ::RegSetValueEx(regROOT, NULL, 0, REG_SZ, (BYTE*)apptitle,
sizeof(apptitle));
836 DWORD editflags = 0x00010000;
837 ::RegSetValueEx(regROOT,
"EditFlags", 0, REG_DWORD, (BYTE*)&editflags,
sizeof(editflags));
840 if (::RegCreateKeyEx(regROOT,
"DefaultIcon", 0, NULL, 0, KEY_READ | KEY_WRITE,
841 NULL, ®ROOTIcon, NULL) == ERROR_SUCCESS) {
844 ::RegSetValueEx(regROOTIcon, NULL, 0, REG_SZ, (BYTE*)iconloc.
Data(), iconloc.
Length() + 1);
845 ::RegCloseKey(regROOTIcon);
850 if (::RegCreateKeyEx(regROOT,
"shell", 0, NULL, 0, KEY_READ | KEY_WRITE,
851 NULL, ®ROOTshell, NULL) == ERROR_SUCCESS) {
853 if (::RegCreateKeyEx(regROOTshell,
"open", 0, NULL, 0, KEY_READ | KEY_WRITE,
854 NULL, ®ShellOpen, NULL) == ERROR_SUCCESS) {
855 HKEY regShellOpenCmd;
856 if (::RegCreateKeyEx(regShellOpen,
"command", 0, NULL, 0, KEY_READ | KEY_WRITE,
857 NULL, ®ShellOpenCmd, NULL) == ERROR_SUCCESS) {
859 cmd +=
" -l \"%1\" \"";
862 ::RegSetValueEx(regShellOpenCmd, NULL, 0, REG_SZ, (BYTE*)cmd.
Data(), cmd.
Length() + 1);
863 ::RegCloseKey(regShellOpenCmd);
865 ::RegCloseKey(regShellOpen);
867 ::RegCloseKey(regROOTshell);
869 ::RegCloseKey(regROOT);
871 if (::RegCreateKeyEx(regCUSC,
".root", 0, NULL, 0, KEY_READ | KEY_WRITE,
872 NULL, ®ROOT, NULL) == ERROR_SUCCESS) {
873 static const char appname[] =
"ROOTDEV.ROOT";
874 ::RegSetValueEx(regROOT, NULL, 0, REG_SZ, (BYTE*)appname,
sizeof(appname));
876 ::RegCloseKey(regCUSC);
877 ::RegCloseKey(regCUS);
880 ::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
888 static bool once =
true;
891 if (!once ||
gROOT->IsBatch())
return false;
892 TString cmdline(::GetCommandLine());
893 Int_t i = 0, from = 0;
894 while (cmdline.
Tokenize(arg, from,
" ")) {
896 if (i == 0 && ((arg !=
"root") && (arg !=
"rootn") &&
897 (arg !=
"root.exe") && (arg !=
"rootn.exe")))
return false;
898 else if ((arg ==
"-l") || (arg ==
"-b"))
return false;
910 static void SetConsoleWindowName()
912 char pszNewWindowTitle[1024];
913 char pszOldWindowTitle[1024];
915 CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
917 if (!::GetConsoleTitle(pszOldWindowTitle, 1024))
920 wsprintf(pszNewWindowTitle,
"%d/%d", ::GetTickCount(), ::GetCurrentProcessId());
922 if (!::SetConsoleTitle(pszNewWindowTitle))
932 ::SetConsoleTitle(
"ROOT session");
934 hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
935 ::SetConsoleMode(hStdout, ENABLE_PROCESSED_OUTPUT |
936 ENABLE_WRAP_AT_EOL_OUTPUT);
937 if (!::GetConsoleScreenBufferInfo(hStdout, &csbiInfo))
956 TIter next(fSignalHandler);
974 fGUIThreadHandle(0), fGUIThreadId(0)
982 if (initwinsock = ::WSAStartup(MAKEWORD(2, 0), &WSAData)) {
983 Error(
"TWinNTSystem()",
"Starting sockets failed");
994 char *buf =
new char[MAX_MODULE_NAME32 + 1];
1000 HMODULE hModCore = ::GetModuleHandle(
"libCore.dll");
1002 ::GetModuleFileName(hModCore, buf, MAX_MODULE_NAME32 + 1);
1003 char *pLibName = strstr(buf,
"libCore.dll");
1006 while (--pLibName >= buf && *pLibName !=
'\\' && *pLibName !=
'/');
1009 check_path +=
"\\etc";
1011 while (buf[0] && GetFileAttributes(check_path.
Data()) == INVALID_FILE_ATTRIBUTES) {
1012 while (--pLibName >= buf && *pLibName !=
'\\' && *pLibName !=
'/');
1015 check_path +=
"\\etc";
1030 UpdateRegistry(
this, buf);
1041 typedef UINT (WINAPI* LPTIMEENDPERIOD)( UINT uPeriod );
1042 HINSTANCE hInstWinMM = LoadLibrary(
"winmm.dll" );
1044 LPTIMEENDPERIOD pTimeEndPeriod = (LPTIMEENDPERIOD)GetProcAddress( hInstWinMM,
"timeEndPeriod" );
1045 if( NULL != pTimeEndPeriod )
1047 FreeLibrary(hInstWinMM);
1058 ::ResetEvent(gGlobalEvent);
1059 ::CloseHandle(gGlobalEvent);
1062 if (gTimerThreadHandle) {
1063 ::TerminateThread(gTimerThreadHandle, 0);
1064 ::CloseHandle(gTimerThreadHandle);
1073 const char *dir = 0;
1101 ::SetUnhandledExceptionFilter(ExceptionFilter);
1106 static char lpFilename[MAX_PATH];
1107 if (::GetModuleFileName(
1110 sizeof(lpFilename))) {
1118 typedef UINT (WINAPI* LPTIMEBEGINPERIOD)( UINT uPeriod );
1119 HINSTANCE hInstWinMM = LoadLibrary(
"winmm.dll" );
1121 LPTIMEBEGINPERIOD pTimeBeginPeriod = (LPTIMEBEGINPERIOD)GetProcAddress( hInstWinMM,
"timeBeginPeriod" );
1122 if( NULL != pTimeBeginPeriod )
1123 pTimeBeginPeriod(1);
1124 FreeLibrary(hInstWinMM);
1126 gTimerThreadHandle = ::CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)
ThreadStub,
1129 gGlobalEvent = ::CreateEvent(NULL,
TRUE,
FALSE, NULL);
1132 char *buf =
new char[MAX_MODULE_NAME32 + 1];
1133 HMODULE hModCore = ::GetModuleHandle(
"libCore.dll");
1135 ::GetModuleFileName(hModCore, buf, MAX_MODULE_NAME32 + 1);
1136 char *pLibName = strstr(buf,
"libCore.dll");
1143 SetConsoleWindowName();
1167 const char *symbol=
name;
1170 while ( (*symbol ==
' ' || *symbol ==
'\t') && *symbol) symbol++;
1173 if (isalpha(symbol[idx]) && symbol[idx+1] ==
':') idx = 2;
1174 if ( (symbol[idx] ==
'/' || symbol[idx] ==
'\\') && symbol[idx+1] ==
'\0') {
1179 Error(
"BaseName",
"name = 0");
1183 char *bslash = (
char *)strrchr(&symbol[idx],
'\\');
1184 char *rslash = (
char *)strrchr(&symbol[idx],
'/');
1185 if (cp = (std::max)(rslash, bslash)) {
1190 return &symbol[idx];
1192 Error(
"BaseName",
"name = 0");
1208 ULong_t namelen=name ? strlen(name) : 0;
1209 if (name && namelen > 0) {
1211 fullname =
new char[namelen+5];
1212 strlcpy(fullname, name,namelen+5);
1213 if ( !strrchr(fullname,
'.') )
1214 strlcat(fullname,
".exe",namelen+5);
1217 dot = strrchr(progname,
'.');
1218 idot = dot ? (
ULong_t)(dot - progname) : strlen(progname);
1223 which =
StrDup(fullname);
1234 dirname.
Form(
"%c:%s", driveletter, d);
1236 dirname.
Form(
"%s", d);
1249 progname[idot] =
'\0';
1251 if (which)
delete [] which;
1255 if (::NeedSplash()) {
1268 if (err < 0 || err >= sys_nerr) {
1270 error_msg.
Form(
"errno out of range %d", err);
1273 return sys_errlist[err];
1286 DWORD il =
sizeof(hn);
1287 ::GetComputerName(hn, &il);
1303 if (freq < 37) freq = 440;
1304 if (duration < 0) duration = 100;
1313 gGUIThreadMsgFunc = func;
1336 int fd = h->
GetFd();
1374 set_console =
kTRUE;
1387 ::SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleSigHandler,
TRUE);
1413 ::SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleSigHandler,
FALSE);
1457 HANDLE snapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,::GetCurrentProcessId());
1462 if (!InitImagehlpFunctions()) {
1463 std::cerr <<
"No stack trace: cannot find (functions in) dbghelp.dll!" << std::endl;
1468 SYSTEM_INFO sysInfo;
1469 ::GetSystemInfo(&sysInfo);
1470 DWORD machineType = IMAGE_FILE_MACHINE_I386;
1471 switch (sysInfo.wProcessorArchitecture) {
1472 case PROCESSOR_ARCHITECTURE_AMD64:
1473 machineType = IMAGE_FILE_MACHINE_AMD64;
1475 case PROCESSOR_ARCHITECTURE_IA64:
1476 machineType = IMAGE_FILE_MACHINE_IA64;
1480 DWORD currentThreadID = ::GetCurrentThreadId();
1481 DWORD currentProcessID = ::GetCurrentProcessId();
1485 THREADENTRY32 threadentry;
1486 threadentry.dwSize =
sizeof(THREADENTRY32);
1487 if (!::Thread32First(snapshot, &threadentry))
return;
1489 std::cerr << std::endl <<
"==========================================" << std::endl;
1490 std::cerr <<
"=============== STACKTRACE ===============" << std::endl;
1491 std::cerr <<
"==========================================" << std::endl << std::endl;
1494 if (threadentry.th32OwnerProcessID != currentProcessID)
1496 HANDLE thread = ::OpenThread(THREAD_GET_CONTEXT|THREAD_SUSPEND_RESUME|THREAD_QUERY_INFORMATION,
1497 FALSE, threadentry.th32ThreadID);
1499 memset(&context, 0,
sizeof(CONTEXT));
1501 if (threadentry.th32ThreadID != currentThreadID) {
1502 ::SuspendThread(thread);
1503 context.ContextFlags = CONTEXT_ALL;
1504 ::GetThreadContext(thread, &context);
1505 ::ResumeThread(thread);
1507 if (fgXcptContext) {
1508 context = *fgXcptContext;
1510 typedef void (WINAPI *RTLCCTXT)(PCONTEXT);
1511 RTLCCTXT p2RtlCCtxt = (RTLCCTXT) ::GetProcAddress(
1512 GetModuleHandle(
"kernel32.dll"),
"RtlCaptureContext");
1514 context.ContextFlags = CONTEXT_ALL;
1515 p2RtlCCtxt(&context);
1521 ::ZeroMemory(&frame,
sizeof(frame));
1523 frame.AddrPC.Mode = AddrModeFlat;
1524 frame.AddrFrame.Mode = AddrModeFlat;
1525 frame.AddrStack.Mode = AddrModeFlat;
1526 #if defined(_M_IX86) 1527 frame.AddrPC.Offset = context.Eip;
1528 frame.AddrFrame.Offset = context.Ebp;
1529 frame.AddrStack.Offset = context.Esp;
1530 #elif defined(_M_X64) 1531 frame.AddrPC.Offset = context.Rip;
1532 frame.AddrFrame.Offset = context.Rsp;
1533 frame.AddrStack.Offset = context.Rsp;
1534 #elif defined(_M_IA64) 1535 frame.AddrPC.Offset = context.StIIP;
1536 frame.AddrFrame.Offset = context.IntSp;
1537 frame.AddrStack.Offset = context.IntSp;
1538 frame.AddrBStore.Offset= context.RsBSP;
1540 std::cerr <<
"Stack traces not supported on your architecture yet." << std::endl;
1545 while (_StackWalk64(machineType, (HANDLE)::GetCurrentProcess(), thread, (LPSTACKFRAME64)&frame,
1546 (LPVOID)&context, (PREAD_PROCESS_MEMORY_ROUTINE)NULL, (PFUNCTION_TABLE_ACCESS_ROUTINE)_SymFunctionTableAccess64,
1547 (PGET_MODULE_BASE_ROUTINE)_SymGetModuleBase64, NULL)) {
1549 std::cerr << std::endl <<
"================ Thread " << iThread++ <<
" ================" << std::endl;
1550 if (!bFirst || threadentry.th32ThreadID != currentThreadID) {
1551 const std::string moduleName = GetModuleName(frame.AddrPC.Offset);
1552 const std::string functionName = GetFunctionName(frame.AddrPC.Offset);
1553 std::cerr <<
" " << moduleName << functionName << std::endl;
1557 ::CloseHandle(thread);
1558 }
while (::Thread32Next(snapshot, &threadentry));
1560 std::cerr << std::endl <<
"==========================================" << std::endl;
1561 std::cerr <<
"============= END STACKTRACE =============" << std::endl;
1562 std::cerr <<
"==========================================" << std::endl << std::endl;
1563 ::CloseHandle(snapshot);
1564 _SymCleanup(GetCurrentProcess());
1573 UInt_t oldmask = _statusfp( );
1575 if (oldmask & _EM_INVALID ) mask |=
kInvalid;
1576 if (oldmask & _EM_ZERODIVIDE) mask |=
kDivByZero;
1577 if (oldmask & _EM_OVERFLOW ) mask |=
kOverflow;
1578 if (oldmask & _EM_UNDERFLOW) mask |=
kUnderflow;
1579 if (oldmask & _EM_INEXACT ) mask |=
kInexact;
1593 if (mask &
kInvalid ) newm |= _EM_INVALID;
1594 if (mask &
kDivByZero) newm |= _EM_ZERODIVIDE;
1595 if (mask &
kOverflow ) newm |= _EM_OVERFLOW;
1596 if (mask &
kUnderflow) newm |= _EM_UNDERFLOW;
1597 if (mask &
kInexact ) newm |= _EM_INEXACT;
1601 ::_controlfp(cm , _MCW_EM);
1620 if (pendingOnly && gGlobalEvent) ::SetEvent(gGlobalEvent);
1622 Bool_t pollOnce = pendingOnly;
1626 if (
gROOT->GetApplication()) {
1642 ::WaitForSingleObject(gGlobalEvent, 1);
1643 ::ResetEvent(gGlobalEvent);
1669 if (pendingOnly && !pollOnce)
1708 if (!pendingOnly && gGlobalEvent) {
1709 ::WaitForSingleObject(gGlobalEvent, 1);
1710 ::ResetEvent(gGlobalEvent);
1724 for (i = 0; i <
fReadmask->GetCount(); i++) {
1729 rc = WinNTSelect(&t, 0, 0);
1730 if (rc < 0 && rc != -2) {
1731 ::SysError(
"DispatchOneEvent",
"select: read error on %d\n", fd);
1737 for (i = 0; i <
fWritemask->GetCount(); i++) {
1743 rc = WinNTSelect(0, &t, 0);
1744 if (rc < 0 && rc != -2) {
1745 ::SysError(
"DispatchOneEvent",
"select: write error on %d\n", fd);
1797 if (sync == sh->
IsSync()) {
1799 if ((
fSignals->IsSet(sig) && sigdone == -1) || sigdone == sig) {
1800 if (sigdone == -1) {
1810 if (sigdone != -1)
return kTRUE;
1831 if ((
fReadready->IsSet(fd) && fddone == -1) ||
1832 (fddone == fd && read)) {
1842 (fddone == fd && !read)) {
1852 if (fddone != -1)
return kTRUE;
1869 if (dirname.
Length() == 0) {
1878 const char driveletter =
DriveName(name);
1886 if (res)
return res;
1906 const char *
proto = (strstr(name,
"file:///")) ?
"file://" :
"file:";
1909 if (!name)
return 0;
1913 if (!name)
return 0;
1945 HANDLE searchFile = (HANDLE)dirp;
1979 return (psz[0] == TEXT(
'\\') && psz[1] == TEXT(
'\\'));
1999 #pragma data_seg(".text", "CODE") 2014 if (!IsDBCSLeadByte(*pPath)) {
2019 if ((*pPath == TEXT(
'\\')) && (*(pPath + 1) == 0))
2025 int cBackslashes = 0;
2026 for (p = pPath + 2; *p; p = CharNext(p)) {
2027 if (*p == TEXT(
'\\') && (++cBackslashes > 1))
2047 const char *
proto = (strstr(fdir,
"file:///")) ?
"file://" :
"file:";
2050 char *dir =
new char[MAX_PATH];
2051 if (IsShortcut(sdir)) {
2052 if (!ResolveShortCut(sdir, dir, MAX_PATH))
2053 strlcpy(dir, sdir,MAX_PATH);
2056 strlcpy(dir, sdir,MAX_PATH);
2058 int nche = strlen(dir)+3;
2059 char *entry =
new char[nche];
2060 struct _stati64 finfo;
2063 strlcpy(entry, dir,nche);
2064 if ((entry[strlen(dir)-1] ==
'/') || (entry[strlen(dir)-1] ==
'\\' )) {
2065 entry[strlen(dir)-1] =
'\0';
2068 strlcat(entry,
"\\",nche);
2070 if (_stati64(entry, &finfo) < 0) {
2077 strlcpy(entry, dir,nche);
2078 if ((entry[strlen(dir)-1] ==
'/') || (entry[strlen(dir)-1] ==
'\\' )) {
2080 entry[strlen(dir)-1] =
'\0';
2082 if (_stati64(entry, &finfo) < 0) {
2089 if (finfo.st_mode & S_IFDIR) {
2090 strlcpy(entry, dir,nche);
2091 if (!(entry[strlen(dir)-1] ==
'/' || entry[strlen(dir)-1] ==
'\\' )) {
2092 strlcat(entry,
"\\",nche);
2094 if (entry[strlen(dir)-1] ==
' ')
2095 entry[strlen(dir)-1] =
'\0';
2096 strlcat(entry,
"*",nche);
2165 char drive = driveletter ? toupper( driveletter ) -
'A' + 1 : 0;
2171 if (!(wdpath = ::_getdcwd( (
int)drive, wdpath,
kMAXPATHLEN))) {
2173 Warning(
"WorkingDirectory",
"getcwd() failed");
2197 return std::string(mydir);
2206 if (!(h = ::getenv(
"home"))) h = ::getenv(
"HOME");
2213 h = ::getenv(
"HOMESHARE");
2214 if (!h) h = ::getenv(
"HOMEDRIVE");
2217 h = ::getenv(
"HOMEPATH");
2222 h = ::getenv(
"USERPROFILE");
2227 if (mydir[1] ==
':')
2228 mydir[0] = toupper(mydir[0]);
2244 if (!dir) dir =
"c:\\";
2260 char tmpName[MAX_PATH];
2264 FILE *fp = fopen(tmpName,
"w+");
2266 if (!fp)
::SysError(
"TempFileName",
"error opening %s", tmpName);
2284 if (!opt || !opt[0]) {
2289 UINT nOldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS);
2293 curdrive = _getdrive();
2294 if (strstr(opt,
"cur")) {
2296 sDrive.
Form(
"%c:", (curdrive +
'A' - 1));
2297 sType.
Form(
"Unknown Drive (%s)", sDrive.
Data());
2298 ::GetVolumeInformation(
Form(
"%s\\", sDrive.
Data()), NULL, 0, NULL, NULL,
2299 NULL, (LPSTR)szFs, 32);
2300 type = ::GetDriveType(sDrive.
Data());
2303 case DRIVE_NO_ROOT_DIR:
2305 case DRIVE_REMOVABLE:
2306 sType.
Form(
"Removable Disk (%s)", sDrive.
Data());
2309 sType.
Form(
"Local Disk (%s)", sDrive.
Data());
2312 sType.
Form(
"Network Drive (%s) (%s)", szFs, sDrive.
Data());
2315 sType.
Form(
"CD/DVD Drive (%s)", sDrive.
Data());
2318 sType.
Form(
"RAM Disk (%s)", sDrive.
Data());
2323 else if (strstr(opt,
"all")) {
2326 if (::GetLogicalDriveStrings(511, szTemp)) {
2327 TCHAR szDrive[3] = TEXT(
" :");
2333 sDrive.
Form(
"%s", szDrive);
2335 if ((sDrive ==
"A:") || (sDrive ==
"B:")) {
2339 sType.
Form(
"Unknown Drive (%s)", sDrive.
Data());
2340 ::GetVolumeInformation(
Form(
"%s\\", sDrive.
Data()), NULL, 0, NULL,
2341 NULL, NULL, (LPSTR)szFs, 32);
2342 type = ::GetDriveType(sDrive.
Data());
2345 case DRIVE_NO_ROOT_DIR:
2347 case DRIVE_REMOVABLE:
2348 sType.
Form(
"Removable Disk (%s)", sDrive.
Data());
2351 sType.
Form(
"Local Disk (%s)", sDrive.
Data());
2354 sType.
Form(
"Network Drive (%s) (%s)", szFs, sDrive.
Data());
2357 sType.
Form(
"CD/DVD Drive (%s)", sDrive.
Data());
2360 sType.
Form(
"RAM Disk (%s)", sDrive.
Data());
2370 ::SetErrorMode(nOldErrorMode);
2389 if (strchr(pathname,
'/') || strchr(pathname,
'\\')) {
2390 const char *rslash = strrchr(pathname,
'/');
2391 const char *bslash = strrchr(pathname,
'\\');
2392 const char *
r = (std::max)(rslash, bslash);
2393 const char *ptr = pathname;
2403 int len = r - pathname;
2435 if (!pathname)
return 0;
2436 if (!pathname[0])
return 0;
2442 while(*lpchar ==
' ') lpchar++;
2444 if (isalpha((
int)*lpchar) && *(lpchar+1) ==
':') {
2448 if ( (*lpchar ==
'\\' || *lpchar ==
'/' ) &&
2449 (*(lpchar+1) ==
'\\' || *(lpchar+1) ==
'/') )
return 0;
2462 if (strchr(dir,
':')) idx = 2;
2463 return (dir[idx] ==
'/' || dir[idx] ==
'\\');
2496 const int kBufSize = 1024;
2497 TTHREAD_TLS_ARRAY(
char, kBufSize, temp);
2499 strlcpy(temp, name, kBufSize);
2500 char *currentChar = temp;
2503 while (*currentChar !=
'\0') {
2504 if (*currentChar ==
'\\') *currentChar =
'/';
2522 UINT nOldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS);
2526 const char *
proto = (strstr(path,
"file:///")) ?
"file://" :
"file:";
2529 ::SetErrorMode(nOldErrorMode);
2534 ::SetErrorMode(nOldErrorMode);
2556 if (name ==
".") name =
"";
2557 if (dir && dir[0]) {
2559 char last = dir[strlen(dir) - 1];
2560 if (last !=
'/' && last !=
'\\') {
2581 if (!ret)
return -1;
2590 int ret = ::rename(f, t);
2607 struct _stati64 sbuf;
2610 const char *
proto = (strstr(path,
"file:///")) ?
"file://" :
"file:";
2612 int l = strlen(newpath);
2614 if (newpath[--l] !=
'\\' || newpath[--l] !=
'/') {
2620 if (newpath && ::_stati64(newpath, &sbuf) >= 0) {
2622 buf.
fDev = sbuf.st_dev;
2623 buf.
fIno = sbuf.st_ino;
2624 buf.
fMode = sbuf.st_mode;
2625 buf.
fUid = sbuf.st_uid;
2626 buf.
fGid = sbuf.st_gid;
2627 buf.
fSize = sbuf.st_size;
2628 buf.
fMtime = sbuf.st_mtime;
2629 buf.
fIsLink = IsShortcut(newpath);
2631 char *lpath =
new char[MAX_PATH];
2632 if (IsShortcut(newpath)) {
2633 struct _stati64 sbuf2;
2634 if (ResolveShortCut(newpath, lpath, MAX_PATH)) {
2635 if (::_stati64(lpath, &sbuf2) >= 0) {
2636 buf.
fMode = sbuf2.st_mode;
2662 LPCTSTR lpRootPathName = path;
2665 LPTSTR lpVolumeNameBuffer = 0;
2666 DWORD nVolumeNameSize = 0;
2668 DWORD volumeSerialNumber;
2669 DWORD maximumComponentLength;
2672 DWORD fileSystemFlags;
2675 char fileSystemNameBuffer[512];
2676 DWORD nFileSystemNameSize =
sizeof(fileSystemNameBuffer);
2679 UINT nOldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS);
2680 if (!::GetVolumeInformation(lpRootPathName,
2681 lpVolumeNameBuffer, nVolumeNameSize,
2682 &volumeSerialNumber,
2683 &maximumComponentLength,
2685 fileSystemNameBuffer, nFileSystemNameSize)) {
2687 ::SetErrorMode(nOldErrorMode);
2691 const char *fsNames[] = {
"FAT",
"NTFS" };
2693 for (i = 0; i < 2; i++) {
2694 if (!strncmp(fileSystemNameBuffer, fsNames[i], nFileSystemNameSize))
2699 DWORD sectorsPerCluster;
2700 DWORD bytesPerSector;
2701 DWORD numberOfFreeClusters;
2702 DWORD totalNumberOfClusters;
2704 if (!::GetDiskFreeSpace(lpRootPathName,
2707 &numberOfFreeClusters,
2708 &totalNumberOfClusters)) {
2710 ::SetErrorMode(nOldErrorMode);
2714 ::SetErrorMode(nOldErrorMode);
2716 *bsize = sectorsPerCluster * bytesPerSector;
2717 *blocks = totalNumberOfClusters;
2718 *bfree = numberOfFreeClusters;
2728 struct _stati64 finfo;
2733 char linkname[1024];
2734 LPTSTR lpszFilePart;
2735 TCHAR szPath[MAX_PATH];
2738 typedef BOOL (__stdcall *CREATEHARDLINKPROC)( LPCTSTR, LPCTSTR, LPSECURITY_ATTRIBUTES );
2739 static CREATEHARDLINKPROC _CreateHardLink = 0;
2741 HMODULE hModImagehlp = LoadLibrary(
"Kernel32.dll" );
2746 _CreateHardLink = (CREATEHARDLINKPROC) GetProcAddress( hModImagehlp,
"CreateHardLinkW" );
2748 _CreateHardLink = (CREATEHARDLINKPROC) GetProcAddress( hModImagehlp,
"CreateHardLinkA" );
2750 if (!_CreateHardLink)
2753 dwRet = GetFullPathName(from,
sizeof(szPath) /
sizeof(TCHAR),
2754 szPath, &lpszFilePart);
2756 if (_stati64(szPath, &finfo) < 0)
2759 if (finfo.st_mode & S_IFDIR)
2763 _splitpath(linkname,winDrive,winDir,winName,winExt);
2764 if ((!winDrive[0] ) &&
2766 _splitpath(szPath,winDrive,winDir,winName,winExt);
2767 snprintf(linkname,1024,
"%s\\%s\\%s", winDrive, winDir, to);
2769 else if (!winDrive[0]) {
2770 _splitpath(szPath,winDrive,winDir,winName,winExt);
2771 snprintf(linkname,1024,
"%s\\%s", winDrive, to);
2774 if (!_CreateHardLink(linkname, szPath, NULL))
2787 IShellLink* pShellLink;
2788 IPersistFile* pPersistFile;
2789 WCHAR wszLinkfile[MAX_PATH];
2790 int iWideCharsWritten;
2792 LPTSTR lpszFilePart;
2793 TCHAR szPath[MAX_PATH];
2795 hRes = E_INVALIDARG;
2796 if ((from == NULL) || (!from[0]) || (to == NULL) ||
2802 typedef HRESULT (__stdcall *COINITIALIZEPROC)( LPVOID );
2803 static COINITIALIZEPROC _CoInitialize = 0;
2804 typedef void (__stdcall *COUNINITIALIZEPROC)(
void );
2805 static COUNINITIALIZEPROC _CoUninitialize = 0;
2806 typedef HRESULT (__stdcall *COCREATEINSTANCEPROC)( REFCLSID, LPUNKNOWN, DWORD, REFIID, LPVOID );
2807 static COCREATEINSTANCEPROC _CoCreateInstance = 0;
2809 HMODULE hModImagehlp = LoadLibrary(
"ole32.dll" );
2813 _CoInitialize = (COINITIALIZEPROC) GetProcAddress( hModImagehlp,
"CoInitialize" );
2816 _CoUninitialize = (COUNINITIALIZEPROC) GetProcAddress( hModImagehlp,
"CoUninitialize" );
2817 if (!_CoUninitialize)
2819 _CoCreateInstance = (COCREATEINSTANCEPROC) GetProcAddress( hModImagehlp,
"CoCreateInstance" );
2820 if (!_CoCreateInstance)
2827 _CoInitialize(NULL);
2830 dwRet = GetFullPathName(from,
sizeof(szPath) /
sizeof(TCHAR),
2831 szPath, &lpszFilePart);
2832 hRes = _CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
2833 IID_IShellLink, (LPVOID *)&pShellLink);
2834 if (SUCCEEDED(hRes)) {
2836 hRes = pShellLink->SetPath(szPath);
2838 hRes = pShellLink->QueryInterface(IID_IPersistFile, (
void **)&pPersistFile);
2839 if (SUCCEEDED(hRes)){
2840 iWideCharsWritten = MultiByteToWideChar(CP_ACP, 0, linkname.
Data(), -1,
2841 wszLinkfile, MAX_PATH);
2842 hRes = pPersistFile->Save(wszLinkfile,
TRUE);
2843 pPersistFile->Release();
2845 pShellLink->Release();
2858 return helper->
Unlink(name);
2860 struct _stati64 finfo;
2862 if (_stati64(name, &finfo) < 0) {
2866 if (finfo.st_mode & S_IFDIR) {
2867 return ::_rmdir(name);
2869 return ::_unlink(name);
2878 if (::ioctlsocket(fd, FIONBIO, (u_long *)1) == SOCKET_ERROR) {
2897 const char *patbuf = (
const char *)patbuf0;
2905 const char driveletter =
DriveName(patbuf);
2922 while (*patbuf ==
' ') {
2927 while (*patbuf ==
':') {
2932 while (*patbuf ==
';') {
2938 for (q = (
char*)patbuf; *
q; q++) {
2942 if ( (((q-2)>patbuf) && ( (*(q-2)!=
';') || !isalpha(*(q-1)) )) &&
2949 for (p = patbuf; *p; p++) {
2966 char replacement[4];
2969 for (
int k = 0; k<3; k++) replacement[k] = 0
x1;
2971 replacement[3] = 0x0;
2975 while ( (pos = patbuf0.
Index(TildaNum,pos)) !=
kNPOS ) {
2976 patbuf0.
Replace(pos, 1, replacement);
2982 Int_t lbuf = ::ExpandEnvironmentStrings(
2988 cmd =
new char[lbuf+1];
2989 ::ExpandEnvironmentStrings(
3008 char newpath[MAX_PATH];
3009 if (IsShortcut(path)) {
3010 if (!ResolveShortCut(path, newpath, MAX_PATH))
3011 strlcpy(newpath, path, MAX_PATH);
3014 strlcpy(newpath, path, MAX_PATH);
3029 return ::_chmod(file, mode);
3037 return ::umask(mask);
3047 Error(
"Utime",
"need write permission for %s to change utime", file);
3050 if (!actime) actime = modtime;
3053 t.actime = (time_t)actime;
3054 t.modtime = (time_t)modtime;
3055 return ::utime(file, &t);
3074 return infile.
Data();
3082 Int_t lastDelim = -1;
3083 for(
int i=0; i < exsearch.
Length(); ++i) {
3084 switch( exsearch[i] ) {
3087 if (i-lastDelim!=2) exsearch[i] =
';';
3090 case ';': lastDelim = i;
break;
3097 char *lpFilePart = 0;
3099 ::access(name, mode) == 0 && stat(name, &finfo) == 0 &&
3100 finfo.st_mode & S_IFREG) {
3102 Printf(
"Which: %s = %s", infile, name);
3105 return infile.
Data();
3119 if ((
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) && (::GetVersion() < 0x80000000)) {
3122 HINSTANCE netapi = ::LoadLibrary(
"netapi32.DLL");
3123 if (!netapi)
return kFALSE;
3125 p2NetApiBufferFree = (pfn1)::GetProcAddress(netapi,
"NetApiBufferFree");
3126 p2NetUserGetInfo = (pfn2)::GetProcAddress(netapi,
"NetUserGetInfo");
3127 p2NetLocalGroupGetMembers = (pfn3)::GetProcAddress(netapi,
"NetLocalGroupGetMembers");
3128 p2NetLocalGroupEnum = (pfn4)::GetProcAddress(netapi,
"NetLocalGroupEnum");
3130 if (!p2NetApiBufferFree || !p2NetUserGetInfo ||
3131 !p2NetLocalGroupGetMembers || !p2NetLocalGroupEnum)
return kFALSE;
3142 ::FreeLibrary(netapi);
3152 NET_API_STATUS NetStatus = NERR_Success;
3154 DWORD
Index = 0, ResumeHandle = 0, Total = 0;
3155 LOCALGROUP_MEMBERS_INFO_1 *MemberInfo;
3156 WCHAR wszGroupName[256];
3158 DWORD dwLastError = 0;
3160 iRetOp = MultiByteToWideChar (
3162 (DWORD)MB_PRECOMPOSED,
3163 (LPCSTR)lpszGroupName,
3165 (LPWSTR)wszGroupName,
3166 (
int)
sizeof(wszGroupName) );
3169 dwLastError = GetLastError();
3171 p2NetApiBufferFree(Data);
3177 NetStatus = p2NetLocalGroupGetMembers (NULL, wszGroupName, 1,
3178 &Data, 8192, &Index, &Total, &ResumeHandle );
3180 if (NetStatus != NERR_Success || Data == NULL) {
3181 dwLastError = GetLastError();
3183 if (dwLastError == ERROR_ENVVAR_NOT_FOUND) {
3189 NetStatus = p2NetLocalGroupGetMembers ( NULL, wszGroupName, 0,
3190 &Data, 8192, &Index, &Total, &ResumeHandle );
3194 p2NetApiBufferFree(Data);
3199 MemberInfo = (LOCALGROUP_MEMBERS_INFO_1 *)Data;
3202 p2NetApiBufferFree(Data);
3211 NET_API_STATUS NetStatus = NERR_Success;
3213 DWORD
Index = 0, ResumeHandle = 0, Total = 0, i;
3214 LOCALGROUP_INFO_0 *GroupInfo;
3215 char szAnsiName[256];
3216 DWORD dwLastError = 0;
3219 NetStatus = p2NetLocalGroupEnum(NULL, 0, &Data, 8192, &Index,
3220 &Total, &ResumeHandle );
3222 if (NetStatus != NERR_Success || Data == NULL) {
3223 dwLastError = GetLastError();
3225 p2NetApiBufferFree(Data);
3230 GroupInfo = (LOCALGROUP_INFO_0 *)Data;
3231 for (i=0; i < Total; i++) {
3233 iRetOp = WideCharToMultiByte (
3236 (LPCWSTR)(GroupInfo->lgrpi0_name),
3239 (
int)(
sizeof(szAnsiName)),
3251 p2NetApiBufferFree(Data);
3263 int &groupIdx,
int &memberIdx)
3265 BOOL bRetOp =
FALSE;
3267 DWORD dwSidSize, dwDomainNameSize;
3270 SID_NAME_USE sidType;
3271 PUCHAR puchar_SubAuthCount = NULL;
3272 SID_IDENTIFIER_AUTHORITY sid_identifier_authority;
3273 PSID_IDENTIFIER_AUTHORITY psid_identifier_authority = NULL;
3274 unsigned char j = 0;
3275 DWORD dwLastError = 0;
3277 pSid = (PSID)bySidBuffer;
3278 dwSidSize =
sizeof(bySidBuffer);
3279 dwDomainNameSize =
sizeof(szDomainName);
3281 bRetOp = LookupAccountName (
3283 (LPCTSTR)lpszAccountName,
3285 (LPDWORD)&dwSidSize,
3286 (LPTSTR)szDomainName,
3287 (LPDWORD)&dwDomainNameSize,
3288 (PSID_NAME_USE)&sidType );
3290 if (bRetOp ==
FALSE) {
3291 dwLastError = GetLastError();
3295 bRetOp = IsValidSid((PSID)pSid);
3297 if (bRetOp ==
FALSE) {
3298 dwLastError = GetLastError();
3303 psid_identifier_authority = GetSidIdentifierAuthority ((PSID)pSid);
3306 memcpy (&sid_identifier_authority, psid_identifier_authority,
3307 sizeof(SID_IDENTIFIER_AUTHORITY));
3310 puchar_SubAuthCount = (PUCHAR)GetSidSubAuthorityCount((PSID)pSid);
3312 j = (
unsigned char)(*puchar_SubAuthCount);
3314 DWORD dwSubAuth = 0;
3315 PDWORD pdwSubAuth = NULL;
3317 pdwSubAuth = (PDWORD)GetSidSubAuthority (
3320 dwSubAuth = *pdwSubAuth;
3339 NET_API_STATUS NetStatus = NERR_Success;
3341 DWORD
Index = 0, ResumeHandle = 0, Total = 0, i;
3342 LOCALGROUP_MEMBERS_INFO_1 *MemberInfo;
3343 char szAnsiMemberName[256];
3344 char szFullMemberName[256];
3345 char szMemberHomeDir[256];
3346 WCHAR wszGroupName[256];
3349 DWORD length =
sizeof (act_name);
3350 DWORD dwLastError = 0;
3351 LPUSER_INFO_11 pUI11Buf = NULL;
3352 NET_API_STATUS nStatus;
3354 iRetOp = MultiByteToWideChar (
3356 (DWORD)MB_PRECOMPOSED,
3357 (LPCSTR)lpszGroupName,
3359 (LPWSTR)wszGroupName,
3360 (
int)
sizeof(wszGroupName) );
3363 dwLastError = GetLastError();
3365 p2NetApiBufferFree(Data);
3369 GetUserName (act_name, &length);
3373 NetStatus = p2NetLocalGroupGetMembers (NULL, wszGroupName, 1,
3374 &Data, 8192, &Index, &Total, &ResumeHandle );
3376 if (NetStatus != NERR_Success || Data == NULL) {
3377 dwLastError = GetLastError();
3379 if (dwLastError == ERROR_ENVVAR_NOT_FOUND) {
3385 NetStatus = p2NetLocalGroupGetMembers ( NULL, wszGroupName, 0,
3386 &Data, 8192, &Index, &Total, &ResumeHandle );
3390 p2NetApiBufferFree(Data);
3394 MemberInfo = (LOCALGROUP_MEMBERS_INFO_1 *)Data;
3395 for (i=0; i < Total; i++) {
3396 iRetOp = WideCharToMultiByte (
3399 (LPCWSTR)(MemberInfo->lgrmi1_name),
3401 (LPSTR)szAnsiMemberName,
3402 (
int)(
sizeof(szAnsiMemberName)),
3407 dwLastError = GetLastError();
3418 TCHAR szUserName[255]=TEXT(
"");
3419 MultiByteToWideChar(CP_ACP, 0, szAnsiMemberName, -1, (LPWSTR)szUserName, 255);
3423 nStatus = p2NetUserGetInfo(NULL, (LPCWSTR)szUserName, 11, (LPBYTE *)&pUI11Buf);
3427 if (nStatus == NERR_Success) {
3428 if (pUI11Buf != NULL) {
3429 wsprintf(szFullMemberName,
"%S",pUI11Buf->usri11_full_name);
3431 wsprintf(szMemberHomeDir,
"%S",pUI11Buf->usri11_home_dir);
3442 if (pUI11Buf != NULL) {
3443 p2NetApiBufferFree(pUI11Buf);
3448 if (getenv(
"SHELL") == NULL)
3449 putenv ((GetVersion () & 0x80000000) ?
"SHELL=command" :
"SHELL=cmd");
3462 p2NetApiBufferFree(Data);
3472 NET_API_STATUS NetStatus = NERR_Success;
3474 DWORD
Index = 0, ResumeHandle = 0, Total = 0, i;
3475 LOCALGROUP_INFO_0 *GroupInfo;
3476 char szAnsiName[256];
3477 DWORD dwLastError = 0;
3478 int iRetOp = 0, iGroupIdx = 0, iMemberIdx = 0;
3480 NetStatus = p2NetLocalGroupEnum(NULL, 0, &Data, 8192, &Index,
3481 &Total, &ResumeHandle );
3483 if (NetStatus != NERR_Success || Data == NULL) {
3484 dwLastError = GetLastError();
3486 p2NetApiBufferFree(Data);
3490 GroupInfo = (LOCALGROUP_INFO_0 *)Data;
3491 for (i=0; i < Total; i++) {
3493 iRetOp = WideCharToMultiByte (
3496 (LPCWSTR)(GroupInfo->lgrpi0_name),
3499 (
int)(
sizeof(szAnsiName)),
3517 p2NetApiBufferFree(Data);
3531 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3534 DWORD length =
sizeof (
name);
3535 if (::GetUserName (name, &length)) {
3536 if (stricmp (
"administrator", name) == 0)
3546 if (!user || !user[0])
3572 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3575 DWORD length =
sizeof (
name);
3576 if (::GetUserName (name, &length)) {
3577 if (stricmp (
"administrator", name) == 0)
3599 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3602 DWORD length =
sizeof (
name);
3603 if (::GetUserName (name, &length)) {
3604 if (stricmp (
"administrator", name) == 0)
3614 if (!group || !group[0])
3617 struct group *grp = 0;
3640 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3643 DWORD length =
sizeof (
name);
3644 if (::GetUserName (name, &length)) {
3645 if (stricmp (
"administrator", name) == 0)
3668 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3670 DWORD length =
sizeof (
name);
3672 if (::GetUserName (name, &length)) {
3674 if (stricmp (
"administrator", name) == 0) {
3676 ug->
fGroup =
"administrators";
3685 ug->
fUser =
"unknown";
3698 for (
int i = 0; i <
fNbUsers; i++) {
3742 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3744 DWORD length =
sizeof (
name);
3746 if (::GetUserName (name, &length)) {
3747 if (stricmp (
"administrator", name) == 0) {
3748 gr->
fGroup =
"administrators";
3763 struct group *grp = 0;
3808 const char *env = ::getenv(name);
3810 if (::_stricmp(name,
"home") == 0 ) {
3812 }
else if (::_stricmp(name,
"rootsys") == 0 ) {
3826 return ::system(shellcmd);
3834 return ::_popen(command, mode);
3842 return ::_pclose(pipe);
3869 gROOT->CloseFiles();
3870 if (
gROOT->GetListOfBrowsers()) {
3873 if (
gROOT->IsBatch())
3874 gROOT->GetListOfBrowsers()->Delete();
3880 if (((TBrowser*)0x%lx)->GetBrowserImp() &&\ 3881 ((TBrowser*)0x%lx)->GetBrowserImp()->GetMainFrame()) \ 3882 ((TBrowser*)0x%lx)->GetBrowserImp()->GetMainFrame()->CloseWindow();\ 3886 gROOT->EndOfProcessCleanups();
3926 static int fd1=0, fd2=0;
3927 static fpos_t pos1=0, pos2=0;
3937 const char *
m = (mode[0] ==
'a' || mode[0] ==
'w') ? mode :
"a";
3950 fgetpos(stdout, &pos1);
3951 fd1 = _dup(fileno(stdout));
3953 if ((fout = freopen(file, m, stdout)) == 0) {
3954 SysError(
"RedirectOutput",
"could not freopen stdout");
3956 _dup2(fd1, fileno(stdout));
3960 fsetpos(stdout, &pos1);
3965 fgetpos(stderr, &pos2);
3966 fd2 = _dup(fileno(stderr));
3967 if ((ferr = freopen(file, m, stderr)) == 0) {
3968 SysError(
"RedirectOutput",
"could not freopen stderr");
3970 _dup2(fd1, fileno(stdout));
3974 fsetpos(stdout, &pos1);
3976 _dup2(fd2, fileno(stderr));
3980 fsetpos(stderr, &pos2);
3985 fseek(fout, 0, SEEK_END);
3986 fseek(ferr, 0, SEEK_END);
3993 if (_dup2(fd1, fileno(stdout))) {
3994 SysError(
"RedirectOutput",
"could not restore stdout");
4000 fsetpos(stdout, &pos1);
4007 if (_dup2(fd2, fileno(stderr))) {
4008 SysError(
"RedirectOutput",
"could not restore stderr");
4014 fsetpos(stderr, &pos2);
4069 if (len > 4 && (!stricmp(sLib.
Data()+len-4,
".dll"))) {
4082 Error(
"DynamicPathName",
4083 "%s does not exist in %s,\nor has wrong file extension (.dll)",
4100 #pragma warning(push) 4101 #pragma warning(disable:4200) 4118 if (!linkedLibs.
IsNull())
4131 HANDLE hFile, hMapping;
4134 if((hFile = CreateFile(exe,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0))==
INVALID_HANDLE_VALUE) {
4138 if(!(hMapping = CreateFileMapping(hFile,0,PAGE_READONLY|SEC_COMMIT,0,0,0))) {
4143 if(!(basepointer = MapViewOfFile(hMapping,FILE_MAP_READ,0,0,0))) {
4144 CloseHandle(hMapping);
4151 IMAGE_DOS_HEADER *dos_head = (IMAGE_DOS_HEADER *)basepointer;
4154 IMAGE_FILE_HEADER _head;
4155 IMAGE_OPTIONAL_HEADER opt_head;
4156 IMAGE_SECTION_HEADER section_header[];
4158 struct header *pheader;
4159 const IMAGE_SECTION_HEADER * section_header;
4161 if(dos_head->e_magic!=
'ZM') {
4166 pheader = (
struct header *)((
char*)dos_head + dos_head->e_lfanew);
4168 if(IsBadReadPtr(pheader,
sizeof(
struct header))) {
4172 if(pheader->signature!=IMAGE_NT_SIGNATURE) {
4173 switch((
unsigned short)pheader->signature) {
4174 case IMAGE_DOS_SIGNATURE:
4177 case IMAGE_OS2_SIGNATURE:
4180 case IMAGE_OS2_SIGNATURE_LE:
4188 #define isin(address,start,length) ((address)>=(start) && (address)<(start)+(length)) 4191 for(sect=0,section_header=pheader->section_header;
4192 sect<pheader->_head.NumberOfSections;sect++,section_header++) {
4194 const void *
const section_data =
4195 (
char*)basepointer + section_header->PointerToRawData;
4196 for(directory=0;directory<IMAGE_NUMBEROF_DIRECTORY_ENTRIES;directory++) {
4197 if(
isin(pheader->opt_head.DataDirectory[directory].VirtualAddress,
4198 section_header->VirtualAddress,
4199 section_header->SizeOfRawData)) {
4200 const IMAGE_IMPORT_DESCRIPTOR *stuff_start =
4201 (IMAGE_IMPORT_DESCRIPTOR *)((
char*)section_data +
4202 (pheader->opt_head.DataDirectory[directory].VirtualAddress -
4203 section_header->VirtualAddress));
4206 const unsigned stuff_length =
4207 pheader->opt_head.DataDirectory[directory].Size;
4208 if(directory == IMAGE_DIRECTORY_ENTRY_IMPORT) {
4209 while(!IsBadReadPtr(stuff_start,
sizeof(*stuff_start)) &&
4210 stuff_start->Name) {
4211 TString dll = (
char*)section_data +
4212 ((DWORD)(stuff_start->Name)) -
4213 section_header->VirtualAddress;
4217 char *winPath = getenv(
"windir");
4218 _splitpath(winPath,winDrive,winDir,winName,winExt);
4219 if(!strstr(dllPath, winDir)) {
4220 if (!linkedLibs.
IsNull())
4222 linkedLibs += dllPath;
4234 UnmapViewOfFile(basepointer);
4235 CloseHandle(hMapping);
4247 #pragma warning(pop) 4268 TRegexp separator(
"[^ \\t\\s]+");
4273 Ssiz_t start, index, end;
4274 start = index = end = 0;
4276 while ((start < libs.
Length()) && (index !=
kNPOS)) {
4277 index = libs.
Index(separator, &end, start);
4281 s = libs(index, end);
4358 if (mode && t->
IsSync()) {
4362 }
else if (!mode && t->
IsAsync()) {
4380 FILETIME ftFileTime;
4384 ::GetSystemTimeAsFileTime(&ftRealTime.ftFileTime);
4393 OSVERSIONINFO OsVersionInfo;
4402 OsVersionInfo.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
4403 GetVersionEx(&OsVersionInfo);
4404 if (OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
4410 FILETIME ftFileTime;
4415 FILETIME ftFileTime;
4419 HANDLE hThread = GetCurrentThread();
4420 ret = GetThreadTimes (hThread, &ftCreate, &ftExit,
4421 &ftKernel.ftFileTime,
4422 &ftUser.ftFileTime);
4424 ret = ::GetLastError();
4425 ::Error(
"GetCPUTime",
" Error on GetProcessTimes 0x%lx", (
int)ret);
4445 static time_t jan95 = 0;
4456 jan95 = mktime(&tp);
4457 if ((
int)jan95 == -1) {
4458 ::SysError(
"TWinNTSystem::Now",
"error converting 950001 0:00 to time_t");
4465 return TTime((now.time-(
Long_t)jan95)*1000 + now.millitm);
4497 rc = WinNTSelect(&rd, &wr, to);
4531 rc = WinNTSelect(&rd, &wr, to);
4553 if ((sp = ::getservbyname(servicename,
kProtocolName)) == 0) {
4554 Error(
"GetServiceByName",
"no service \"%s\" with protocol \"%s\"\n",
4558 return ::ntohs(sp->s_port);
4569 if ((sp = ::getservbyport(::htons(port),
kProtocolName)) == 0) {
4570 return Form(
"%d", port);
4580 struct hostent *host_ptr;
4585 if ((addr = ::inet_addr(hostname)) != INADDR_NONE) {
4587 if ((host_ptr = ::gethostbyaddr((
const char *)&addr,
4588 sizeof(addr), AF_INET))) {
4589 host = host_ptr->h_name;
4593 for (i = 1; host_ptr->h_addr_list[i]; i++) {
4594 memcpy(&addr2, host_ptr->h_addr_list[i], host_ptr->h_length);
4597 for (i = 0; host_ptr->h_aliases[i]; i++)
4598 a.
AddAlias(host_ptr->h_aliases[i]);
4601 host =
"UnNamedHost";
4603 }
else if ((host_ptr = ::gethostbyname(hostname))) {
4605 if (host_ptr->h_addrtype != AF_INET) {
4606 Error(
"GetHostByName",
"%s is not an internet host\n", hostname);
4609 memcpy(&addr, host_ptr->h_addr, host_ptr->h_length);
4610 host = host_ptr->h_name;
4611 type = host_ptr->h_addrtype;
4615 for (i = 1; host_ptr->h_addr_list[i]; i++) {
4616 memcpy(&addr2, host_ptr->h_addr_list[i], host_ptr->h_length);
4619 for (i = 0; host_ptr->h_aliases[i]; i++)
4620 a.
AddAlias(host_ptr->h_aliases[i]);
4623 if (
gDebug > 0)
Error(
"GetHostByName",
"unknown host %s", hostname);
4636 struct sockaddr_in addr;
4637 int len =
sizeof(addr);
4639 if (::getpeername(sock, (
struct sockaddr *)&addr, &len) == SOCKET_ERROR) {
4644 struct hostent *host_ptr;
4645 const char *hostname;
4649 if ((host_ptr = ::gethostbyaddr((
const char *)&addr.sin_addr,
4650 sizeof(addr.sin_addr), AF_INET))) {
4651 memcpy(&iaddr, host_ptr->h_addr, host_ptr->h_length);
4652 hostname = host_ptr->h_name;
4653 family = host_ptr->h_addrtype;
4655 memcpy(&iaddr, &addr.sin_addr,
sizeof(addr.sin_addr));
4660 return TInetAddress(hostname, ::ntohl(iaddr), family, ::ntohs(addr.sin_port));
4669 struct sockaddr_in addr;
4670 int len =
sizeof(addr);
4672 if (::getsockname(sock, (
struct sockaddr *)&addr, &len) == SOCKET_ERROR) {
4677 struct hostent *host_ptr;
4678 const char *hostname;
4682 if ((host_ptr = ::gethostbyaddr((
const char *)&addr.sin_addr,
4683 sizeof(addr.sin_addr), AF_INET))) {
4684 memcpy(&iaddr, host_ptr->h_addr, host_ptr->h_length);
4685 hostname = host_ptr->h_name;
4686 family = host_ptr->h_addrtype;
4688 memcpy(&iaddr, &addr.sin_addr,
sizeof(addr.sin_addr));
4693 return TInetAddress(hostname, ::ntohl(iaddr), family, ::ntohs(addr.sin_port));
4704 if ((sock = ::socket(AF_INET, SOCK_STREAM, 0)) ==
INVALID_SOCKET) {
4705 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"socket");
4709 struct sockaddr_in inserver;
4710 memset(&inserver, 0,
sizeof(inserver));
4711 inserver.sin_family = AF_INET;
4712 inserver.sin_addr.s_addr = ::htonl(INADDR_LOOPBACK);
4713 inserver.sin_port = port;
4717 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver)) == SOCKET_ERROR) {
4718 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"bind");
4723 if (::listen(sock, backlog)) {
4724 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"listen");
4736 if (!sockpath || strlen(sockpath) <= 0) {
4737 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"socket path undefined");
4741 struct sockaddr_in myaddr;
4743 int len =
sizeof myaddr;
4748 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
4749 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"socket");
4753 memset(&myaddr, 0,
sizeof(myaddr));
4754 myaddr.sin_port = 0;
4755 myaddr.sin_family = AF_INET;
4756 myaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
4758 rc = bind(sock, (
struct sockaddr *)&myaddr, len);
4760 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"bind");
4763 rc = getsockname(sock, (
struct sockaddr *)&myaddr, &len);
4765 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"getsockname");
4768 TString socketpath = sockpath;
4770 fp = fopen(socketpath,
"wb");
4772 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"fopen");
4775 fprintf(fp,
"%d", myaddr.sin_port);
4779 if (listen(sock, backlog)) {
4780 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"listen");
4792 if (socket == -1)
return;
4796 ::shutdown(sock, 2);
4798 struct linger linger = {0, 0};
4799 ::setsockopt(sock, SOL_SOCKET, SO_LINGER, (
char *) &linger,
sizeof(linger));
4800 while (::
closesocket(sock) == SOCKET_ERROR && WSAGetLastError() == WSAEINTR) {
4814 if (WinNTRecv(sock, &header,
sizeof(header), 0) > 0) {
4815 int count = ::ntohl(header);
4817 if (count > length) {
4818 Error(
"RecvBuf",
"record header exceeds buffer size");
4820 }
else if (count > 0) {
4821 if (WinNTRecv(sock, buf, count, 0) < 0) {
4822 Error(
"RecvBuf",
"cannot receive buffer");
4837 Int_t header = ::htonl(length);
4839 if (WinNTSend(sock, &header,
sizeof(header), 0) < 0) {
4840 Error(
"SendBuf",
"cannot send header");
4844 if (WinNTSend(sock, buf, length, 0) < 0) {
4845 Error(
"SendBuf",
"cannot send buffer");
4885 if ((n = WinNTRecv(sock, buf, length, flag)) <= 0) {
4887 Error(
"RecvRaw",
"cannot receive buffer");
4921 if ((n = WinNTSend(sock, buf, length, flag)) <= 0) {
4922 if (n == -1 &&
GetErrno() != EINTR) {
4923 Error(
"SendRaw",
"cannot send buffer");
4936 if (socket == -1)
return -1;
4941 if (::setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4942 ::SysError(
"SetSockOpt",
"setsockopt(SO_SNDBUF)");
4947 if (::setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4948 ::SysError(
"SetSockOpt",
"setsockopt(SO_RCVBUF)");
4953 if (::setsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4954 SysError(
"SetSockOpt",
"setsockopt(SO_OOBINLINE)");
4959 if (::setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4960 ::SysError(
"SetSockOpt",
"setsockopt(SO_KEEPALIVE)");
4965 if (::setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4966 ::SysError(
"SetSockOpt",
"setsockopt(SO_REUSEADDR)");
4971 if (::setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4972 ::SysError(
"SetSockOpt",
"setsockopt(TCP_NODELAY)");
4977 if (::ioctlsocket(sock, FIONBIO, &val) == SOCKET_ERROR) {
4984 if (::ioctl(sock, SIOCSPGRP, &val) == -1) {
4985 ::SysError(
"SetSockOpt",
"ioctl(SIOCSPGRP)");
4993 Error(
"SetSockOpt",
"illegal option (%d)", opt);
5005 if (socket == -1)
return -1;
5008 int optlen =
sizeof(*val);
5012 if (::getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)val, &optlen) == SOCKET_ERROR) {
5013 ::SysError(
"GetSockOpt",
"getsockopt(SO_SNDBUF)");
5018 if (::getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)val, &optlen) == SOCKET_ERROR) {
5019 ::SysError(
"GetSockOpt",
"getsockopt(SO_RCVBUF)");
5024 if (::getsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)val, &optlen) == SOCKET_ERROR) {
5025 ::SysError(
"GetSockOpt",
"getsockopt(SO_OOBINLINE)");
5030 if (::getsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)val, &optlen) == SOCKET_ERROR) {
5031 ::SysError(
"GetSockOpt",
"getsockopt(SO_KEEPALIVE)");
5036 if (::getsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)val, &optlen) == SOCKET_ERROR) {
5037 ::SysError(
"GetSockOpt",
"getsockopt(SO_REUSEADDR)");
5042 if (::getsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)val, &optlen) == SOCKET_ERROR) {
5043 ::SysError(
"GetSockOpt",
"getsockopt(TCP_NODELAY)");
5059 if (::ioctlsocket(sock, SIOCGPGRP, (u_long*)val) == SOCKET_ERROR) {
5060 ::SysError(
"GetSockOpt",
"ioctl(SIOCGPGRP)");
5066 if (::ioctlsocket(sock, SIOCATMARK, (u_long*)val) == SOCKET_ERROR) {
5067 ::SysError(
"GetSockOpt",
"ioctl(SIOCATMARK)");
5072 if (::ioctlsocket(sock, FIONREAD, (u_long*)val) == SOCKET_ERROR) {
5078 Error(
"GetSockOpt",
"illegal option (%d)", opt);
5090 int tcpwindowsize,
const char *protocol)
5095 if (!strcmp(servername,
"unix")) {
5099 (servername[1] ==
':' && servername[2] ==
'/')) {
5103 if (!strcmp(protocol,
"udp")){
5110 sport = ::htons(port);
5114 if (!addr.
IsValid())
return -1;
5117 struct sockaddr_in server;
5118 memset(&server, 0,
sizeof(server));
5119 memcpy(&server.sin_addr, &adr,
sizeof(adr));
5121 server.sin_port = sport;
5125 if ((sock = ::socket(AF_INET, SOCK_STREAM, 0)) ==
INVALID_SOCKET) {
5126 ::SysError(
"TWinNTSystem::WinNTConnectTcp",
"socket");
5130 if (tcpwindowsize > 0) {
5135 if (::connect(sock, (
struct sockaddr*) &server,
sizeof(server)) ==
INVALID_SOCKET) {
5148 struct sockaddr_in myaddr;
5151 memset(&myaddr, 0,
sizeof(myaddr));
5152 myaddr.sin_family = AF_INET;
5153 myaddr.sin_port = port;
5154 myaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
5157 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
5158 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"socket");
5162 while ((connect(sock, (
struct sockaddr *)&myaddr,
sizeof myaddr)) == -1) {
5166 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"connect");
5182 if (!sockpath || strlen(sockpath) <= 0) {
5183 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"socket path undefined");
5186 TString socketpath = sockpath;
5188 fp = fopen(socketpath.
Data(),
"rb");
5190 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"fopen");
5193 fscanf(fp,
"%d", &port);
5196 if (port < 0 || port > 65535) {
5197 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"invalid port");
5215 sport = htons(port);
5218 if (!addr.
IsValid())
return -1;
5221 struct sockaddr_in server;
5222 memset(&server, 0,
sizeof(server));
5223 memcpy(&server.sin_addr, &adr,
sizeof(adr));
5225 server.sin_port = sport;
5229 if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
5230 ::SysError(
"TWinNTSystem::WinNTUdpConnect",
"socket (%s:%d)",
5235 while (connect(sock, (
struct sockaddr*) &server,
sizeof(server)) == -1) {
5239 ::SysError(
"TWinNTSystem::WinNTUdpConnect",
"connect (%s:%d)",
5257 const char *protocol)
5278 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
5279 short tryport = kSOCKET_MINPORT;
5284 sport = ::htons(port);
5287 if (port == 0 && reuse) {
5288 ::Error(
"TWinNTSystem::WinNTTcpService",
"cannot do a port scan while reuse is true");
5295 sport = ::htons(port);
5300 if ((sock = ::socket(AF_INET, SOCK_STREAM, 0)) < 0) {
5301 ::SysError(
"TWinNTSystem::WinNTTcpService",
"socket");
5309 if (tcpwindowsize > 0) {
5314 struct sockaddr_in inserver;
5315 memset(&inserver, 0,
sizeof(inserver));
5316 inserver.sin_family = AF_INET;
5317 inserver.sin_addr.s_addr = ::htonl(INADDR_ANY);
5318 inserver.sin_port = sport;
5322 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver)) == SOCKET_ERROR) {
5323 ::SysError(
"TWinNTSystem::WinNTTcpService",
"bind");
5329 inserver.sin_port = ::htons(tryport);
5330 bret = ::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
5332 }
while (bret == SOCKET_ERROR && WSAGetLastError() == WSAEADDRINUSE &&
5333 tryport < kSOCKET_MAXPORT);
5334 if (bret == SOCKET_ERROR) {
5335 ::SysError(
"TWinNTSystem::WinNTTcpService",
"bind (port scan)");
5341 if (::listen(sock, backlog) == SOCKET_ERROR) {
5342 ::SysError(
"TWinNTSystem::WinNTTcpService",
"listen");
5359 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
5360 short sport, tryport = kSOCKET_MINPORT;
5366 sport = htons(port);
5370 if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
5371 ::SysError(
"TUnixSystem::UnixUdpService",
"socket");
5375 struct sockaddr_in inserver;
5376 memset(&inserver, 0,
sizeof(inserver));
5377 inserver.sin_family = AF_INET;
5378 inserver.sin_addr.s_addr = htonl(INADDR_ANY);
5379 inserver.sin_port = sport;
5383 if (bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver))) {
5384 ::SysError(
"TWinNTSystem::AnnounceUdpService",
"bind");
5390 inserver.sin_port = htons(tryport);
5391 bret = bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
5393 }
while (bret == SOCKET_ERROR && WSAGetLastError() == WSAEADDRINUSE &&
5394 tryport < kSOCKET_MAXPORT);
5396 ::SysError(
"TWinNTSystem::AnnounceUdpService",
"bind (port scan)");
5402 if (listen(sock, backlog)) {
5403 ::SysError(
"TWinNTSystem::AnnounceUdpService",
"listen");
5421 (::WSAGetLastError() == WSAEINTR)) {
5426 if (::WSAGetLastError() == WSAEWOULDBLOCK) {
5440 #define SystemBasicInformation 0 5441 #define SystemPerformanceInformation 2 5446 ULONG uKeMaximumIncrement;
5448 ULONG uMmNumberOfPhysicalPages;
5449 ULONG uMmLowestPhysicalPage;
5450 ULONG UMmHighestPhysicalPage;
5451 ULONG uAllocationGranularity;
5452 PVOID pLowestUserAddress;
5453 PVOID pMmHighestUserAddress;
5454 ULONG uKeActiveProcessors;
5455 BYTE bKeNumberProcessors;
5458 } SYSTEM_BASIC_INFORMATION;
5462 LARGE_INTEGER liIdleTime;
5464 } SYSTEM_PERFORMANCE_INFORMATION;
5466 typedef struct _PROCESS_MEMORY_COUNTERS {
5468 DWORD PageFaultCount;
5469 SIZE_T PeakWorkingSetSize;
5470 SIZE_T WorkingSetSize;
5471 SIZE_T QuotaPeakPagedPoolUsage;
5472 SIZE_T QuotaPagedPoolUsage;
5473 SIZE_T QuotaPeakNonPagedPoolUsage;
5474 SIZE_T QuotaNonPagedPoolUsage;
5475 SIZE_T PagefileUsage;
5476 SIZE_T PeakPagefileUsage;
5481 #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + (double)((x).LowPart)) 5489 LARGE_INTEGER ulFreq, ulTicks, ulValue, ulStartCounter;
5493 if (QueryPerformanceFrequency(&ulFreq)) {
5495 QueryPerformanceCounter(&ulTicks);
5498 ulValue.QuadPart = ulTicks.QuadPart + ulFreq.QuadPart/10;
5499 ulStartCounter.QuadPart =
__rdtsc();
5503 QueryPerformanceCounter(&ulTicks);
5504 }
while (ulTicks.QuadPart <= ulValue.QuadPart);
5506 return (DWORD)((
__rdtsc() - ulStartCounter.QuadPart)/100000);
5514 #define SM_SERVERR2 89 5521 OSVERSIONINFOEX osvi;
5524 BOOL bOsVersionInfoEx;
5525 static char *strReturn = 0;
5529 strReturn =
new char[2048];
5533 ZeroMemory(&si,
sizeof(SYSTEM_INFO));
5534 ZeroMemory(&osvi,
sizeof(OSVERSIONINFOEX));
5539 osvi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFOEX);
5541 if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
5543 osvi.dwOSVersionInfoSize =
sizeof (OSVERSIONINFO);
5544 if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
5549 pGNSI = (
PGNSI) GetProcAddress( GetModuleHandle(
"kernel32.dll"),
5550 "GetNativeSystemInfo");
5553 else GetSystemInfo(&si);
5555 switch (osvi.dwPlatformId)
5558 case VER_PLATFORM_WIN32_NT:
5561 if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 )
5563 if( osvi.wProductType == VER_NT_WORKSTATION )
5564 strlcpy(strReturn,
"Microsoft Windows Vista ",2048);
5565 else strlcpy(strReturn,
"Windows Server \"Longhorn\" " ,2048);
5567 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
5570 strlcpy(strReturn,
"Microsoft Windows Server 2003 \"R2\" ",2048);
5571 else if( osvi.wProductType == VER_NT_WORKSTATION &&
5572 si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
5574 strlcpy(strReturn,
"Microsoft Windows XP Professional x64 Edition ",2048);
5576 else strlcpy(strReturn,
"Microsoft Windows Server 2003, ",2048);
5578 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
5579 strlcpy(strReturn,
"Microsoft Windows XP ",2048);
5581 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
5582 strlcpy(strReturn,
"Microsoft Windows 2000 ",2048);
5584 if ( osvi.dwMajorVersion <= 4 )
5585 strlcpy(strReturn,
"Microsoft Windows NT ",2048);
5588 if( bOsVersionInfoEx )
5591 if ( osvi.wProductType == VER_NT_WORKSTATION &&
5592 si.wProcessorArchitecture!=PROCESSOR_ARCHITECTURE_AMD64)
5594 if( osvi.dwMajorVersion == 4 )
5595 strlcat(strReturn,
"Workstation 4.0 ",2048 );
5596 else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
5597 strlcat(strReturn,
"Home Edition " ,2048);
5598 else strlcat(strReturn,
"Professional " ,2048);
5601 else if ( osvi.wProductType == VER_NT_SERVER ||
5602 osvi.wProductType == VER_NT_DOMAIN_CONTROLLER )
5604 if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==2)
5606 if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_IA64 )
5608 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
5609 strlcat(strReturn,
"Datacenter Edition for Itanium-based Systems",2048 );
5610 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5611 strlcat(strReturn,
"Enterprise Edition for Itanium-based Systems" ,2048);
5613 else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
5615 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
5616 strlcat(strReturn,
"Datacenter x64 Edition ",2048 );
5617 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5618 strlcat(strReturn,
"Enterprise x64 Edition ",2048 );
5619 else strlcat(strReturn,
"Standard x64 Edition ",2048 );
5623 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
5624 strlcat(strReturn,
"Datacenter Edition ",2048 );
5625 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5626 strlcat(strReturn,
"Enterprise Edition ",2048 );
5627 else if ( osvi.wSuiteMask == VER_SUITE_BLADE )
5628 strlcat(strReturn,
"Web Edition " ,2048);
5629 else strlcat(strReturn,
"Standard Edition ",2048 );
5632 else if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==0)
5634 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
5635 strlcat(strReturn,
"Datacenter Server ",2048 );
5636 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5637 strlcat(strReturn,
"Advanced Server ",2048 );
5638 else strlcat(strReturn,
"Server ",2048 );
5642 if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5643 strlcat(strReturn,
"Server 4.0, Enterprise Edition " ,2048);
5644 else strlcat(strReturn,
"Server 4.0 ",2048 );
5653 DWORD dwBufLen=
BUFSIZE*
sizeof(TCHAR);
5656 lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
5657 "SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
5658 0, KEY_QUERY_VALUE, &hKey );
5659 if( lRet != ERROR_SUCCESS )
5662 lRet = RegQueryValueEx( hKey,
"ProductType", NULL, NULL,
5663 (LPBYTE) szProductType, &dwBufLen);
5664 RegCloseKey( hKey );
5666 if( (lRet != ERROR_SUCCESS) || (dwBufLen >
BUFSIZE*
sizeof(TCHAR)) )
5669 if ( lstrcmpi(
"WINNT", szProductType) == 0 )
5670 strlcat(strReturn,
"Workstation " ,2048);
5671 if ( lstrcmpi(
"LANMANNT", szProductType) == 0 )
5672 strlcat(strReturn,
"Server " ,2048);
5673 if ( lstrcmpi(
"SERVERNT", szProductType) == 0 )
5674 strlcat(strReturn,
"Advanced Server " ,2048);
5675 snprintf(temp,512,
"%d.%d ", osvi.dwMajorVersion, osvi.dwMinorVersion);
5676 strlcat(strReturn, temp,2048);
5681 if( osvi.dwMajorVersion == 4 &&
5682 lstrcmpi( osvi.szCSDVersion,
"Service Pack 6" ) == 0 )
5688 lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
5689 "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009",
5690 0, KEY_QUERY_VALUE, &hKey );
5691 if( lRet == ERROR_SUCCESS ) {
5692 snprintf(temp, 512,
"Service Pack 6a (Build %d)", osvi.dwBuildNumber & 0xFFFF );
5693 strlcat(strReturn, temp,2048 );
5697 snprintf(temp,512,
"%s (Build %d)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
5698 strlcat(strReturn, temp,2048 );
5701 RegCloseKey( hKey );
5705 snprintf(temp, 512,
"%s (Build %d)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
5706 strlcat(strReturn, temp,2048 );
5712 case VER_PLATFORM_WIN32_WINDOWS:
5714 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
5716 strlcpy(strReturn,
"Microsoft Windows 95 ",2048);
5717 if (osvi.szCSDVersion[1]==
'C' || osvi.szCSDVersion[1]==
'B')
5718 strlcat(strReturn,
"OSR2 " ,2048);
5721 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
5723 strlcpy(strReturn,
"Microsoft Windows 98 ",2048);
5724 if ( osvi.szCSDVersion[1]==
'A' || osvi.szCSDVersion[1]==
'B')
5725 strlcat(strReturn,
"SE ",2048 );
5728 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
5730 strlcpy(strReturn,
"Microsoft Windows Millennium Edition",2048);
5734 case VER_PLATFORM_WIN32s:
5735 strlcpy(strReturn,
"Microsoft Win32s",2048);
5746 unsigned nHighestFeatureEx;
5750 nHighestFeatureEx = (unsigned)nBuff[0];
5752 if (nHighestFeatureEx >= 0x80000006) {
5754 return (((
unsigned)nBuff[2])>>16);
5764 SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
5765 SYSTEM_INFO sysInfo;
5766 MEMORYSTATUSEX statex;
5767 OSVERSIONINFO OsVersionInfo;
5769 char szKeyValueString[80];
5770 DWORD szKeyValueDword;
5775 NtQuerySystemInformation = (
PROCNTQSI)GetProcAddress(
5776 GetModuleHandle(
"ntdll"),
"NtQuerySystemInformation");
5778 if (!NtQuerySystemInformation) {
5780 "Error on GetProcAddress(NtQuerySystemInformation)");
5785 &SysPerfInfo,
sizeof(SysPerfInfo),
5787 OsVersionInfo.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
5788 GetVersionEx(&OsVersionInfo);
5789 GetSystemInfo(&sysInfo);
5790 statex.dwLength =
sizeof(statex);
5791 if (!GlobalMemoryStatusEx(&statex)) {
5792 ::Error(
"GetWinNTSysInfo",
"Error on GlobalMemoryStatusEx()");
5795 sysinfo->
fCpus = sysInfo.dwNumberOfProcessors;
5804 status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"HARDWARE\\DESCRIPTION\\System",
5805 0, KEY_QUERY_VALUE, &hKey);
5806 if (status == ERROR_SUCCESS) {
5807 dwBufLen =
sizeof(szKeyValueString);
5808 RegQueryValueEx(hKey,
"Identifier", NULL, NULL,(LPBYTE)szKeyValueString,
5810 sysinfo->
fModel = szKeyValueString;
5813 status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
5814 "Hardware\\Description\\System\\CentralProcessor\\0",
5815 0, KEY_QUERY_VALUE, &hKey);
5816 if (status == ERROR_SUCCESS) {
5817 dwBufLen =
sizeof(szKeyValueString);
5818 status = RegQueryValueEx(hKey,
"ProcessorNameString", NULL, NULL,
5819 (LPBYTE)szKeyValueString, &dwBufLen);
5820 if (status == ERROR_SUCCESS)
5821 sysinfo->
fCpuType = szKeyValueString;
5822 dwBufLen =
sizeof(DWORD);
5823 status = RegQueryValueEx(hKey,
"~MHz",NULL,NULL,(LPBYTE)&szKeyValueDword,
5825 if ((status == ERROR_SUCCESS) && ((sysinfo->
fCpuSpeed <= 0) ||
5826 (sysinfo->
fCpuSpeed < (szKeyValueDword >> 1))))
5840 SYSTEM_INFO sysInfo;
5841 Float_t idle_ratio, kernel_ratio, user_ratio, total_ratio;
5842 FILETIME ft_sys_idle, ft_sys_kernel, ft_sys_user, ft_fun_time;
5843 SYSTEMTIME st_fun_time;
5845 ULARGE_INTEGER ul_sys_idle, ul_sys_kernel, ul_sys_user;
5846 static ULARGE_INTEGER ul_sys_idleold = {0, 0};
5847 static ULARGE_INTEGER ul_sys_kernelold = {0, 0};
5848 static ULARGE_INTEGER ul_sys_userold = {0, 0};
5849 ULARGE_INTEGER ul_sys_idle_diff, ul_sys_kernel_diff, ul_sys_user_diff;
5851 ULARGE_INTEGER ul_fun_time;
5852 ULARGE_INTEGER ul_fun_timeold = {0, 0};
5853 ULARGE_INTEGER ul_fun_time_diff;
5855 typedef BOOL (__stdcall *GetSystemTimesProc)( LPFILETIME lpIdleTime,
5856 LPFILETIME lpKernelTime, LPFILETIME lpUserTime );
5857 static GetSystemTimesProc pGetSystemTimes = 0;
5859 HMODULE hModImagehlp = LoadLibrary(
"Kernel32.dll" );
5860 if (!hModImagehlp) {
5861 ::Error(
"GetWinNTCpuInfo",
"Error on LoadLibrary(Kernel32.dll)");
5865 pGetSystemTimes = (GetSystemTimesProc) GetProcAddress( hModImagehlp,
5867 if (!pGetSystemTimes) {
5868 ::Error(
"GetWinNTCpuInfo",
"Error on GetProcAddress(GetSystemTimes)");
5871 GetSystemInfo(&sysInfo);
5874 pGetSystemTimes(&ft_sys_idle,&ft_sys_kernel,&ft_sys_user);
5875 GetSystemTime(&st_fun_time);
5876 SystemTimeToFileTime(&st_fun_time,&ft_fun_time);
5878 memcpy(&ul_sys_idle, &ft_sys_idle,
sizeof(FILETIME));
5879 memcpy(&ul_sys_kernel, &ft_sys_kernel,
sizeof(FILETIME));
5880 memcpy(&ul_sys_user, &ft_sys_user,
sizeof(FILETIME));
5881 memcpy(&ul_fun_time, &ft_fun_time,
sizeof(FILETIME));
5883 ul_sys_idle_diff.QuadPart = ul_sys_idle.QuadPart -
5884 ul_sys_idleold.QuadPart;
5885 ul_sys_kernel_diff.QuadPart = ul_sys_kernel.QuadPart -
5886 ul_sys_kernelold.QuadPart;
5887 ul_sys_user_diff.QuadPart = ul_sys_user.QuadPart -
5888 ul_sys_userold.QuadPart;
5890 ul_fun_time_diff.QuadPart = ul_fun_time.QuadPart -
5891 ul_fun_timeold.QuadPart;
5893 ul_sys_idleold.QuadPart = ul_sys_idle.QuadPart;
5894 ul_sys_kernelold.QuadPart = ul_sys_kernel.QuadPart;
5895 ul_sys_userold.QuadPart = ul_sys_user.QuadPart;
5897 if (ul_fun_timeold.QuadPart == 0) {
5899 ul_fun_timeold.QuadPart = ul_fun_time.QuadPart;
5902 ul_fun_timeold.QuadPart = ul_fun_time.QuadPart;
5910 idle_ratio /= (
Float_t)sysInfo.dwNumberOfProcessors;
5911 user_ratio /= (
Float_t)sysInfo.dwNumberOfProcessors;
5912 kernel_ratio /= (
Float_t)sysInfo.dwNumberOfProcessors;
5913 total_ratio = 100.0 - idle_ratio;
5918 cpuinfo->
fUser = user_ratio;
5919 cpuinfo->
fSys = kernel_ratio;
5920 cpuinfo->
fTotal = total_ratio;
5921 cpuinfo->
fIdle = idle_ratio;
5930 MEMORYSTATUSEX statex;
5931 statex.dwLength =
sizeof(statex);
5932 if (!GlobalMemoryStatusEx(&statex)) {
5933 ::Error(
"GetWinNTMemInfo",
"Error on GlobalMemoryStatusEx()");
5936 used = (
Long64_t)(statex.ullTotalPhys - statex.ullAvailPhys);
5937 free = (
Long64_t) statex.ullAvailPhys;
5938 total = (
Long64_t) statex.ullTotalPhys;
5944 swap_total = (
Long64_t)(statex.ullTotalPageFile - statex.ullTotalPhys);
5945 swap_avail = (
Long64_t)(statex.ullAvailPageFile - statex.ullAvailPhys);
5946 swap_used = swap_total - swap_avail;
5959 FILETIME starttime, exittime, kerneltime, usertime;
5960 timeval ru_stime, ru_utime;
5963 typedef BOOL (__stdcall *GetProcessMemoryInfoProc)( HANDLE Process,
5965 static GetProcessMemoryInfoProc pGetProcessMemoryInfo = 0;
5967 HMODULE hModImagehlp = LoadLibrary(
"Psapi.dll" );
5968 if (!hModImagehlp) {
5969 ::Error(
"GetWinNTProcInfo",
"Error on LoadLibrary(Psapi.dll)");
5973 pGetProcessMemoryInfo = (GetProcessMemoryInfoProc) GetProcAddress(
5974 hModImagehlp,
"GetProcessMemoryInfo" );
5975 if (!pGetProcessMemoryInfo) {
5977 "Error on GetProcAddress(GetProcessMemoryInfo)");
5981 if ( pGetProcessMemoryInfo( GetCurrentProcess(), &pmc,
sizeof(pmc)) ) {
5985 if ( GetProcessTimes(GetCurrentProcess(), &starttime, &exittime,
5986 &kerneltime, &usertime)) {
5989 memcpy(&li, &kerneltime,
sizeof(FILETIME));
5991 ru_stime.tv_sec = li.QuadPart / 1000000
L;
5992 ru_stime.tv_usec = li.QuadPart % 1000000
L;
5994 memcpy(&li, &usertime,
sizeof(FILETIME));
5996 ru_utime.tv_sec = li.QuadPart / 1000000
L;
5997 ru_utime.tv_usec = li.QuadPart % 1000000
L;
6000 ((
Float_t)(ru_utime.tv_usec) / 1000000.);
6002 ((
Float_t)(ru_stime.tv_usec) / 1000000.);
6013 if (!info)
return -1;
6025 if (!info)
return -1;
6036 if (!info)
return -1;
6047 if (!info)
return -1;
Int_t GetGid(const char *group=0)
Returns the group's id. If group = 0, returns current user's group.
void DispatchOneEvent(Bool_t pendingOnly=kFALSE)
Dispatch a single event in TApplication::Run() loop.
void(* SigHandler_t)(ESignals)
const TCHAR c_szColonSlash[]
const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists)
Find location of file in a search path.
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
int GetSockOpt(int sock, int opt, int *val)
Get socket option.
FILE * OpenPipe(const char *shellcmd, const char *mode)
Open a pipe.
static void GetWinNTProcInfo(ProcInfo_t *procinfo)
Get process info for this process on Windows NT.
virtual void SetWriteReady()
Int_t GetEffectiveGid()
Returns the effective group id.
static void __cpuid(int *cpuid_data, int)
UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
const char * HomeDirectory(const char *userName=0)
Return the user's home directory.
virtual Bool_t Notify()
Notify when event occurred on descriptor associated with this handler.
int RecvRaw(int sock, void *buffer, int length, int flag)
Receive exactly length bytes into buffer.
const char * HostName()
Return the system's host name.
WIN32_FIND_DATA fFindFileData
virtual Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in 'path' points to the local file system.
void SetDynamicPath(const char *path)
Set the dynamic path to a new value.
const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
R__EXTERN Int_t gErrorIgnoreLevel
static DWORD GetCPUSpeed()
Calculate the CPU clock speed using the 'rdtsc' instruction.
int Link(const char *from, const char *to)
Create a link from file1 to file2.
virtual void StackTrace()
Print a stack trace.
const char * GetError()
Return system error string.
BOOL PathIsUNC(LPCTSTR pszPath)
Returns TRUE if the given string is a UNC path.
Bool_t EqualTo(const char *cs, ECaseCompare cmp=kExact) const
const char * GetLinkedLibraries()
Get list of shared libraries loaded at the start of the executable.
#define INVALID_HANDLE_VALUE
int Unlink(const char *name)
Unlink, i.e. remove, a file or directory.
HANDLE GetProcess()
Get current process handle.
TTime Now()
Get current time in milliseconds since 0:00 Jan 1 1995.
void CloseConnection(int sock, Bool_t force=kFALSE)
Close socket.
std::string GetWorkingDirectory() const
Return the working directory for the default drive.
int CopyFile(const char *from, const char *to, Bool_t overwrite=kFALSE)
Copy a file.
void * _ReturnAddress(void)
const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
image html pict1_TGaxis_012 png width
Define new text attributes for the label number "labNum".
This class represents a WWW compatible URL.
TString & ReplaceAll(const TString &s1, const TString &s2)
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.
std::string GetHomeDirectory(const char *userName=0) const
Return the user's home directory.
const char * GetProtocol() const
static char * GetWindowsVersion()
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
void AddDynamicPath(const char *dir)
Add a new directory to the dynamic path.
TTimer * RemoveTimer(TTimer *ti)
Remove timer from list of system timers.
This class represents an Internet Protocol (IP) address.
virtual int MakeDirectory(const char *name)
Make a directory.
int GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
virtual void AddSignalHandler(TSignalHandler *sh)
Add a signal handler to list of system signal handlers.
Regular expression class.
int Umask(Int_t mask)
Set the process file creation mode mask.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
static constexpr double cm
char * GetServiceByPort(int port)
Get name of internet service.
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
int SendRaw(int sock, const void *buffer, int length, int flag)
Send exactly length bytes from buffer.
TSeqCollection * fSignalHandler
void(WINAPI * PGNSI)(LPSYSTEM_INFO)
void IgnoreSignal(ESignals sig, Bool_t ignore=kTRUE)
If ignore is true ignore the specified signal, else restore previous behaviour.
virtual TTimer * RemoveTimer(TTimer *t)
Remove timer from list of system timers.
Bool_t IsAbsoluteFileName(const char *dir)
Return true if dir is an absolute pathname.
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
void Break(const char *location, const char *msgfmt,...)
Bool_t CheckDescriptors()
Check if there is activity on some file descriptors and call their Notify() member.
const char * DirName(const char *pathname)
Return the directory name in pathname.
static void ThreadStub(void *Parameter)
virtual void ResetReadyMask()
TString & Prepend(const char *cs)
R__EXTERN TApplication * gApplication
Basic time type with millisecond precision.
int ClosePipe(FILE *pipe)
Close the pipe.
Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in 'path' points to the local file system.
Int_t GetEffectiveUid()
Returns the effective user id.
const char * kProtocolName
virtual TFileHandler * RemoveFileHandler(TFileHandler *fh)
Remove a file handler from the list of file handlers.
void NotifyApplicationCreated()
Hook to tell TSystem that the TApplication object has been created.
void SysError(const char *location, const char *msgfmt,...)
virtual Bool_t HandleTermInput()
virtual const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Bool_t DispatchTimers(Bool_t mode)
Handle and dispatch timers.
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
static Int_t GetErrno()
Static function returning system error number.
Int_t GetSysInfo(SysInfo_t *info) const
Returns static system info, like OS type, CPU type, number of CPUs RAM size, etc into the SysInfo_t s...
void Abort(int code=0)
Abort the application.
static int GetL2CacheSize()
Use assembly to retrieve the L2 cache information ...
void AddSignalHandler(TSignalHandler *sh)
Add a signal handler to list of system signal handlers.
virtual Bool_t Notify()
Notify when signal occurs.
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
virtual int Unlink(const char *name)
Unlink, i.e. remove, a file.
Bool_t ChangeDirectory(const char *path)
Change directory.
Int_t GetCpuInfo(CpuInfo_t *info, Int_t sampleTime=1000) const
Returns cpu load average and load info into the CpuInfo_t structure.
static int WinNTUnixConnect(int port)
Connect to a Unix domain socket.
BOOL PathIsRoot(LPCTSTR pPath)
check if a path is a root
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
TSignalHandler * RemoveSignalHandler(TSignalHandler *sh)
Remove a signal handler from list of signal handlers.
Int_t SetFPEMask(Int_t mask=kDefaultMask)
Set which conditions trigger a floating point exception.
int AcceptConnection(int sock)
Accept a connection.
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
static const char * DynamicPath(const char *newpath=0, Bool_t reset=kFALSE)
Get shared library search path. Static utility function.
const char * FindDynamicLibrary(TString &lib, Bool_t quiet=kFALSE)
Returns and updates sLib to the path of a dynamic library (searches for library in the dynamic librar...
int GetPid()
Get process id.
TObject * Next()
Return next object in collection.
R__EXTERN TFileHandler * gXDisplay
Int_t fNfd
Signals that were trapped.
void AddTimer(TTimer *ti)
Add timer to list of system timers.
virtual const char * Getenv(const char *env)
Get environment variable.
TString & Append(const char *cs)
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
static constexpr double L
virtual void ExitLoop()
Exit from event loop.
struct _PROCESS_MEMORY_COUNTERS PROCESS_MEMORY_COUNTERS
Ssiz_t First(char c) const
Find first occurrence of a character c.
const char * WorkingDirectory()
Return the working directory for the default drive.
LONG(WINAPI * PROCNTQSI)(UINT, PVOID, ULONG, PULONG)
int GetServiceByName(const char *service)
Get port # of internet service.
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
int OpenConnection(const char *server, int port, int tcpwindowsize=-1, const char *protocol="tcp")
Open a connection to a service on a server.
void Error(const char *location, const char *msgfmt,...)
const char * GetDynamicPath()
Return the dynamic path (used to find shared libraries).
TSeqCollection * fFileHandler
TString & GetLastErrorString()
Return the thread local storage for the custom last error message.
struct _PROCESS_MEMORY_COUNTERS * PPROCESS_MEMORY_COUNTERS
Bool_t InitUsersGroups()
Collect local users and groups accounts information.
static void SigHandler(ESignals sig)
Unix signal handler.
virtual ~TWinNTSystem()
dtor
int MakeDirectory(const char *name)
Make a WinNT file system directory.
Using a TBrowser one can browse all ROOT objects.
virtual Bool_t WriteNotify()
Notify when something can be written to the descriptor associated with this handler.
const char * GetDirEntry(void *dirp)
Returns the next directory entry.
R__EXTERN const char * gProgName
static int WinNTUdpConnect(const char *hostname, int port)
Creates a UDP socket connection Is called via the TSocket constructor.
Bool_t Init()
Initialize WinNT system interface.
static void sighandler(int sig)
Call the signal handler associated with the signal.
void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
virtual Bool_t HasWriteInterest()
True if handler is interested in write events.
const char * BaseName(const char *name)
Base name of a file name.
Bool_t ProcessEvents()
process pending events, i.e. DispatchOneEvent(kTRUE)
virtual Bool_t Init()
Initialize the OS interface.
R__EXTERN TSystem * gSystem
Int_t GetFPEMask()
Return the bitmap of conditions that trigger a floating point exception.
virtual const char * GetLibraries(const char *regexp="", const char *option="", Bool_t isRegexp=kTRUE)
Return a space separated list of loaded shared libraries.
#define SystemPerformanceInformation
UInt_t GetAddress() const
int ConnectService(const char *servername, int port, int tcpwindowsize, const char *protocol="tcp")
Connect to service servicename on server servername.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
virtual void SetReadReady()
virtual Long_t NextTimeOut(Bool_t mode)
Time when next timer of mode (synchronous=kTRUE or asynchronous=kFALSE) will time-out (in ms)...
void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
#define isin(address, start, length)
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
char * Form(const char *fmt,...)
void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
int Utime(const char *file, Long_t modtime, Long_t actime)
Set a files modification and access times.
ESignals GetSignal() const
void ResetSignal(ESignals sig, Bool_t reset=kTRUE)
If reset is true reset the signal handler for the specified signal to the default handler...
static const char * StripOffProto(const char *path, const char *proto)
struct passwd * fPasswords
const char * UnixPathName(const char *unixpathname)
Convert a pathname to a unix pathname.
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
static void GetWinNTSysInfo(SysInfo_t *sysinfo)
Get system info for Windows NT.
Handles synchronous and a-synchronous timer events.
Bool_t CheckTimer(const TTime &now)
Check if timer timed out.
void DoBeep(Int_t freq=-1, Int_t duration=-1) const
Beep.
void ResetSignals()
Reset signals handlers to previous behaviour.
static void GetWinNTCpuInfo(CpuInfo_t *cpuinfo, Int_t sampleTime)
Get CPU stat for Window.
void DispatchSignals(ESignals sig)
Handle and dispatch signals.
void AddAlias(const char *alias)
Add alias to list of aliases.
virtual void FreeDirectory(void *dirp)
Free a directory.
const char * GetLibraries(const char *regexp="", const char *option="", Bool_t isRegexp=kTRUE)
Return a space separated list of loaded shared libraries.
const char DriveName(const char *pathname="/")
Return the drive letter in pathname.
char * StrDup(const char *str)
Duplicate the string str.
void ExitLoop()
Exit from event loop.
virtual int SetSockOpt(int sock, int kind, int val)
Set socket option.
int Exec(const char *shellcmd)
Execute a command.
UserGroup_t * GetGroupInfo(Int_t gid)
Returns all group info in the UserGroup_t structure.
static unsigned int total
TString & Remove(Ssiz_t pos)
RooCmdArg Index(RooCategory &icat)
int SendBuf(int sock, const void *buffer, int length)
Send a buffer headed by a length indicator.
virtual TSignalHandler * RemoveSignalHandler(TSignalHandler *sh)
Remove a signal handler from list of signal handlers.
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
TFdSet * fReadready
Files that should be checked for write events.
void AddAddress(UInt_t addr)
Add alternative address to list of addresses.
R__EXTERN const char * gProgPath
void Copy(void *source, void *dest)
static const double x1[5]
TString & Swap(TString &other)
int AnnounceTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize=-1)
Announce TCP/IP service.
R__EXTERN TWin32SplashThread * gSplash
Ssiz_t Last(char c) const
Find last occurrence of a character c.
char * DynamicPathName(const char *lib, Bool_t quiet=kFALSE)
Find a dynamic library called lib using the system search paths.
int AnnounceUnixService(int port, int backlog)
Announce unix domain service.
int RecvBuf(int sock, void *buffer, int length)
Receive a buffer headed by a length indicator.
int Chmod(const char *file, UInt_t mode)
Set the file permission bits.
virtual const char * ExpandFileName(const char *fname)
Expand a pathname getting rid of special shell characters like ~.
int AnnounceUdpService(int port, int backlog)
Announce UDP service.
void TimerThread()
Special Thread to check asynchronous timers.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TFdSet * fSignals
Files with writes waiting.
static constexpr double s
void Beep(Int_t freq=-1, Int_t duration=-1, Bool_t setDefault=kFALSE)
Beep for duration milliseconds with a tone of frequency freq.
Bool_t HandleConsoleEvent()
__inline BOOL DBL_BSLASH(LPCTSTR psz)
Inline function to check for a double-backslash at the beginning of a string.
int Symlink(const char *from, const char *to)
Create a symlink from file1 to file2.
void Gl_setwidth(int width)
void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
void FillWithHomeDirectory(const char *userName, char *mydir) const
Fill buffer with user's home directory.
int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
TInetAddress GetPeerName(int sock)
Get Internet Protocol (IP) address of remote host and port #.
TFileHandler * RemoveFileHandler(TFileHandler *fh)
Remove a file handler from the list of file handlers.
Bool_t ExpandPathName(TString &patbuf)
Expand a pathname getting rid of special shell characaters like ~.$, etc.
Binding & operator=(OUT(*fun)(void))
void Throw(int code)
If an exception context has been set (using the TRY and RETRY macros) jump back to where it was set...
void FreeDirectory(void *dirp)
Close a WinNT file system directory.
Int_t Select(TList *active, Long_t timeout)
Select on file descriptors. The timeout to is in millisec.
int SetSockOpt(int sock, int opt, int val)
Set socket option.
TInetAddress GetSockName(int sock)
Get Internet Protocol (IP) address of host and port #.
typedef void((*Func_t)())
Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
Bool_t CountMembers(const char *lpszGroupName)
Bool_t(* ThreadMsgFunc_t)(MSG *)
Int_t GetUid(const char *user=0)
Returns the user's id. If user = 0, returns current user's id.
virtual void Add(TObject *obj)
static const TString & GetLibDir()
Get the library directory in the installation. Static utility function.
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
R__EXTERN const char * gRootDir
Int_t GetProcInfo(ProcInfo_t *info) const
Returns cpu and memory used by this process into the ProcInfo_t structure.
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
int SetNonBlock(int fd)
Make descriptor fd non-blocking.
int GetFsInfo(const char *path, Long_t *id, Long_t *bsize, Long_t *blocks, Long_t *bfree)
Get info about a file system: id, bsize, bfree, blocks.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
FILE * TempFileName(TString &base, const char *dir=0)
Create a secure temporary file by appending a unique 6 letter string to base.
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.
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Iterator of ordered collection.
virtual Bool_t ReadNotify()
Notify when something can be read from the descriptor associated with this handler.
Bool_t CollectMembers(const char *lpszGroupName, int &groupIdx, int &memberIdx)
TSystem * FindHelper(const char *path, void *dirptr=0)
Create helper TSystem to handle file and directory operations that might be special for remote file a...
virtual void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
static void ResetErrno()
Static function resetting system error number.
static const TString & GetBinDir()
Get the binary directory in the installation. Static utility function.
void SetProgname(const char *name)
Set the application name (from command line, argv[0]) and copy it in gProgName.
Bool_t CheckSignals(Bool_t sync)
Check if some signals were raised and call their Notify() member.
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
void Setenv(const char *name, const char *value)
Set environment variable.
TFdSet * fWriteready
Files with reads waiting.
TList * GetVolumes(Option_t *opt="") const
Get list of volumes (drives) mounted on the system.
static void GetWinNTMemInfo(MemInfo_t *meminfo)
Get VM stat for Windows NT.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Abstract base class defining a generic interface to the underlying Operating System.
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
TFdSet * fWritemask
Files that should be checked for read events.
Int_t GetMemInfo(MemInfo_t *info) const
Returns ram and swap memory usage info into the MemInfo_t structure.
void StackTrace()
Print a stack trace, if gEnv entry "Root.Stacktrace" is unset or 1, and if the image helper functions...
const char * Getenv(const char *name)
Get environment variable.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
void SetGUIThreadMsgHandler(ThreadMsgFunc_t func)
Set the (static part of) the event handler func for GUI messages.
Int_t RedirectOutput(const char *name, const char *mode="a", RedirectHandle_t *h=0)
Redirect standard output (stdout, stderr) to the specified file.
int Rename(const char *from, const char *to)
Rename a file. Returns 0 when successful, -1 in case of failure.
virtual Bool_t HasReadInterest()
True if handler is interested in read events.
const char * Data() const