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);
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";
826 ::RegCloseKey(regROOT);
827 ::RegCloseKey(regCUSC);
828 ::RegCloseKey(regCUS);
832 static const char apptitle[] =
"ROOT data file";
833 ::RegSetValueEx(regROOT,
NULL, 0, REG_SZ, (BYTE*)apptitle,
sizeof(apptitle));
834 DWORD editflags = 0x00010000;
835 ::RegSetValueEx(regROOT,
"EditFlags", 0, REG_DWORD, (BYTE*)&editflags,
sizeof(editflags));
838 if (::RegCreateKeyEx(regROOT,
"DefaultIcon", 0,
NULL, 0, KEY_READ | KEY_WRITE,
839 NULL, ®ROOTIcon,
NULL) == ERROR_SUCCESS) {
842 ::RegSetValueEx(regROOTIcon,
NULL, 0, REG_SZ, (BYTE*)iconloc.
Data(), iconloc.
Length() + 1);
843 ::RegCloseKey(regROOTIcon);
848 if (::RegCreateKeyEx(regROOT,
"shell", 0,
NULL, 0, KEY_READ | KEY_WRITE,
849 NULL, ®ROOTshell,
NULL) == ERROR_SUCCESS) {
851 if (::RegCreateKeyEx(regROOTshell,
"open", 0,
NULL, 0, KEY_READ | KEY_WRITE,
852 NULL, ®ShellOpen,
NULL) == ERROR_SUCCESS) {
853 HKEY regShellOpenCmd;
854 if (::RegCreateKeyEx(regShellOpen,
"command", 0,
NULL, 0, KEY_READ | KEY_WRITE,
855 NULL, ®ShellOpenCmd,
NULL) == ERROR_SUCCESS) {
857 cmd +=
" -l \"%1\" \"";
860 ::RegSetValueEx(regShellOpenCmd,
NULL, 0, REG_SZ, (BYTE*)cmd.
Data(), cmd.
Length() + 1);
861 ::RegCloseKey(regShellOpenCmd);
863 ::RegCloseKey(regShellOpen);
865 ::RegCloseKey(regROOTshell);
867 ::RegCloseKey(regROOT);
869 if (::RegCreateKeyEx(regCUSC,
".root", 0,
NULL, 0, KEY_READ | KEY_WRITE,
870 NULL, ®ROOT,
NULL) == ERROR_SUCCESS) {
871 static const char appname[] =
"ROOTDEV.ROOT";
872 ::RegSetValueEx(regROOT,
NULL, 0, REG_SZ, (BYTE*)appname,
sizeof(appname));
874 ::RegCloseKey(regCUSC);
875 ::RegCloseKey(regCUS);
878 ::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST,
NULL,
NULL);
886 static bool once =
true;
889 if ((arg !=
"root") && (arg !=
"rootn") &&
890 (arg !=
"root.exe") && (arg !=
"rootn.exe"))
return false;
894 if ((arg ==
"-l") || (arg ==
"-b")) {
907 static void SetConsoleWindowName()
909 char pszNewWindowTitle[1024];
910 char pszOldWindowTitle[1024];
912 CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
914 if (!::GetConsoleTitle(pszOldWindowTitle, 1024))
917 wsprintf(pszNewWindowTitle,
"%d/%d", ::GetTickCount(), ::GetCurrentProcessId());
919 if (!::SetConsoleTitle(pszNewWindowTitle))
929 ::SetConsoleTitle(
"ROOT session");
931 hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
932 ::SetConsoleMode(hStdout, ENABLE_PROCESSED_OUTPUT |
933 ENABLE_WRAP_AT_EOL_OUTPUT);
934 if (!::GetConsoleScreenBufferInfo(hStdout, &csbiInfo))
953 TIter next(fSignalHandler);
971 fGUIThreadHandle(0), fGUIThreadId(0)
979 if (initwinsock = ::WSAStartup(MAKEWORD(2, 0), &WSAData)) {
980 Error(
"TWinNTSystem()",
"Starting sockets failed");
991 char *buf =
new char[MAX_MODULE_NAME32 + 1];
997 HMODULE hModCore = ::GetModuleHandle(
"libCore.dll");
999 ::GetModuleFileName(hModCore, buf, MAX_MODULE_NAME32 + 1);
1000 char *pLibName = strstr(buf,
"libCore.dll");
1003 while (--pLibName >= buf && *pLibName !=
'\\' && *pLibName !=
'/');
1006 check_path +=
"\\etc";
1008 while (buf[0] && GetFileAttributes(check_path.
Data()) == INVALID_FILE_ATTRIBUTES) {
1009 while (--pLibName >= buf && *pLibName !=
'\\' && *pLibName !=
'/');
1012 check_path +=
"\\etc";
1027 UpdateRegistry(
this, buf);
1038 typedef UINT (WINAPI* LPTIMEENDPERIOD)( UINT uPeriod );
1039 HINSTANCE hInstWinMM = LoadLibrary(
"winmm.dll" );
1041 LPTIMEENDPERIOD pTimeEndPeriod = (LPTIMEENDPERIOD)GetProcAddress( hInstWinMM,
"timeEndPeriod" );
1042 if(
NULL != pTimeEndPeriod )
1044 FreeLibrary(hInstWinMM);
1055 ::ResetEvent(gGlobalEvent);
1056 ::CloseHandle(gGlobalEvent);
1059 if (gTimerThreadHandle) {
1060 ::TerminateThread(gTimerThreadHandle, 0);
1061 ::CloseHandle(gTimerThreadHandle);
1070 const char *dir = 0;
1098 ::SetUnhandledExceptionFilter(ExceptionFilter);
1103 static char lpFilename[MAX_PATH];
1104 if (::GetModuleFileName(
1107 sizeof(lpFilename))) {
1115 typedef UINT (WINAPI* LPTIMEBEGINPERIOD)( UINT uPeriod );
1116 HINSTANCE hInstWinMM = LoadLibrary(
"winmm.dll" );
1118 LPTIMEBEGINPERIOD pTimeBeginPeriod = (LPTIMEBEGINPERIOD)GetProcAddress( hInstWinMM,
"timeBeginPeriod" );
1119 if(
NULL != pTimeBeginPeriod )
1120 pTimeBeginPeriod(1);
1121 FreeLibrary(hInstWinMM);
1129 char *buf =
new char[MAX_MODULE_NAME32 + 1];
1130 HMODULE hModCore = ::GetModuleHandle(
"libCore.dll");
1132 ::GetModuleFileName(hModCore, buf, MAX_MODULE_NAME32 + 1);
1133 char *pLibName = strstr(buf,
"libCore.dll");
1140 SetConsoleWindowName();
1164 const char *symbol=
name;
1167 while ( (*symbol ==
' ' || *symbol ==
'\t') && *symbol) symbol++;
1170 if (isalpha(symbol[idx]) && symbol[idx+1] ==
':') idx = 2;
1171 if ( (symbol[idx] ==
'/' || symbol[idx] ==
'\\') && symbol[idx+1] ==
'\0') {
1176 Error(
"BaseName",
"name = 0");
1180 char *bslash = (
char *)strrchr(&symbol[idx],
'\\');
1181 char *rslash = (
char *)strrchr(&symbol[idx],
'/');
1182 if (cp = std::max(rslash, bslash)) {
1187 return &symbol[idx];
1189 Error(
"BaseName",
"name = 0");
1205 ULong_t namelen=name ? strlen(name) : 0;
1206 if (name && namelen > 0) {
1208 fullname =
new char[namelen+5];
1209 strlcpy(fullname, name,namelen+5);
1210 if ( !strrchr(fullname,
'.') )
1211 strlcat(fullname,
".exe",namelen+5);
1214 dot = strrchr(progname,
'.');
1215 idot = dot ? (
ULong_t)(dot - progname) : strlen(progname);
1220 which =
StrDup(fullname);
1228 const char *d =
DirName(which);
1231 dirname.
Form(
"%c:%s", driveletter, d);
1233 dirname.
Form(
"%s", d);
1246 progname[idot] =
'\0';
1248 if (which)
delete [] which;
1252 if (::NeedSplash()) {
1265 if (err < 0 || err >= sys_nerr) {
1267 error_msg.
Form(
"errno out of range %d", err);
1270 return sys_errlist[err];
1283 DWORD il =
sizeof(hn);
1284 ::GetComputerName(hn, &il);
1300 if (freq < 37) freq = 440;
1301 if (duration < 0) duration = 100;
1310 gGUIThreadMsgFunc =
func;
1333 int fd = h->
GetFd();
1371 set_console =
kTRUE;
1384 ::SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleSigHandler,
TRUE);
1410 ::SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleSigHandler,
FALSE);
1454 HANDLE snapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,::GetCurrentProcessId());
1459 if (!InitImagehlpFunctions()) {
1460 std::cerr <<
"No stack trace: cannot find (functions in) dbghelp.dll!" << std::endl;
1465 SYSTEM_INFO sysInfo;
1466 ::GetSystemInfo(&sysInfo);
1467 DWORD machineType = IMAGE_FILE_MACHINE_I386;
1468 switch (sysInfo.wProcessorArchitecture) {
1469 case PROCESSOR_ARCHITECTURE_AMD64:
1470 machineType = IMAGE_FILE_MACHINE_AMD64;
1472 case PROCESSOR_ARCHITECTURE_IA64:
1473 machineType = IMAGE_FILE_MACHINE_IA64;
1477 DWORD currentThreadID = ::GetCurrentThreadId();
1478 DWORD currentProcessID = ::GetCurrentProcessId();
1482 THREADENTRY32 threadentry;
1483 threadentry.dwSize =
sizeof(THREADENTRY32);
1484 if (!::Thread32First(snapshot, &threadentry))
return;
1486 std::cerr << std::endl <<
"==========================================" << std::endl;
1487 std::cerr <<
"=============== STACKTRACE ===============" << std::endl;
1488 std::cerr <<
"==========================================" << std::endl << std::endl;
1491 if (threadentry.th32OwnerProcessID != currentProcessID)
1493 HANDLE thread = ::OpenThread(THREAD_GET_CONTEXT|THREAD_SUSPEND_RESUME|THREAD_QUERY_INFORMATION,
1494 FALSE, threadentry.th32ThreadID);
1496 memset(&context, 0,
sizeof(CONTEXT));
1498 if (threadentry.th32ThreadID != currentThreadID) {
1499 ::SuspendThread(thread);
1500 context.ContextFlags = CONTEXT_ALL;
1501 ::GetThreadContext(thread, &context);
1502 ::ResumeThread(thread);
1504 if (fgXcptContext) {
1505 context = *fgXcptContext;
1507 typedef void (WINAPI *RTLCCTXT)(PCONTEXT);
1508 RTLCCTXT p2RtlCCtxt = (RTLCCTXT) ::GetProcAddress(
1509 GetModuleHandle(
"kernel32.dll"),
"RtlCaptureContext");
1511 context.ContextFlags = CONTEXT_ALL;
1512 p2RtlCCtxt(&context);
1518 ::ZeroMemory(&frame,
sizeof(frame));
1520 frame.AddrPC.Mode = AddrModeFlat;
1521 frame.AddrFrame.Mode = AddrModeFlat;
1522 frame.AddrStack.Mode = AddrModeFlat;
1523 #if defined(_M_IX86) 1524 frame.AddrPC.Offset = context.Eip;
1525 frame.AddrFrame.Offset = context.Ebp;
1526 frame.AddrStack.Offset = context.Esp;
1527 #elif defined(_M_X64) 1528 frame.AddrPC.Offset = context.Rip;
1529 frame.AddrFrame.Offset = context.Rsp;
1530 frame.AddrStack.Offset = context.Rsp;
1531 #elif defined(_M_IA64) 1532 frame.AddrPC.Offset = context.StIIP;
1533 frame.AddrFrame.Offset = context.IntSp;
1534 frame.AddrStack.Offset = context.IntSp;
1535 frame.AddrBStore.Offset= context.RsBSP;
1537 std::cerr <<
"Stack traces not supported on your architecture yet." << std::endl;
1542 while (_StackWalk64(machineType, (HANDLE)::GetCurrentProcess(), thread, (LPSTACKFRAME64)&frame,
1543 (LPVOID)&context, (PREAD_PROCESS_MEMORY_ROUTINE)
NULL, (PFUNCTION_TABLE_ACCESS_ROUTINE)_SymFunctionTableAccess64,
1544 (PGET_MODULE_BASE_ROUTINE)_SymGetModuleBase64, NULL)) {
1546 std::cerr << std::endl <<
"================ Thread " << iThread++ <<
" ================" << std::endl;
1547 if (!bFirst || threadentry.th32ThreadID != currentThreadID) {
1548 const std::string moduleName = GetModuleName(frame.AddrPC.Offset);
1549 const std::string functionName = GetFunctionName(frame.AddrPC.Offset);
1550 std::cerr <<
" " << moduleName << functionName << std::endl;
1554 ::CloseHandle(thread);
1555 }
while (::Thread32Next(snapshot, &threadentry));
1557 std::cerr << std::endl <<
"==========================================" << std::endl;
1558 std::cerr <<
"============= END STACKTRACE =============" << std::endl;
1559 std::cerr <<
"==========================================" << std::endl << std::endl;
1560 ::CloseHandle(snapshot);
1561 _SymCleanup(GetCurrentProcess());
1570 UInt_t oldmask = _statusfp( );
1572 if (oldmask & _EM_INVALID ) mask |=
kInvalid;
1573 if (oldmask & _EM_ZERODIVIDE) mask |=
kDivByZero;
1574 if (oldmask & _EM_OVERFLOW ) mask |=
kOverflow;
1575 if (oldmask & _EM_UNDERFLOW) mask |=
kUnderflow;
1576 if (oldmask & _EM_INEXACT ) mask |=
kInexact;
1590 if (mask &
kInvalid ) newm |= _EM_INVALID;
1591 if (mask &
kDivByZero) newm |= _EM_ZERODIVIDE;
1592 if (mask &
kOverflow ) newm |= _EM_OVERFLOW;
1593 if (mask &
kUnderflow) newm |= _EM_UNDERFLOW;
1594 if (mask &
kInexact ) newm |= _EM_INEXACT;
1596 UInt_t cm = ::_statusfp();
1598 ::_controlfp(cm , _MCW_EM);
1617 if (pendingOnly && gGlobalEvent) ::SetEvent(gGlobalEvent);
1619 Bool_t pollOnce = pendingOnly;
1623 if (
gROOT->GetApplication()) {
1639 ::WaitForSingleObject(gGlobalEvent, 1);
1640 ::ResetEvent(gGlobalEvent);
1666 if (pendingOnly && !pollOnce)
1705 if (!pendingOnly && gGlobalEvent) {
1706 ::WaitForSingleObject(gGlobalEvent, 1);
1707 ::ResetEvent(gGlobalEvent);
1721 for (i = 0; i <
fReadmask->GetCount(); i++) {
1726 rc = WinNTSelect(&t, 0, 0);
1727 if (rc < 0 && rc != -2) {
1728 ::SysError(
"DispatchOneEvent",
"select: read error on %d\n", fd);
1734 for (i = 0; i <
fWritemask->GetCount(); i++) {
1740 rc = WinNTSelect(0, &t, 0);
1741 if (rc < 0 && rc != -2) {
1742 ::SysError(
"DispatchOneEvent",
"select: write error on %d\n", fd);
1794 if (sync == sh->
IsSync()) {
1796 if ((
fSignals->IsSet(sig) && sigdone == -1) || sigdone == sig) {
1797 if (sigdone == -1) {
1807 if (sigdone != -1)
return kTRUE;
1828 if ((
fReadready->IsSet(fd) && fddone == -1) ||
1829 (fddone == fd && read)) {
1839 (fddone == fd && !read)) {
1849 if (fddone != -1)
return kTRUE;
1866 if (dirname.
Length() == 0) {
1875 const char driveletter =
DriveName(name);
1883 if (res)
return res;
1903 const char *
proto = (strstr(name,
"file:///")) ?
"file://" :
"file:";
1906 if (!name)
return 0;
1910 if (!name)
return 0;
1942 HANDLE searchFile = (HANDLE)dirp;
1976 return (psz[0] == TEXT(
'\\') && psz[1] == TEXT(
'\\'));
1996 #pragma data_seg(".text", "CODE") 2011 if (!IsDBCSLeadByte(*pPath)) {
2016 if ((*pPath == TEXT(
'\\')) && (*(pPath + 1) == 0))
2022 int cBackslashes = 0;
2023 for (p = pPath + 2; *p; p = CharNext(p)) {
2024 if (*p == TEXT(
'\\') && (++cBackslashes > 1))
2044 const char *
proto = (strstr(fdir,
"file:///")) ?
"file://" :
"file:";
2047 char *dir =
new char[MAX_PATH];
2048 if (IsShortcut(sdir)) {
2049 if (!ResolveShortCut(sdir, dir, MAX_PATH))
2050 strlcpy(dir, sdir,MAX_PATH);
2053 strlcpy(dir, sdir,MAX_PATH);
2055 int nche = strlen(dir)+3;
2056 char *entry =
new char[nche];
2057 struct _stati64 finfo;
2060 strlcpy(entry, dir,nche);
2061 if ((entry[strlen(dir)-1] ==
'/') || (entry[strlen(dir)-1] ==
'\\' )) {
2062 entry[strlen(dir)-1] =
'\0';
2065 strlcat(entry,
"\\",nche);
2067 if (_stati64(entry, &finfo) < 0) {
2074 strlcpy(entry, dir,nche);
2075 if ((entry[strlen(dir)-1] ==
'/') || (entry[strlen(dir)-1] ==
'\\' )) {
2077 entry[strlen(dir)-1] =
'\0';
2079 if (_stati64(entry, &finfo) < 0) {
2086 if (finfo.st_mode & S_IFDIR) {
2087 strlcpy(entry, dir,nche);
2088 if (!(entry[strlen(dir)-1] ==
'/' || entry[strlen(dir)-1] ==
'\\' )) {
2089 strlcat(entry,
"\\",nche);
2091 strlcat(entry,
"*",nche);
2160 char drive = driveletter ? toupper( driveletter ) -
'A' + 1 : 0;
2166 if (!(wdpath = ::_getdcwd( (
int)drive, wdpath,
kMAXPATHLEN))) {
2168 Warning(
"WorkingDirectory",
"getcwd() failed");
2192 return std::string(mydir);
2201 if (!(h = ::getenv(
"home"))) h = ::getenv(
"HOME");
2208 h = ::getenv(
"HOMESHARE");
2209 if (!h) h = ::getenv(
"HOMEDRIVE");
2212 h = ::getenv(
"HOMEPATH");
2217 h = ::getenv(
"USERPROFILE");
2222 if (mydir[1] ==
':')
2223 mydir[0] = toupper(mydir[0]);
2240 if (!dir) dir =
"c:\\";
2256 char tmpName[MAX_PATH];
2260 FILE *fp = fopen(tmpName,
"w+");
2262 if (!fp)
::SysError(
"TempFileName",
"error opening %s", tmpName);
2280 if (!opt || !opt[0]) {
2285 UINT nOldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS);
2289 curdrive = _getdrive();
2290 if (strstr(opt,
"cur")) {
2292 sDrive.
Form(
"%c:", (curdrive +
'A' - 1));
2293 sType.
Form(
"Unknown Drive (%s)", sDrive.
Data());
2295 NULL, (LPSTR)szFs, 32);
2296 type = ::GetDriveType(sDrive.
Data());
2299 case DRIVE_NO_ROOT_DIR:
2301 case DRIVE_REMOVABLE:
2302 sType.
Form(
"Removable Disk (%s)", sDrive.
Data());
2305 sType.
Form(
"Local Disk (%s)", sDrive.
Data());
2308 sType.
Form(
"Network Drive (%s) (%s)", szFs, sDrive.
Data());
2311 sType.
Form(
"CD/DVD Drive (%s)", sDrive.
Data());
2314 sType.
Form(
"RAM Disk (%s)", sDrive.
Data());
2319 else if (strstr(opt,
"all")) {
2322 if (::GetLogicalDriveStrings(511, szTemp)) {
2323 TCHAR szDrive[3] = TEXT(
" :");
2329 sDrive.
Form(
"%s", szDrive);
2331 if ((sDrive ==
"A:") || (sDrive ==
"B:")) {
2335 sType.
Form(
"Unknown Drive (%s)", sDrive.
Data());
2338 type = ::GetDriveType(sDrive.
Data());
2341 case DRIVE_NO_ROOT_DIR:
2343 case DRIVE_REMOVABLE:
2344 sType.
Form(
"Removable Disk (%s)", sDrive.
Data());
2347 sType.
Form(
"Local Disk (%s)", sDrive.
Data());
2350 sType.
Form(
"Network Drive (%s) (%s)", szFs, sDrive.
Data());
2353 sType.
Form(
"CD/DVD Drive (%s)", sDrive.
Data());
2356 sType.
Form(
"RAM Disk (%s)", sDrive.
Data());
2366 ::SetErrorMode(nOldErrorMode);
2385 if (strchr(pathname,
'/') || strchr(pathname,
'\\')) {
2386 const char *rslash = strrchr(pathname,
'/');
2387 const char *bslash = strrchr(pathname,
'\\');
2388 const char *
r = std::max(rslash, bslash);
2389 const char *ptr = pathname;
2399 int len = r - pathname;
2430 if (!pathname)
return 0;
2431 if (!pathname[0])
return 0;
2437 while(*lpchar ==
' ') lpchar++;
2439 if (isalpha((
int)*lpchar) && *(lpchar+1) ==
':') {
2443 if ( (*lpchar ==
'\\' || *lpchar ==
'/' ) &&
2444 (*(lpchar+1) ==
'\\' || *(lpchar+1) ==
'/') )
return 0;
2457 if (strchr(dir,
':')) idx = 2;
2458 return (dir[idx] ==
'/' || dir[idx] ==
'\\');
2491 static char temp[1024];
2492 strlcpy(temp, name,1024);
2493 char *currentChar = temp;
2495 while (*currentChar !=
'\0') {
2496 if (*currentChar ==
'\\') *currentChar =
'/';
2514 UINT nOldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS);
2518 const char *
proto = (strstr(path,
"file:///")) ?
"file://" :
"file:";
2521 ::SetErrorMode(nOldErrorMode);
2526 ::SetErrorMode(nOldErrorMode);
2548 if (name ==
".") name =
"";
2549 if (dir && dir[0]) {
2551 char last = dir[strlen(dir) - 1];
2552 if (last !=
'/' && last !=
'\\') {
2573 if (!ret)
return -1;
2582 int ret = ::rename(f, t);
2599 struct _stati64 sbuf;
2602 const char *
proto = (strstr(path,
"file:///")) ?
"file://" :
"file:";
2604 int l = strlen(newpath);
2606 if (newpath[--l] !=
'\\' || newpath[--l] !=
'/') {
2612 if (newpath && ::_stati64(newpath, &sbuf) >= 0) {
2614 buf.
fDev = sbuf.st_dev;
2615 buf.
fIno = sbuf.st_ino;
2616 buf.
fMode = sbuf.st_mode;
2617 buf.
fUid = sbuf.st_uid;
2618 buf.
fGid = sbuf.st_gid;
2619 buf.
fSize = sbuf.st_size;
2620 buf.
fMtime = sbuf.st_mtime;
2621 buf.
fIsLink = IsShortcut(newpath);
2623 char *lpath =
new char[MAX_PATH];
2624 if (IsShortcut(newpath)) {
2625 struct _stati64 sbuf2;
2626 if (ResolveShortCut(newpath, lpath, MAX_PATH)) {
2627 if (::_stati64(lpath, &sbuf2) >= 0) {
2628 buf.
fMode = sbuf2.st_mode;
2654 LPCTSTR lpRootPathName = path;
2657 LPTSTR lpVolumeNameBuffer = 0;
2658 DWORD nVolumeNameSize = 0;
2660 DWORD volumeSerialNumber;
2661 DWORD maximumComponentLength;
2664 DWORD fileSystemFlags;
2667 char fileSystemNameBuffer[512];
2668 DWORD nFileSystemNameSize =
sizeof(fileSystemNameBuffer);
2671 UINT nOldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS);
2672 if (!::GetVolumeInformation(lpRootPathName,
2673 lpVolumeNameBuffer, nVolumeNameSize,
2674 &volumeSerialNumber,
2675 &maximumComponentLength,
2677 fileSystemNameBuffer, nFileSystemNameSize)) {
2679 ::SetErrorMode(nOldErrorMode);
2683 const char *fsNames[] = {
"FAT",
"NTFS" };
2685 for (i = 0; i < 2; i++) {
2686 if (!strncmp(fileSystemNameBuffer, fsNames[i], nFileSystemNameSize))
2691 DWORD sectorsPerCluster;
2692 DWORD bytesPerSector;
2693 DWORD numberOfFreeClusters;
2694 DWORD totalNumberOfClusters;
2696 if (!::GetDiskFreeSpace(lpRootPathName,
2699 &numberOfFreeClusters,
2700 &totalNumberOfClusters)) {
2702 ::SetErrorMode(nOldErrorMode);
2706 ::SetErrorMode(nOldErrorMode);
2708 *bsize = sectorsPerCluster * bytesPerSector;
2709 *blocks = totalNumberOfClusters;
2710 *bfree = numberOfFreeClusters;
2720 struct _stati64 finfo;
2725 char linkname[1024];
2726 LPTSTR lpszFilePart;
2727 TCHAR szPath[MAX_PATH];
2730 typedef BOOL (__stdcall *CREATEHARDLINKPROC)( LPCTSTR, LPCTSTR, LPSECURITY_ATTRIBUTES );
2731 static CREATEHARDLINKPROC _CreateHardLink = 0;
2733 HMODULE hModImagehlp = LoadLibrary(
"Kernel32.dll" );
2738 _CreateHardLink = (CREATEHARDLINKPROC) GetProcAddress( hModImagehlp,
"CreateHardLinkW" );
2740 _CreateHardLink = (CREATEHARDLINKPROC) GetProcAddress( hModImagehlp,
"CreateHardLinkA" );
2742 if (!_CreateHardLink)
2745 dwRet = GetFullPathName(from,
sizeof(szPath) /
sizeof(TCHAR),
2746 szPath, &lpszFilePart);
2748 if (_stati64(szPath, &finfo) < 0)
2751 if (finfo.st_mode & S_IFDIR)
2755 _splitpath(linkname,winDrive,winDir,winName,winExt);
2756 if ((!winDrive[0] ) &&
2758 _splitpath(szPath,winDrive,winDir,winName,winExt);
2759 snprintf(linkname,1024,
"%s\\%s\\%s", winDrive, winDir, to);
2761 else if (!winDrive[0]) {
2762 _splitpath(szPath,winDrive,winDir,winName,winExt);
2763 snprintf(linkname,1024,
"%s\\%s", winDrive, to);
2766 if (!_CreateHardLink(linkname, szPath,
NULL))
2779 IShellLink* pShellLink;
2780 IPersistFile* pPersistFile;
2781 WCHAR wszLinkfile[MAX_PATH];
2782 int iWideCharsWritten;
2784 LPTSTR lpszFilePart;
2785 TCHAR szPath[MAX_PATH];
2787 hRes = E_INVALIDARG;
2788 if ((from ==
NULL) || (!from[0]) || (to ==
NULL) ||
2794 typedef HRESULT (__stdcall *COINITIALIZEPROC)( LPVOID );
2795 static COINITIALIZEPROC _CoInitialize = 0;
2796 typedef void (__stdcall *COUNINITIALIZEPROC)(
void );
2797 static COUNINITIALIZEPROC _CoUninitialize = 0;
2798 typedef HRESULT (__stdcall *COCREATEINSTANCEPROC)( REFCLSID, LPUNKNOWN, DWORD, REFIID, LPVOID );
2799 static COCREATEINSTANCEPROC _CoCreateInstance = 0;
2801 HMODULE hModImagehlp = LoadLibrary(
"ole32.dll" );
2805 _CoInitialize = (COINITIALIZEPROC) GetProcAddress( hModImagehlp,
"CoInitialize" );
2808 _CoUninitialize = (COUNINITIALIZEPROC) GetProcAddress( hModImagehlp,
"CoUninitialize" );
2809 if (!_CoUninitialize)
2811 _CoCreateInstance = (COCREATEINSTANCEPROC) GetProcAddress( hModImagehlp,
"CoCreateInstance" );
2812 if (!_CoCreateInstance)
2819 _CoInitialize(
NULL);
2822 dwRet = GetFullPathName(from,
sizeof(szPath) /
sizeof(TCHAR),
2823 szPath, &lpszFilePart);
2824 hRes = _CoCreateInstance(CLSID_ShellLink,
NULL, CLSCTX_INPROC_SERVER,
2825 IID_IShellLink, (LPVOID *)&pShellLink);
2826 if (SUCCEEDED(hRes)) {
2828 hRes = pShellLink->SetPath(szPath);
2830 hRes = pShellLink->QueryInterface(IID_IPersistFile, (
void **)&pPersistFile);
2831 if (SUCCEEDED(hRes)){
2832 iWideCharsWritten = MultiByteToWideChar(CP_ACP, 0, linkname.
Data(), -1,
2833 wszLinkfile, MAX_PATH);
2834 hRes = pPersistFile->Save(wszLinkfile,
TRUE);
2835 pPersistFile->Release();
2837 pShellLink->Release();
2850 return helper->
Unlink(name);
2852 struct _stati64 finfo;
2854 if (_stati64(name, &finfo) < 0) {
2858 if (finfo.st_mode & S_IFDIR) {
2859 return ::_rmdir(name);
2861 return ::_unlink(name);
2870 if (::ioctlsocket(fd, FIONBIO, (u_long *)1) == SOCKET_ERROR) {
2889 const char *patbuf = (
const char *)patbuf0;
2907 while (*patbuf ==
' ') {
2912 while (*patbuf ==
':') {
2917 while (*patbuf ==
';') {
2923 for (q = (
char*)patbuf; *
q; q++) {
2927 if ( (((q-2)>patbuf) && ( (*(q-2)!=
';') || !isalpha(*(q-1)) )) &&
2934 for (p = patbuf; *p; p++) {
2951 char replacement[4];
2954 for (
int k = 0; k<3; k++) replacement[k] = 0
x1;
2956 replacement[3] = 0x0;
2960 while ( (pos = patbuf0.
Index(TildaNum,pos)) !=
kNPOS ) {
2961 patbuf0.
Replace(pos, 1, replacement);
2967 Int_t lbuf = ::ExpandEnvironmentStrings(
2973 cmd =
new char[lbuf+1];
2974 ::ExpandEnvironmentStrings(
2993 char newpath[MAX_PATH];
2994 if (IsShortcut(path)) {
2995 if (!ResolveShortCut(path, newpath, MAX_PATH))
2996 strlcpy(newpath, path, MAX_PATH);
2999 strlcpy(newpath, path, MAX_PATH);
3014 return ::_chmod(file, mode);
3022 return ::umask(mask);
3032 Error(
"Utime",
"need write permission for %s to change utime", file);
3035 if (!actime) actime = modtime;
3038 t.actime = (time_t)actime;
3039 t.modtime = (time_t)modtime;
3040 return ::utime(file, &t);
3059 return infile.
Data();
3067 Int_t lastDelim = -1;
3068 for(
int i=0; i < exsearch.
Length(); ++i) {
3069 switch( exsearch[i] ) {
3072 if (i-lastDelim!=2) exsearch[i] =
';';
3075 case ';': lastDelim = i;
break;
3082 char *lpFilePart = 0;
3084 ::access(name, mode) == 0 && stat(name, &finfo) == 0 &&
3085 finfo.st_mode & S_IFREG) {
3087 Printf(
"Which: %s = %s", infile, name);
3090 return infile.
Data();
3104 if ((
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) && (::GetVersion() < 0x80000000)) {
3107 HINSTANCE netapi = ::LoadLibrary(
"netapi32.DLL");
3108 if (!netapi)
return kFALSE;
3110 p2NetApiBufferFree = (pfn1)::GetProcAddress(netapi,
"NetApiBufferFree");
3111 p2NetUserGetInfo = (pfn2)::GetProcAddress(netapi,
"NetUserGetInfo");
3112 p2NetLocalGroupGetMembers = (pfn3)::GetProcAddress(netapi,
"NetLocalGroupGetMembers");
3113 p2NetLocalGroupEnum = (pfn4)::GetProcAddress(netapi,
"NetLocalGroupEnum");
3115 if (!p2NetApiBufferFree || !p2NetUserGetInfo ||
3116 !p2NetLocalGroupGetMembers || !p2NetLocalGroupEnum)
return kFALSE;
3127 ::FreeLibrary(netapi);
3137 NET_API_STATUS NetStatus = NERR_Success;
3139 DWORD
Index = 0, ResumeHandle = 0, Total = 0;
3140 LOCALGROUP_MEMBERS_INFO_1 *MemberInfo;
3141 WCHAR wszGroupName[256];
3143 DWORD dwLastError = 0;
3145 iRetOp = MultiByteToWideChar (
3147 (DWORD)MB_PRECOMPOSED,
3148 (LPCSTR)lpszGroupName,
3150 (LPWSTR)wszGroupName,
3151 (
int)
sizeof(wszGroupName) );
3154 dwLastError = GetLastError();
3156 p2NetApiBufferFree(Data);
3162 NetStatus = p2NetLocalGroupGetMembers (
NULL, wszGroupName, 1,
3163 &Data, 8192, &Index, &Total, &ResumeHandle );
3165 if (NetStatus != NERR_Success || Data ==
NULL) {
3166 dwLastError = GetLastError();
3168 if (dwLastError == ERROR_ENVVAR_NOT_FOUND) {
3174 NetStatus = p2NetLocalGroupGetMembers (
NULL, wszGroupName, 0,
3175 &Data, 8192, &Index, &Total, &ResumeHandle );
3179 p2NetApiBufferFree(Data);
3184 MemberInfo = (LOCALGROUP_MEMBERS_INFO_1 *)Data;
3187 p2NetApiBufferFree(Data);
3196 NET_API_STATUS NetStatus = NERR_Success;
3198 DWORD
Index = 0, ResumeHandle = 0, Total = 0, i;
3199 LOCALGROUP_INFO_0 *GroupInfo;
3200 char szAnsiName[256];
3201 DWORD dwLastError = 0;
3204 NetStatus = p2NetLocalGroupEnum(
NULL, 0, &Data, 8192, &Index,
3205 &Total, &ResumeHandle );
3207 if (NetStatus != NERR_Success || Data ==
NULL) {
3208 dwLastError = GetLastError();
3210 p2NetApiBufferFree(Data);
3215 GroupInfo = (LOCALGROUP_INFO_0 *)Data;
3216 for (i=0; i < Total; i++) {
3218 iRetOp = WideCharToMultiByte (
3221 (LPCWSTR)(GroupInfo->lgrpi0_name),
3224 (
int)(
sizeof(szAnsiName)),
3236 p2NetApiBufferFree(Data);
3248 int &groupIdx,
int &memberIdx)
3250 BOOL bRetOp =
FALSE;
3252 DWORD dwSidSize, dwDomainNameSize;
3255 SID_NAME_USE sidType;
3256 PUCHAR puchar_SubAuthCount =
NULL;
3257 SID_IDENTIFIER_AUTHORITY sid_identifier_authority;
3258 PSID_IDENTIFIER_AUTHORITY psid_identifier_authority =
NULL;
3259 unsigned char j = 0;
3260 DWORD dwLastError = 0;
3262 pSid = (PSID)bySidBuffer;
3263 dwSidSize =
sizeof(bySidBuffer);
3264 dwDomainNameSize =
sizeof(szDomainName);
3266 bRetOp = LookupAccountName (
3268 (LPCTSTR)lpszAccountName,
3270 (LPDWORD)&dwSidSize,
3271 (LPTSTR)szDomainName,
3272 (LPDWORD)&dwDomainNameSize,
3273 (PSID_NAME_USE)&sidType );
3275 if (bRetOp ==
FALSE) {
3276 dwLastError = GetLastError();
3280 bRetOp = IsValidSid((PSID)pSid);
3282 if (bRetOp ==
FALSE) {
3283 dwLastError = GetLastError();
3288 psid_identifier_authority = GetSidIdentifierAuthority ((PSID)pSid);
3291 memcpy (&sid_identifier_authority, psid_identifier_authority,
3292 sizeof(SID_IDENTIFIER_AUTHORITY));
3295 puchar_SubAuthCount = (PUCHAR)GetSidSubAuthorityCount((PSID)pSid);
3297 j = (
unsigned char)(*puchar_SubAuthCount);
3299 DWORD dwSubAuth = 0;
3300 PDWORD pdwSubAuth =
NULL;
3302 pdwSubAuth = (PDWORD)GetSidSubAuthority (
3305 dwSubAuth = *pdwSubAuth;
3324 NET_API_STATUS NetStatus = NERR_Success;
3326 DWORD
Index = 0, ResumeHandle = 0, Total = 0, i;
3327 LOCALGROUP_MEMBERS_INFO_1 *MemberInfo;
3328 char szAnsiMemberName[256];
3329 char szFullMemberName[256];
3330 char szMemberHomeDir[256];
3331 WCHAR wszGroupName[256];
3334 DWORD length =
sizeof (act_name);
3335 DWORD dwLastError = 0;
3336 LPUSER_INFO_11 pUI11Buf =
NULL;
3337 NET_API_STATUS nStatus;
3339 iRetOp = MultiByteToWideChar (
3341 (DWORD)MB_PRECOMPOSED,
3342 (LPCSTR)lpszGroupName,
3344 (LPWSTR)wszGroupName,
3345 (
int)
sizeof(wszGroupName) );
3348 dwLastError = GetLastError();
3350 p2NetApiBufferFree(Data);
3354 GetUserName (act_name, &length);
3358 NetStatus = p2NetLocalGroupGetMembers (
NULL, wszGroupName, 1,
3359 &Data, 8192, &Index, &Total, &ResumeHandle );
3361 if (NetStatus != NERR_Success || Data ==
NULL) {
3362 dwLastError = GetLastError();
3364 if (dwLastError == ERROR_ENVVAR_NOT_FOUND) {
3370 NetStatus = p2NetLocalGroupGetMembers (
NULL, wszGroupName, 0,
3371 &Data, 8192, &Index, &Total, &ResumeHandle );
3375 p2NetApiBufferFree(Data);
3379 MemberInfo = (LOCALGROUP_MEMBERS_INFO_1 *)Data;
3380 for (i=0; i < Total; i++) {
3381 iRetOp = WideCharToMultiByte (
3384 (LPCWSTR)(MemberInfo->lgrmi1_name),
3386 (LPSTR)szAnsiMemberName,
3387 (
int)(
sizeof(szAnsiMemberName)),
3392 dwLastError = GetLastError();
3403 TCHAR szUserName[255]=TEXT(
"");
3404 MultiByteToWideChar(CP_ACP, 0, szAnsiMemberName, -1, (LPWSTR)szUserName, 255);
3408 nStatus = p2NetUserGetInfo(NULL, (LPCWSTR)szUserName, 11, (LPBYTE *)&pUI11Buf);
3412 if (nStatus == NERR_Success) {
3413 if (pUI11Buf != NULL) {
3414 wsprintf(szFullMemberName,
"%S",pUI11Buf->usri11_full_name);
3416 wsprintf(szMemberHomeDir,
"%S",pUI11Buf->usri11_home_dir);
3427 if (pUI11Buf != NULL) {
3428 p2NetApiBufferFree(pUI11Buf);
3433 if (getenv(
"SHELL") == NULL)
3434 putenv ((GetVersion () & 0x80000000) ?
"SHELL=command" :
"SHELL=cmd");
3447 p2NetApiBufferFree(Data);
3457 NET_API_STATUS NetStatus = NERR_Success;
3459 DWORD
Index = 0, ResumeHandle = 0, Total = 0, i;
3460 LOCALGROUP_INFO_0 *GroupInfo;
3461 char szAnsiName[256];
3462 DWORD dwLastError = 0;
3463 int iRetOp = 0, iGroupIdx = 0, iMemberIdx = 0;
3465 NetStatus = p2NetLocalGroupEnum(
NULL, 0, &Data, 8192, &Index,
3466 &Total, &ResumeHandle );
3468 if (NetStatus != NERR_Success || Data ==
NULL) {
3469 dwLastError = GetLastError();
3471 p2NetApiBufferFree(Data);
3475 GroupInfo = (LOCALGROUP_INFO_0 *)Data;
3476 for (i=0; i < Total; i++) {
3478 iRetOp = WideCharToMultiByte (
3481 (LPCWSTR)(GroupInfo->lgrpi0_name),
3484 (
int)(
sizeof(szAnsiName)),
3502 p2NetApiBufferFree(Data);
3516 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3519 DWORD length =
sizeof (
name);
3520 if (::GetUserName (name, &length)) {
3521 if (stricmp (
"administrator", name) == 0)
3531 if (!user || !user[0])
3557 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3560 DWORD length =
sizeof (
name);
3561 if (::GetUserName (name, &length)) {
3562 if (stricmp (
"administrator", name) == 0)
3584 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3587 DWORD length =
sizeof (
name);
3588 if (::GetUserName (name, &length)) {
3589 if (stricmp (
"administrator", name) == 0)
3599 if (!group || !group[0])
3602 struct group *grp = 0;
3625 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3628 DWORD length =
sizeof (
name);
3629 if (::GetUserName (name, &length)) {
3630 if (stricmp (
"administrator", name) == 0)
3653 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3655 DWORD length =
sizeof (
name);
3657 if (::GetUserName (name, &length)) {
3659 if (stricmp (
"administrator", name) == 0) {
3661 ug->
fGroup =
"administrators";
3670 ug->
fUser =
"unknown";
3683 for (
int i = 0; i <
fNbUsers; i++) {
3727 if ((!
gEnv->
GetValue(
"WinNT.UseNetAPI", 0)) || (::GetVersion() >= 0x80000000)) {
3729 DWORD length =
sizeof (
name);
3731 if (::GetUserName (name, &length)) {
3732 if (stricmp (
"administrator", name) == 0) {
3733 gr->
fGroup =
"administrators";
3748 struct group *grp = 0;
3793 const char *env = ::getenv(name);
3795 if (::_stricmp(name,
"home") == 0 ) {
3797 }
else if (::_stricmp(name,
"rootsys") == 0 ) {
3811 return ::system(shellcmd);
3819 return ::_popen(command, mode);
3827 return ::_pclose(pipe);
3854 gROOT->CloseFiles();
3855 if (
gROOT->GetListOfBrowsers()) {
3862 gROOT->ProcessLine(
TString::Format(
"((TBrowser*)0x%lx)->GetBrowserImp()->GetMainFrame()->CloseWindow();",
3904 static int fd1=0, fd2=0;
3905 static fpos_t pos1=0, pos2=0;
3915 const char *
m = (mode[0] ==
'a' || mode[0] ==
'w') ? mode :
"a";
3928 fgetpos(stdout, &pos1);
3929 fd1 = _dup(fileno(stdout));
3931 if ((fout = freopen(file, m, stdout)) == 0) {
3932 SysError(
"RedirectOutput",
"could not freopen stdout");
3934 _dup2(fd1, fileno(stdout));
3938 fsetpos(stdout, &pos1);
3943 fgetpos(stderr, &pos2);
3944 fd2 = _dup(fileno(stderr));
3945 if ((ferr = freopen(file, m, stderr)) == 0) {
3946 SysError(
"RedirectOutput",
"could not freopen stderr");
3948 _dup2(fd1, fileno(stdout));
3952 fsetpos(stdout, &pos1);
3954 _dup2(fd2, fileno(stderr));
3958 fsetpos(stderr, &pos2);
3963 fseek(fout, 0, SEEK_END);
3964 fseek(ferr, 0, SEEK_END);
3971 if (_dup2(fd1, fileno(stdout))) {
3972 SysError(
"RedirectOutput",
"could not restore stdout");
3978 fsetpos(stdout, &pos1);
3985 if (_dup2(fd2, fileno(stderr))) {
3986 SysError(
"RedirectOutput",
"could not restore stderr");
3992 fsetpos(stderr, &pos2);
4047 if (len > 4 && (!stricmp(sLib.
Data()+len-4,
".dll"))) {
4060 Error(
"DynamicPathName",
4061 "%s does not exist in %s,\nor has wrong file extension (.dll)",
4078 #pragma warning(push) 4079 #pragma warning(disable:4200) 4096 if (!linkedLibs.
IsNull())
4109 HANDLE hFile, hMapping;
4112 if((hFile = CreateFile(exe,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0))==
INVALID_HANDLE_VALUE) {
4116 if(!(hMapping = CreateFileMapping(hFile,0,PAGE_READONLY|SEC_COMMIT,0,0,0))) {
4121 if(!(basepointer = MapViewOfFile(hMapping,FILE_MAP_READ,0,0,0))) {
4122 CloseHandle(hMapping);
4129 IMAGE_DOS_HEADER *dos_head = (IMAGE_DOS_HEADER *)basepointer;
4132 IMAGE_FILE_HEADER _head;
4133 IMAGE_OPTIONAL_HEADER opt_head;
4134 IMAGE_SECTION_HEADER section_header[];
4136 struct header *pheader;
4137 const IMAGE_SECTION_HEADER * section_header;
4139 if(dos_head->e_magic!=
'ZM') {
4144 pheader = (
struct header *)((
char*)dos_head + dos_head->e_lfanew);
4146 if(IsBadReadPtr(pheader,
sizeof(
struct header))) {
4150 if(pheader->signature!=IMAGE_NT_SIGNATURE) {
4151 switch((
unsigned short)pheader->signature) {
4152 case IMAGE_DOS_SIGNATURE:
4155 case IMAGE_OS2_SIGNATURE:
4158 case IMAGE_OS2_SIGNATURE_LE:
4166 #define isin(address,start,length) ((address)>=(start) && (address)<(start)+(length)) 4169 for(sect=0,section_header=pheader->section_header;
4170 sect<pheader->_head.NumberOfSections;sect++,section_header++) {
4172 const void *
const section_data =
4173 (
char*)basepointer + section_header->PointerToRawData;
4174 for(directory=0;directory<IMAGE_NUMBEROF_DIRECTORY_ENTRIES;directory++) {
4175 if(
isin(pheader->opt_head.DataDirectory[directory].VirtualAddress,
4176 section_header->VirtualAddress,
4177 section_header->SizeOfRawData)) {
4178 const IMAGE_IMPORT_DESCRIPTOR *stuff_start =
4179 (IMAGE_IMPORT_DESCRIPTOR *)((
char*)section_data +
4180 (pheader->opt_head.DataDirectory[directory].VirtualAddress -
4181 section_header->VirtualAddress));
4184 const unsigned stuff_length =
4185 pheader->opt_head.DataDirectory[directory].Size;
4186 if(directory == IMAGE_DIRECTORY_ENTRY_IMPORT) {
4187 while(!IsBadReadPtr(stuff_start,
sizeof(*stuff_start)) &&
4188 stuff_start->Name) {
4189 TString dll = (
char*)section_data +
4190 ((DWORD)(stuff_start->Name)) -
4191 section_header->VirtualAddress;
4195 char *winPath = getenv(
"windir");
4196 _splitpath(winPath,winDrive,winDir,winName,winExt);
4197 if(!strstr(dllPath, winDir)) {
4198 if (!linkedLibs.
IsNull())
4200 linkedLibs += dllPath;
4212 UnmapViewOfFile(basepointer);
4213 CloseHandle(hMapping);
4225 #pragma warning(pop) 4246 TRegexp separator(
"[^ \\t\\s]+");
4251 Ssiz_t start, index, end;
4252 start = index = end = 0;
4254 while ((start < libs.
Length()) && (index !=
kNPOS)) {
4255 index = libs.
Index(separator, &end, start);
4259 s = libs(index, end);
4336 if (mode && t->
IsSync()) {
4340 }
else if (!mode && t->
IsAsync()) {
4358 FILETIME ftFileTime;
4362 ::GetSystemTimeAsFileTime(&ftRealTime.ftFileTime);
4371 OSVERSIONINFO OsVersionInfo;
4380 OsVersionInfo.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
4381 GetVersionEx(&OsVersionInfo);
4382 if (OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
4388 FILETIME ftFileTime;
4393 FILETIME ftFileTime;
4397 HANDLE hThread = GetCurrentThread();
4398 ret = GetThreadTimes (hThread, &ftCreate, &ftExit,
4399 &ftKernel.ftFileTime,
4400 &ftUser.ftFileTime);
4402 ret = ::GetLastError();
4403 ::Error(
"GetCPUTime",
" Error on GetProcessTimes 0x%lx", (
int)ret);
4423 static time_t jan95 = 0;
4434 jan95 = mktime(&tp);
4435 if ((
int)jan95 == -1) {
4436 ::SysError(
"TWinNTSystem::Now",
"error converting 950001 0:00 to time_t");
4443 return TTime((now.time-(
Long_t)jan95)*1000 + now.millitm);
4475 rc = WinNTSelect(&rd, &wr, to);
4509 rc = WinNTSelect(&rd, &wr, to);
4531 if ((sp = ::getservbyname(servicename,
kProtocolName)) == 0) {
4532 Error(
"GetServiceByName",
"no service \"%s\" with protocol \"%s\"\n",
4536 return ::ntohs(sp->s_port);
4547 if ((sp = ::getservbyport(::htons(port),
kProtocolName)) == 0) {
4548 return Form(
"%d", port);
4558 struct hostent *host_ptr;
4563 if ((addr = ::inet_addr(hostname)) != INADDR_NONE) {
4565 if ((host_ptr = ::gethostbyaddr((
const char *)&addr,
4566 sizeof(addr), AF_INET))) {
4567 host = host_ptr->h_name;
4571 for (i = 1; host_ptr->h_addr_list[i]; i++) {
4572 memcpy(&addr2, host_ptr->h_addr_list[i], host_ptr->h_length);
4575 for (i = 0; host_ptr->h_aliases[i]; i++)
4576 a.
AddAlias(host_ptr->h_aliases[i]);
4579 host =
"UnNamedHost";
4581 }
else if ((host_ptr = ::gethostbyname(hostname))) {
4583 if (host_ptr->h_addrtype != AF_INET) {
4584 Error(
"GetHostByName",
"%s is not an internet host\n", hostname);
4587 memcpy(&addr, host_ptr->h_addr, host_ptr->h_length);
4588 host = host_ptr->h_name;
4589 type = host_ptr->h_addrtype;
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 if (
gDebug > 0)
Error(
"GetHostByName",
"unknown host %s", hostname);
4614 struct sockaddr_in addr;
4615 int len =
sizeof(addr);
4617 if (::getpeername(sock, (
struct sockaddr *)&addr, &len) == SOCKET_ERROR) {
4622 struct hostent *host_ptr;
4623 const char *hostname;
4627 if ((host_ptr = ::gethostbyaddr((
const char *)&addr.sin_addr,
4628 sizeof(addr.sin_addr), AF_INET))) {
4629 memcpy(&iaddr, host_ptr->h_addr, host_ptr->h_length);
4630 hostname = host_ptr->h_name;
4631 family = host_ptr->h_addrtype;
4633 memcpy(&iaddr, &addr.sin_addr,
sizeof(addr.sin_addr));
4638 return TInetAddress(hostname, ::ntohl(iaddr), family, ::ntohs(addr.sin_port));
4647 struct sockaddr_in addr;
4648 int len =
sizeof(addr);
4650 if (::getsockname(sock, (
struct sockaddr *)&addr, &len) == SOCKET_ERROR) {
4655 struct hostent *host_ptr;
4656 const char *hostname;
4660 if ((host_ptr = ::gethostbyaddr((
const char *)&addr.sin_addr,
4661 sizeof(addr.sin_addr), AF_INET))) {
4662 memcpy(&iaddr, host_ptr->h_addr, host_ptr->h_length);
4663 hostname = host_ptr->h_name;
4664 family = host_ptr->h_addrtype;
4666 memcpy(&iaddr, &addr.sin_addr,
sizeof(addr.sin_addr));
4671 return TInetAddress(hostname, ::ntohl(iaddr), family, ::ntohs(addr.sin_port));
4682 if ((sock = ::socket(AF_INET, SOCK_STREAM, 0)) ==
INVALID_SOCKET) {
4683 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"socket");
4687 struct sockaddr_in inserver;
4688 memset(&inserver, 0,
sizeof(inserver));
4689 inserver.sin_family = AF_INET;
4690 inserver.sin_addr.s_addr = ::htonl(INADDR_LOOPBACK);
4691 inserver.sin_port = port;
4695 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver)) == SOCKET_ERROR) {
4696 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"bind");
4701 if (::listen(sock, backlog)) {
4702 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"listen");
4714 if (!sockpath || strlen(sockpath) <= 0) {
4715 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"socket path undefined");
4719 struct sockaddr_in myaddr;
4721 int len =
sizeof myaddr;
4726 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
4727 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"socket");
4731 memset(&myaddr, 0,
sizeof(myaddr));
4732 myaddr.sin_port = 0;
4733 myaddr.sin_family = AF_INET;
4734 myaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
4736 rc = bind(sock, (
struct sockaddr *)&myaddr, len);
4738 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"bind");
4741 rc = getsockname(sock, (
struct sockaddr *)&myaddr, &len);
4743 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"getsockname");
4746 TString socketpath = sockpath;
4748 fp = fopen(socketpath,
"wb");
4750 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"fopen");
4753 fprintf(fp,
"%d", myaddr.sin_port);
4757 if (listen(sock, backlog)) {
4758 ::SysError(
"TWinNTSystem::AnnounceUnixService",
"listen");
4770 if (socket == -1)
return;
4774 ::shutdown(sock, 2);
4776 struct linger linger = {0, 0};
4777 ::setsockopt(sock, SOL_SOCKET, SO_LINGER, (
char *) &linger,
sizeof(linger));
4778 while (::
closesocket(sock) == SOCKET_ERROR && WSAGetLastError() == WSAEINTR) {
4792 if (WinNTRecv(sock, &header,
sizeof(header), 0) > 0) {
4793 int count = ::ntohl(header);
4795 if (count > length) {
4796 Error(
"RecvBuf",
"record header exceeds buffer size");
4798 }
else if (count > 0) {
4799 if (WinNTRecv(sock, buf, count, 0) < 0) {
4800 Error(
"RecvBuf",
"cannot receive buffer");
4815 Int_t header = ::htonl(length);
4817 if (WinNTSend(sock, &header,
sizeof(header), 0) < 0) {
4818 Error(
"SendBuf",
"cannot send header");
4822 if (WinNTSend(sock, buf, length, 0) < 0) {
4823 Error(
"SendBuf",
"cannot send buffer");
4863 if ((n = WinNTRecv(sock, buf, length, flag)) <= 0) {
4865 Error(
"RecvRaw",
"cannot receive buffer");
4899 if ((n = WinNTSend(sock, buf, length, flag)) <= 0) {
4900 if (n == -1 &&
GetErrno() != EINTR) {
4901 Error(
"SendRaw",
"cannot send buffer");
4914 if (socket == -1)
return -1;
4919 if (::setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4920 ::SysError(
"SetSockOpt",
"setsockopt(SO_SNDBUF)");
4925 if (::setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4926 ::SysError(
"SetSockOpt",
"setsockopt(SO_RCVBUF)");
4931 if (::setsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4932 SysError(
"SetSockOpt",
"setsockopt(SO_OOBINLINE)");
4937 if (::setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4938 ::SysError(
"SetSockOpt",
"setsockopt(SO_KEEPALIVE)");
4943 if (::setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4944 ::SysError(
"SetSockOpt",
"setsockopt(SO_REUSEADDR)");
4949 if (::setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)&val,
sizeof(val)) == SOCKET_ERROR) {
4950 ::SysError(
"SetSockOpt",
"setsockopt(TCP_NODELAY)");
4955 if (::ioctlsocket(sock, FIONBIO, &val) == SOCKET_ERROR) {
4962 if (::ioctl(sock, SIOCSPGRP, &val) == -1) {
4963 ::SysError(
"SetSockOpt",
"ioctl(SIOCSPGRP)");
4971 Error(
"SetSockOpt",
"illegal option (%d)", opt);
4983 if (socket == -1)
return -1;
4986 int optlen =
sizeof(*val);
4990 if (::getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)val, &optlen) == SOCKET_ERROR) {
4991 ::SysError(
"GetSockOpt",
"getsockopt(SO_SNDBUF)");
4996 if (::getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)val, &optlen) == SOCKET_ERROR) {
4997 ::SysError(
"GetSockOpt",
"getsockopt(SO_RCVBUF)");
5002 if (::getsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)val, &optlen) == SOCKET_ERROR) {
5003 ::SysError(
"GetSockOpt",
"getsockopt(SO_OOBINLINE)");
5008 if (::getsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)val, &optlen) == SOCKET_ERROR) {
5009 ::SysError(
"GetSockOpt",
"getsockopt(SO_KEEPALIVE)");
5014 if (::getsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)val, &optlen) == SOCKET_ERROR) {
5015 ::SysError(
"GetSockOpt",
"getsockopt(SO_REUSEADDR)");
5020 if (::getsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)val, &optlen) == SOCKET_ERROR) {
5021 ::SysError(
"GetSockOpt",
"getsockopt(TCP_NODELAY)");
5037 if (::ioctlsocket(sock, SIOCGPGRP, (u_long*)val) == SOCKET_ERROR) {
5038 ::SysError(
"GetSockOpt",
"ioctl(SIOCGPGRP)");
5044 if (::ioctlsocket(sock, SIOCATMARK, (u_long*)val) == SOCKET_ERROR) {
5045 ::SysError(
"GetSockOpt",
"ioctl(SIOCATMARK)");
5050 if (::ioctlsocket(sock, FIONREAD, (u_long*)val) == SOCKET_ERROR) {
5056 Error(
"GetSockOpt",
"illegal option (%d)", opt);
5068 int tcpwindowsize,
const char *protocol)
5073 if (!strcmp(servername,
"unix")) {
5077 (servername[1] ==
':' && servername[2] ==
'/')) {
5081 if (!strcmp(protocol,
"udp")){
5088 sport = ::htons(port);
5092 if (!addr.
IsValid())
return -1;
5095 struct sockaddr_in server;
5096 memset(&server, 0,
sizeof(server));
5097 memcpy(&server.sin_addr, &adr,
sizeof(adr));
5099 server.sin_port = sport;
5103 if ((sock = ::socket(AF_INET, SOCK_STREAM, 0)) ==
INVALID_SOCKET) {
5104 ::SysError(
"TWinNTSystem::WinNTConnectTcp",
"socket");
5108 if (tcpwindowsize > 0) {
5113 if (::connect(sock, (
struct sockaddr*) &server,
sizeof(server)) ==
INVALID_SOCKET) {
5126 struct sockaddr_in myaddr;
5129 memset(&myaddr, 0,
sizeof(myaddr));
5130 myaddr.sin_family = AF_INET;
5131 myaddr.sin_port = port;
5132 myaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
5135 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
5136 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"socket");
5140 while ((connect(sock, (
struct sockaddr *)&myaddr,
sizeof myaddr)) == -1) {
5144 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"connect");
5160 if (!sockpath || strlen(sockpath) <= 0) {
5161 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"socket path undefined");
5164 TString socketpath = sockpath;
5166 fp = fopen(socketpath.
Data(),
"rb");
5168 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"fopen");
5171 fscanf(fp,
"%d", &port);
5174 if (port < 0 || port > 65535) {
5175 ::SysError(
"TWinNTSystem::WinNTUnixConnect",
"invalid port");
5193 sport = htons(port);
5196 if (!addr.
IsValid())
return -1;
5199 struct sockaddr_in server;
5200 memset(&server, 0,
sizeof(server));
5201 memcpy(&server.sin_addr, &adr,
sizeof(adr));
5203 server.sin_port = sport;
5207 if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
5208 ::SysError(
"TWinNTSystem::WinNTUdpConnect",
"socket (%s:%d)",
5213 while (connect(sock, (
struct sockaddr*) &server,
sizeof(server)) == -1) {
5217 ::SysError(
"TWinNTSystem::WinNTUdpConnect",
"connect (%s:%d)",
5235 const char *protocol)
5256 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
5257 short tryport = kSOCKET_MINPORT;
5262 sport = ::htons(port);
5265 if (port == 0 && reuse) {
5266 ::Error(
"TWinNTSystem::WinNTTcpService",
"cannot do a port scan while reuse is true");
5273 sport = ::htons(port);
5278 if ((sock = ::socket(AF_INET, SOCK_STREAM, 0)) < 0) {
5279 ::SysError(
"TWinNTSystem::WinNTTcpService",
"socket");
5287 if (tcpwindowsize > 0) {
5292 struct sockaddr_in inserver;
5293 memset(&inserver, 0,
sizeof(inserver));
5294 inserver.sin_family = AF_INET;
5295 inserver.sin_addr.s_addr = ::htonl(INADDR_ANY);
5296 inserver.sin_port = sport;
5300 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver)) == SOCKET_ERROR) {
5301 ::SysError(
"TWinNTSystem::WinNTTcpService",
"bind");
5307 inserver.sin_port = ::htons(tryport);
5308 bret = ::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
5310 }
while (bret == SOCKET_ERROR && WSAGetLastError() == WSAEADDRINUSE &&
5311 tryport < kSOCKET_MAXPORT);
5312 if (bret == SOCKET_ERROR) {
5313 ::SysError(
"TWinNTSystem::WinNTTcpService",
"bind (port scan)");
5319 if (::listen(sock, backlog) == SOCKET_ERROR) {
5320 ::SysError(
"TWinNTSystem::WinNTTcpService",
"listen");
5337 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
5338 short sport, tryport = kSOCKET_MINPORT;
5344 sport = htons(port);
5348 if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
5349 ::SysError(
"TUnixSystem::UnixUdpService",
"socket");
5353 struct sockaddr_in inserver;
5354 memset(&inserver, 0,
sizeof(inserver));
5355 inserver.sin_family = AF_INET;
5356 inserver.sin_addr.s_addr = htonl(INADDR_ANY);
5357 inserver.sin_port = sport;
5361 if (bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver))) {
5362 ::SysError(
"TWinNTSystem::AnnounceUdpService",
"bind");
5368 inserver.sin_port = htons(tryport);
5369 bret = bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
5371 }
while (bret == SOCKET_ERROR && WSAGetLastError() == WSAEADDRINUSE &&
5372 tryport < kSOCKET_MAXPORT);
5374 ::SysError(
"TWinNTSystem::AnnounceUdpService",
"bind (port scan)");
5380 if (listen(sock, backlog)) {
5381 ::SysError(
"TWinNTSystem::AnnounceUdpService",
"listen");
5399 (::WSAGetLastError() == WSAEINTR)) {
5404 if (::WSAGetLastError() == WSAEWOULDBLOCK) {
5418 #define SystemBasicInformation 0 5419 #define SystemPerformanceInformation 2 5424 ULONG uKeMaximumIncrement;
5426 ULONG uMmNumberOfPhysicalPages;
5427 ULONG uMmLowestPhysicalPage;
5428 ULONG UMmHighestPhysicalPage;
5429 ULONG uAllocationGranularity;
5430 PVOID pLowestUserAddress;
5431 PVOID pMmHighestUserAddress;
5432 ULONG uKeActiveProcessors;
5433 BYTE bKeNumberProcessors;
5436 } SYSTEM_BASIC_INFORMATION;
5440 LARGE_INTEGER liIdleTime;
5442 } SYSTEM_PERFORMANCE_INFORMATION;
5444 typedef struct _PROCESS_MEMORY_COUNTERS {
5446 DWORD PageFaultCount;
5447 SIZE_T PeakWorkingSetSize;
5448 SIZE_T WorkingSetSize;
5449 SIZE_T QuotaPeakPagedPoolUsage;
5450 SIZE_T QuotaPagedPoolUsage;
5451 SIZE_T QuotaPeakNonPagedPoolUsage;
5452 SIZE_T QuotaNonPagedPoolUsage;
5453 SIZE_T PagefileUsage;
5454 SIZE_T PeakPagefileUsage;
5459 #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + (double)((x).LowPart)) 5467 LARGE_INTEGER ulFreq, ulTicks, ulValue, ulStartCounter;
5471 if (QueryPerformanceFrequency(&ulFreq)) {
5473 QueryPerformanceCounter(&ulTicks);
5476 ulValue.QuadPart = ulTicks.QuadPart + ulFreq.QuadPart/10;
5477 ulStartCounter.QuadPart =
__rdtsc();
5481 QueryPerformanceCounter(&ulTicks);
5482 }
while (ulTicks.QuadPart <= ulValue.QuadPart);
5484 return (DWORD)((
__rdtsc() - ulStartCounter.QuadPart)/100000);
5492 #define SM_SERVERR2 89 5499 OSVERSIONINFOEX osvi;
5502 BOOL bOsVersionInfoEx;
5503 static char *strReturn = 0;
5507 strReturn =
new char[2048];
5511 ZeroMemory(&si,
sizeof(SYSTEM_INFO));
5512 ZeroMemory(&osvi,
sizeof(OSVERSIONINFOEX));
5517 osvi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFOEX);
5519 if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
5521 osvi.dwOSVersionInfoSize =
sizeof (OSVERSIONINFO);
5522 if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
5527 pGNSI = (
PGNSI) GetProcAddress( GetModuleHandle(
"kernel32.dll"),
5528 "GetNativeSystemInfo");
5531 else GetSystemInfo(&si);
5533 switch (osvi.dwPlatformId)
5536 case VER_PLATFORM_WIN32_NT:
5539 if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 )
5541 if( osvi.wProductType == VER_NT_WORKSTATION )
5542 strlcpy(strReturn,
"Microsoft Windows Vista ",2048);
5543 else strlcpy(strReturn,
"Windows Server \"Longhorn\" " ,2048);
5545 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
5548 strlcpy(strReturn,
"Microsoft Windows Server 2003 \"R2\" ",2048);
5549 else if( osvi.wProductType == VER_NT_WORKSTATION &&
5550 si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
5552 strlcpy(strReturn,
"Microsoft Windows XP Professional x64 Edition ",2048);
5554 else strlcpy(strReturn,
"Microsoft Windows Server 2003, ",2048);
5556 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
5557 strlcpy(strReturn,
"Microsoft Windows XP ",2048);
5559 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
5560 strlcpy(strReturn,
"Microsoft Windows 2000 ",2048);
5562 if ( osvi.dwMajorVersion <= 4 )
5563 strlcpy(strReturn,
"Microsoft Windows NT ",2048);
5566 if( bOsVersionInfoEx )
5569 if ( osvi.wProductType == VER_NT_WORKSTATION &&
5570 si.wProcessorArchitecture!=PROCESSOR_ARCHITECTURE_AMD64)
5572 if( osvi.dwMajorVersion == 4 )
5573 strlcat(strReturn,
"Workstation 4.0 ",2048 );
5574 else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
5575 strlcat(strReturn,
"Home Edition " ,2048);
5576 else strlcat(strReturn,
"Professional " ,2048);
5579 else if ( osvi.wProductType == VER_NT_SERVER ||
5580 osvi.wProductType == VER_NT_DOMAIN_CONTROLLER )
5582 if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==2)
5584 if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_IA64 )
5586 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
5587 strlcat(strReturn,
"Datacenter Edition for Itanium-based Systems",2048 );
5588 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5589 strlcat(strReturn,
"Enterprise Edition for Itanium-based Systems" ,2048);
5591 else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
5593 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
5594 strlcat(strReturn,
"Datacenter x64 Edition ",2048 );
5595 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5596 strlcat(strReturn,
"Enterprise x64 Edition ",2048 );
5597 else strlcat(strReturn,
"Standard x64 Edition ",2048 );
5601 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
5602 strlcat(strReturn,
"Datacenter Edition ",2048 );
5603 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5604 strlcat(strReturn,
"Enterprise Edition ",2048 );
5605 else if ( osvi.wSuiteMask == VER_SUITE_BLADE )
5606 strlcat(strReturn,
"Web Edition " ,2048);
5607 else strlcat(strReturn,
"Standard Edition ",2048 );
5610 else if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==0)
5612 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
5613 strlcat(strReturn,
"Datacenter Server ",2048 );
5614 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5615 strlcat(strReturn,
"Advanced Server ",2048 );
5616 else strlcat(strReturn,
"Server ",2048 );
5620 if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
5621 strlcat(strReturn,
"Server 4.0, Enterprise Edition " ,2048);
5622 else strlcat(strReturn,
"Server 4.0 ",2048 );
5631 DWORD dwBufLen=
BUFSIZE*
sizeof(TCHAR);
5634 lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
5635 "SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
5636 0, KEY_QUERY_VALUE, &hKey );
5637 if( lRet != ERROR_SUCCESS )
5640 lRet = RegQueryValueEx( hKey,
"ProductType",
NULL,
NULL,
5641 (LPBYTE) szProductType, &dwBufLen);
5642 RegCloseKey( hKey );
5644 if( (lRet != ERROR_SUCCESS) || (dwBufLen >
BUFSIZE*
sizeof(TCHAR)) )
5647 if ( lstrcmpi(
"WINNT", szProductType) == 0 )
5648 strlcat(strReturn,
"Workstation " ,2048);
5649 if ( lstrcmpi(
"LANMANNT", szProductType) == 0 )
5650 strlcat(strReturn,
"Server " ,2048);
5651 if ( lstrcmpi(
"SERVERNT", szProductType) == 0 )
5652 strlcat(strReturn,
"Advanced Server " ,2048);
5653 snprintf(temp,512,
"%d.%d ", osvi.dwMajorVersion, osvi.dwMinorVersion);
5654 strlcat(strReturn, temp,2048);
5659 if( osvi.dwMajorVersion == 4 &&
5660 lstrcmpi( osvi.szCSDVersion,
"Service Pack 6" ) == 0 )
5666 lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
5667 "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009",
5668 0, KEY_QUERY_VALUE, &hKey );
5669 if( lRet == ERROR_SUCCESS ) {
5670 snprintf(temp, 512,
"Service Pack 6a (Build %d)", osvi.dwBuildNumber & 0xFFFF );
5671 strlcat(strReturn, temp,2048 );
5675 snprintf(temp,512,
"%s (Build %d)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
5676 strlcat(strReturn, temp,2048 );
5679 RegCloseKey( hKey );
5683 snprintf(temp, 512,
"%s (Build %d)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
5684 strlcat(strReturn, temp,2048 );
5690 case VER_PLATFORM_WIN32_WINDOWS:
5692 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
5694 strlcpy(strReturn,
"Microsoft Windows 95 ",2048);
5695 if (osvi.szCSDVersion[1]==
'C' || osvi.szCSDVersion[1]==
'B')
5696 strlcat(strReturn,
"OSR2 " ,2048);
5699 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
5701 strlcpy(strReturn,
"Microsoft Windows 98 ",2048);
5702 if ( osvi.szCSDVersion[1]==
'A' || osvi.szCSDVersion[1]==
'B')
5703 strlcat(strReturn,
"SE ",2048 );
5706 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
5708 strlcpy(strReturn,
"Microsoft Windows Millennium Edition",2048);
5712 case VER_PLATFORM_WIN32s:
5713 strlcpy(strReturn,
"Microsoft Win32s",2048);
5724 unsigned nHighestFeatureEx;
5728 nHighestFeatureEx = (unsigned)nBuff[0];
5730 if (nHighestFeatureEx >= 0x80000006) {
5732 return (((
unsigned)nBuff[2])>>16);
5742 SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
5743 SYSTEM_INFO sysInfo;
5744 MEMORYSTATUSEX statex;
5745 OSVERSIONINFO OsVersionInfo;
5747 char szKeyValueString[80];
5748 DWORD szKeyValueDword;
5753 NtQuerySystemInformation = (
PROCNTQSI)GetProcAddress(
5754 GetModuleHandle(
"ntdll"),
"NtQuerySystemInformation");
5756 if (!NtQuerySystemInformation) {
5758 "Error on GetProcAddress(NtQuerySystemInformation)");
5763 &SysPerfInfo,
sizeof(SysPerfInfo),
5765 OsVersionInfo.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
5766 GetVersionEx(&OsVersionInfo);
5767 GetSystemInfo(&sysInfo);
5768 statex.dwLength =
sizeof(statex);
5769 if (!GlobalMemoryStatusEx(&statex)) {
5770 ::Error(
"GetWinNTSysInfo",
"Error on GlobalMemoryStatusEx()");
5773 sysinfo->
fCpus = sysInfo.dwNumberOfProcessors;
5782 status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"HARDWARE\\DESCRIPTION\\System",
5783 0, KEY_QUERY_VALUE, &hKey);
5784 if (status == ERROR_SUCCESS) {
5785 dwBufLen =
sizeof(szKeyValueString);
5786 RegQueryValueEx(hKey,
"Identifier",
NULL,
NULL,(LPBYTE)szKeyValueString,
5788 sysinfo->
fModel = szKeyValueString;
5791 status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
5792 "Hardware\\Description\\System\\CentralProcessor\\0",
5793 0, KEY_QUERY_VALUE, &hKey);
5794 if (status == ERROR_SUCCESS) {
5795 dwBufLen =
sizeof(szKeyValueString);
5796 status = RegQueryValueEx(hKey,
"ProcessorNameString",
NULL,
NULL,
5797 (LPBYTE)szKeyValueString, &dwBufLen);
5798 if (status == ERROR_SUCCESS)
5799 sysinfo->
fCpuType = szKeyValueString;
5800 dwBufLen =
sizeof(DWORD);
5801 status = RegQueryValueEx(hKey,
"~MHz",
NULL,
NULL,(LPBYTE)&szKeyValueDword,
5803 if ((status == ERROR_SUCCESS) && ((sysinfo->
fCpuSpeed <= 0) ||
5804 (sysinfo->
fCpuSpeed < (szKeyValueDword >> 1))))
5818 SYSTEM_INFO sysInfo;
5819 Float_t idle_ratio, kernel_ratio, user_ratio, total_ratio;
5820 FILETIME ft_sys_idle, ft_sys_kernel, ft_sys_user, ft_fun_time;
5821 SYSTEMTIME st_fun_time;
5823 ULARGE_INTEGER ul_sys_idle, ul_sys_kernel, ul_sys_user;
5824 static ULARGE_INTEGER ul_sys_idleold = {0, 0};
5825 static ULARGE_INTEGER ul_sys_kernelold = {0, 0};
5826 static ULARGE_INTEGER ul_sys_userold = {0, 0};
5827 ULARGE_INTEGER ul_sys_idle_diff, ul_sys_kernel_diff, ul_sys_user_diff;
5829 ULARGE_INTEGER ul_fun_time;
5830 ULARGE_INTEGER ul_fun_timeold = {0, 0};
5831 ULARGE_INTEGER ul_fun_time_diff;
5833 typedef BOOL (__stdcall *GetSystemTimesProc)( LPFILETIME lpIdleTime,
5834 LPFILETIME lpKernelTime, LPFILETIME lpUserTime );
5835 static GetSystemTimesProc pGetSystemTimes = 0;
5837 HMODULE hModImagehlp = LoadLibrary(
"Kernel32.dll" );
5838 if (!hModImagehlp) {
5839 ::Error(
"GetWinNTCpuInfo",
"Error on LoadLibrary(Kernel32.dll)");
5843 pGetSystemTimes = (GetSystemTimesProc) GetProcAddress( hModImagehlp,
5845 if (!pGetSystemTimes) {
5846 ::Error(
"GetWinNTCpuInfo",
"Error on GetProcAddress(GetSystemTimes)");
5849 GetSystemInfo(&sysInfo);
5852 pGetSystemTimes(&ft_sys_idle,&ft_sys_kernel,&ft_sys_user);
5853 GetSystemTime(&st_fun_time);
5854 SystemTimeToFileTime(&st_fun_time,&ft_fun_time);
5856 memcpy(&ul_sys_idle, &ft_sys_idle,
sizeof(FILETIME));
5857 memcpy(&ul_sys_kernel, &ft_sys_kernel,
sizeof(FILETIME));
5858 memcpy(&ul_sys_user, &ft_sys_user,
sizeof(FILETIME));
5859 memcpy(&ul_fun_time, &ft_fun_time,
sizeof(FILETIME));
5861 ul_sys_idle_diff.QuadPart = ul_sys_idle.QuadPart -
5862 ul_sys_idleold.QuadPart;
5863 ul_sys_kernel_diff.QuadPart = ul_sys_kernel.QuadPart -
5864 ul_sys_kernelold.QuadPart;
5865 ul_sys_user_diff.QuadPart = ul_sys_user.QuadPart -
5866 ul_sys_userold.QuadPart;
5868 ul_fun_time_diff.QuadPart = ul_fun_time.QuadPart -
5869 ul_fun_timeold.QuadPart;
5871 ul_sys_idleold.QuadPart = ul_sys_idle.QuadPart;
5872 ul_sys_kernelold.QuadPart = ul_sys_kernel.QuadPart;
5873 ul_sys_userold.QuadPart = ul_sys_user.QuadPart;
5875 if (ul_fun_timeold.QuadPart == 0) {
5877 ul_fun_timeold.QuadPart = ul_fun_time.QuadPart;
5880 ul_fun_timeold.QuadPart = ul_fun_time.QuadPart;
5888 idle_ratio /= (
Float_t)sysInfo.dwNumberOfProcessors;
5889 user_ratio /= (
Float_t)sysInfo.dwNumberOfProcessors;
5890 kernel_ratio /= (
Float_t)sysInfo.dwNumberOfProcessors;
5891 total_ratio = 100.0 - idle_ratio;
5896 cpuinfo->
fUser = user_ratio;
5897 cpuinfo->
fSys = kernel_ratio;
5898 cpuinfo->
fTotal = total_ratio;
5899 cpuinfo->
fIdle = idle_ratio;
5908 MEMORYSTATUSEX statex;
5909 statex.dwLength =
sizeof(statex);
5910 if (!GlobalMemoryStatusEx(&statex)) {
5911 ::Error(
"GetWinNTMemInfo",
"Error on GlobalMemoryStatusEx()");
5914 used = (
Long64_t)(statex.ullTotalPhys - statex.ullAvailPhys);
5915 free = (
Long64_t) statex.ullAvailPhys;
5916 total = (
Long64_t) statex.ullTotalPhys;
5922 swap_total = (
Long64_t)(statex.ullTotalPageFile - statex.ullTotalPhys);
5923 swap_avail = (
Long64_t)(statex.ullAvailPageFile - statex.ullAvailPhys);
5924 swap_used = swap_total - swap_avail;
5937 FILETIME starttime, exittime, kerneltime, usertime;
5938 timeval ru_stime, ru_utime;
5941 typedef BOOL (__stdcall *GetProcessMemoryInfoProc)( HANDLE Process,
5943 static GetProcessMemoryInfoProc pGetProcessMemoryInfo = 0;
5945 HMODULE hModImagehlp = LoadLibrary(
"Psapi.dll" );
5946 if (!hModImagehlp) {
5947 ::Error(
"GetWinNTProcInfo",
"Error on LoadLibrary(Psapi.dll)");
5951 pGetProcessMemoryInfo = (GetProcessMemoryInfoProc) GetProcAddress(
5952 hModImagehlp,
"GetProcessMemoryInfo" );
5953 if (!pGetProcessMemoryInfo) {
5955 "Error on GetProcAddress(GetProcessMemoryInfo)");
5959 if ( pGetProcessMemoryInfo( GetCurrentProcess(), &pmc,
sizeof(pmc)) ) {
5963 if ( GetProcessTimes(GetCurrentProcess(), &starttime, &exittime,
5964 &kerneltime, &usertime)) {
5967 memcpy(&li, &kerneltime,
sizeof(FILETIME));
5969 ru_stime.tv_sec = li.QuadPart / 1000000
L;
5970 ru_stime.tv_usec = li.QuadPart % 1000000
L;
5972 memcpy(&li, &usertime,
sizeof(FILETIME));
5974 ru_utime.tv_sec = li.QuadPart / 1000000
L;
5975 ru_utime.tv_usec = li.QuadPart % 1000000
L;
5978 ((
Float_t)(ru_utime.tv_usec) / 1000000.);
5980 ((
Float_t)(ru_stime.tv_usec) / 1000000.);
5991 if (!info)
return -1;
6003 if (!info)
return -1;
6014 if (!info)
return -1;
6025 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)
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
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.
double read(const std::string &file_name)
reading
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.
static const TString & GetMacroDir()
Get the macro directory in the installation. Static utility function.
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)
RooArgList L(const RooAbsArg &v1)
const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
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
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.