ROOT  6.06/08
Reference Guide
TSystem.cxx
Go to the documentation of this file.
1 // @(#)root/base:$Id: 8944840ba34631ec28efc779647618db43c0eee5 $
2 // Author: Fons Rademakers 15/09/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TSystem
13 
14 Abstract base class defining a generic interface to the underlying
15 Operating System.
16 This is not an ABC in the strict sense of the (C++) word. For
17 every member function there is an implementation (often not more
18 than a call to AbstractMethod() which prints a warning saying
19 that the method should be overridden in a derived class), which
20 allows a simple partial implementation for new OS'es.
21 */
22 
23 #ifdef WIN32
24 #include <io.h>
25 #endif
26 #include <stdlib.h>
27 #include <errno.h>
28 #include <algorithm>
29 #include <sys/stat.h>
30 
31 #include "Riostream.h"
32 #include "TSystem.h"
33 #include "TApplication.h"
34 #include "TException.h"
35 #include "TROOT.h"
36 #include "TClass.h"
37 #include "TClassTable.h"
38 #include "TEnv.h"
39 #include "TBrowser.h"
40 #include "TString.h"
41 #include "TOrdCollection.h"
42 #include "TInterpreter.h"
43 #include "TRegexp.h"
44 #include "TTimer.h"
45 #include "TObjString.h"
46 #include "TError.h"
47 #include "TPluginManager.h"
48 #include "TUrl.h"
49 #include "TVirtualMutex.h"
50 #include "compiledata.h"
51 #include "RConfigure.h"
52 
53 const char *gRootDir;
54 const char *gProgName;
55 const char *gProgPath;
56 
57 TSystem *gSystem = 0;
58 TFileHandler *gXDisplay = 0; // Display server event handler, set in TGClient
59 
60 static Int_t *gLibraryVersion = 0; // Set in TVersionCheck, used in Load()
61 static Int_t gLibraryVersionIdx = 0; // Set in TVersionCheck, used in Load()
63 
64 
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 /// Create async event processor timer. Delay is in milliseconds.
69 
71 {
72  gROOT->SetInterrupt(kFALSE);
73  TurnOn();
74 }
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 /// Process events if timer did time out. Returns kTRUE if interrupt
78 /// flag is set (by hitting a key in the canvas or selecting the
79 /// Interrupt menu item in canvas or some other action).
80 
82 {
83  if (fTimeout) {
84  if (gSystem->ProcessEvents()) {
85  Remove();
86  return kTRUE;
87  } else {
88  Reset();
89  return kFALSE;
90  }
91  }
92  return kFALSE;
93 }
94 
95 
96 
98 
99 TVirtualMutex* gSystemMutex = 0;
100 
101 ////////////////////////////////////////////////////////////////////////////////
102 /// Create a new OS interface.
103 
104 TSystem::TSystem(const char *name, const char *title) : TNamed(name, title), fAclicProperties(0)
105 {
106  if (gSystem && name[0] != '-' && strcmp(name, "Generic"))
107  Error("TSystem", "only one instance of TSystem allowed");
108 
109  fOnExitList = 0;
110  fSignalHandler = 0;
111  fFileHandler = 0;
112  fStdExceptionHandler = 0;
113  fTimers = 0;
114  fCompiled = 0;
115  fHelpers = 0;
116  fInsideNotify = kFALSE;
117  fBeepDuration = 0;
118  fBeepFreq = 0;
119  fReadmask = 0;
120  fWritemask = 0;
121  fReadready = 0;
122  fWriteready = 0;
123  fSignals = 0;
124  fDone = kFALSE;
125  fAclicMode = kDefault;
126  fInControl = kFALSE;
127  fLevel = 0;
128  fMaxrfd = -1;
129  fMaxwfd = -1;
130  fNfd = 0;
131  fSigcnt = 0;
132 
133  if (!gLibraryVersion) {
134  gLibraryVersion = new Int_t [gLibraryVersionMax];
135  memset(gLibraryVersion, 0, gLibraryVersionMax*sizeof(Int_t));
136  }
137 }
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 /// Delete the OS interface.
141 
143 {
144  if (fOnExitList) {
145  fOnExitList->Delete();
146  SafeDelete(fOnExitList);
147  }
148 
149  if (fSignalHandler) {
150  fSignalHandler->Delete();
151  SafeDelete(fSignalHandler);
152  }
153 
154  if (fFileHandler) {
155  fFileHandler->Delete();
156  SafeDelete(fFileHandler);
157  }
158 
159  if (fStdExceptionHandler) {
160  fStdExceptionHandler->Delete();
161  SafeDelete(fStdExceptionHandler);
162  }
163 
164  if (fTimers) {
165  fTimers->Delete();
166  SafeDelete(fTimers);
167  }
168 
169  if (fCompiled) {
170  fCompiled->Delete();
171  SafeDelete(fCompiled);
172  }
173 
174  if (fHelpers) {
175  fHelpers->Delete();
176  SafeDelete(fHelpers);
177  }
178 
179  if (gSystem == this)
180  gSystem = 0;
181 }
182 
183 ////////////////////////////////////////////////////////////////////////////////
184 /// Initialize the OS interface.
185 
187 {
188  fNfd = 0;
189  fMaxrfd = -1;
190  fMaxwfd = -1;
191 
192  fSigcnt = 0;
193  fLevel = 0;
194 
195  fSignalHandler = new TOrdCollection;
196  fFileHandler = new TOrdCollection;
197  fStdExceptionHandler = new TOrdCollection;
198  fTimers = new TOrdCollection;
199 
200  fBuildArch = BUILD_ARCH;
201  fBuildCompiler = COMPILER;
202  fBuildCompilerVersion = COMPILERVERS;
203  fBuildNode = BUILD_NODE;
204  fFlagsDebug = CXXDEBUG;
205  fFlagsOpt = CXXOPT;
206  fIncludePath = INCLUDEPATH;
207  fLinkedLibs = LINKEDLIBS;
208  fSoExt = SOEXT;
209  fObjExt = OBJEXT;
210  fAclicMode = kDefault;
211  fMakeSharedLib = MAKESHAREDLIB;
212  fMakeExe = MAKEEXE;
213  fCompiled = new TOrdCollection;
214 
215  if (gEnv && fBeepDuration == 0 && fBeepFreq == 0) {
216  fBeepDuration = gEnv->GetValue("Root.System.BeepDuration", 100);
217  fBeepFreq = gEnv->GetValue("Root.System.BeepFreq", 440);
218  }
219  if (!fName.CompareTo("Generic")) return kTRUE;
220  return kFALSE;
221 }
222 
223 ////////////////////////////////////////////////////////////////////////////////
224 /// Set the application name (from command line, argv[0]) and copy it in
225 /// gProgName.
226 
227 void TSystem::SetProgname(const char *name)
228 {
229  gProgName = StrDup(name);
230 }
231 
232 ////////////////////////////////////////////////////////////////////////////////
233 /// Set DISPLAY environment variable based on utmp entry. Only for UNIX.
234 
236 {
237 }
238 
239 ////////////////////////////////////////////////////////////////////////////////
240 /// Set the system error string. This string will be used by GetError().
241 /// To be used in case one does not want or can use the system error
242 /// string (e.g. because error is generated by a third party POSIX like
243 /// library that does not use standard errno).
244 
245 void TSystem::SetErrorStr(const char *errstr)
246 {
247  ResetErrno(); // so GetError() uses the fLastErrorString
248  GetLastErrorString() = errstr;
249 }
250 
251 ////////////////////////////////////////////////////////////////////////////////
252 /// Return system error string.
253 
254 const char *TSystem::GetError()
255 {
256  if (GetErrno() == 0 && GetLastErrorString() != "")
257  return GetLastErrorString();
258  return Form("errno: %d", GetErrno());
259 }
260 
261 ////////////////////////////////////////////////////////////////////////////////
262 /// Static function returning system error number.
263 
265 {
266 #ifdef _REENTRANT
267  return errno; // errno can be a macro if _REENTRANT is set
268 #else
269 #ifdef R__SOLARIS_CC50
270  return ::errno;
271 #else
272  return errno;
273 #endif
274 #endif
275 }
276 
277 ////////////////////////////////////////////////////////////////////////////////
278 /// Static function resetting system error number.
279 
281 {
282 #ifdef _REENTRANT
283  errno = 0; // errno can be a macro if _REENTRANT is set
284 #else
285 #ifdef R__SOLARIS_CC50
286  ::errno = 0;
287 #else
288  errno = 0;
289 #endif
290 #endif
291 }
292 
293 ////////////////////////////////////////////////////////////////////////////////
294 /// Objects that should be deleted on exit of the OS interface.
295 
297 {
298  if (fOnExitList == 0)
299  fOnExitList = new TOrdCollection;
300  if (fOnExitList->FindObject(obj) == 0)
301  fOnExitList->Add(obj);
302 }
303 
304 ////////////////////////////////////////////////////////////////////////////////
305 /// Return the system's host name.
306 
307 const char *TSystem::HostName()
308 {
309  return "Local host";
310 }
311 
312 ////////////////////////////////////////////////////////////////////////////////
313 /// Hook to tell TSystem that the TApplication object has been created.
314 
316 {
317  // Currently needed only for WinNT interface.
318 }
319 
320 ////////////////////////////////////////////////////////////////////////////////
321 /// Beep for duration milliseconds with a tone of frequency freq.
322 /// Defaults to printing the `\a` character to stdout.
323 /// If freq or duration is <0 respectively, use default value.
324 /// If setDefault is set, only set the frequency and duration as
325 /// new defaults, but don't beep.
326 /// If default freq or duration is <0, never beep (silence)
327 
328 void TSystem::Beep(Int_t freq /*=-1*/, Int_t duration /*=-1*/,
329  Bool_t setDefault /*=kFALSE*/)
330 {
331  if (setDefault) {
332  fBeepFreq = freq;
333  fBeepDuration = duration;
334  return;
335  }
336  if (fBeepDuration < 0 || fBeepFreq < 0) return; // silence
337  if (freq < 0) freq = fBeepFreq;
338  if (duration < 0) duration = fBeepDuration;
339  DoBeep(freq, duration);
340 }
341 
342 //---- EventLoop ---------------------------------------------------------------
343 
344 ////////////////////////////////////////////////////////////////////////////////
345 /// System event loop.
346 
348 {
349  fInControl = kTRUE;
350  fDone = kFALSE;
351 
352 loop_entry:
353  try {
354  RETRY {
355  while (!fDone) {
357  InnerLoop();
359  }
360  } ENDTRY;
361  }
362  catch (std::exception& exc) {
363  TIter next(fStdExceptionHandler);
364  TStdExceptionHandler* eh = 0;
365  while ((eh = (TStdExceptionHandler*) next())) {
366  switch (eh->Handle(exc))
367  {
369  break;
371  goto loop_entry;
372  break;
374  Warning("Run", "instructed to abort");
375  goto loop_end;
376  break;
377  }
378  }
379  throw;
380  }
381  catch (const char *str) {
382  printf("%s\n", str);
383  }
384  // handle every exception
385  catch (...) {
386  Warning("Run", "handle uncaugth exception, terminating");
387  }
388 
389 loop_end:
390  fInControl = kFALSE;
391 }
392 
393 ////////////////////////////////////////////////////////////////////////////////
394 /// Exit from event loop.
395 
397 {
398  fDone = kTRUE;
399 }
400 
401 ////////////////////////////////////////////////////////////////////////////////
402 /// Inner event loop.
403 
405 {
406  fLevel++;
407  DispatchOneEvent();
408  fLevel--;
409 }
410 
411 ////////////////////////////////////////////////////////////////////////////////
412 /// Process pending events (GUI, timers, sockets). Returns the result of
413 /// TROOT::IsInterrupted(). The interrupt flag (TROOT::SetInterrupt())
414 /// can be set during the handling of the events. This mechanism allows
415 /// macros running in tight calculating loops to be interrupted by some
416 /// GUI event (depending on the interval with which this method is
417 /// called). For example hitting ctrl-c in a canvas will set the
418 /// interrupt flag.
419 
421 {
422  gROOT->SetInterrupt(kFALSE);
423 
424  if (!gROOT->TestBit(TObject::kInvalidObject))
425  DispatchOneEvent(kTRUE);
426 
427  return gROOT->IsInterrupted();
428 }
429 
430 ////////////////////////////////////////////////////////////////////////////////
431 /// Dispatch a single event.
432 
434 {
435  AbstractMethod("DispatchOneEvent");
436 }
437 
438 ////////////////////////////////////////////////////////////////////////////////
439 /// Sleep milliSec milli seconds.
440 
442 {
443  AbstractMethod("Sleep");
444 }
445 
446 ////////////////////////////////////////////////////////////////////////////////
447 /// Select on active file descriptors (called by TMonitor).
448 
450 {
451  AbstractMethod("Select");
452  return -1;
453 }
454 ////////////////////////////////////////////////////////////////////////////////
455 /// Select on active file descriptors (called by TMonitor).
456 
458 {
459  AbstractMethod("Select");
460  return -1;
461 }
462 
463 //---- handling of system events -----------------------------------------------
464 ////////////////////////////////////////////////////////////////////////////////
465 /// Get current time in milliseconds since 0:00 Jan 1 1995.
466 
468 {
469  return TTime(0);
470 }
471 
472 ////////////////////////////////////////////////////////////////////////////////
473 /// Add timer to list of system timers.
474 
476 {
477  if (ti && fTimers && (fTimers->FindObject(ti) == 0))
478  fTimers->Add(ti);
479 }
480 
481 ////////////////////////////////////////////////////////////////////////////////
482 /// Remove timer from list of system timers. Returns removed timer or 0
483 /// if timer was not active.
484 
486 {
487  if (fTimers) {
488  TTimer *tr = (TTimer*) fTimers->Remove(ti);
489  return tr;
490  }
491  return 0;
492 }
493 
494 ////////////////////////////////////////////////////////////////////////////////
495 /// Time when next timer of mode (synchronous=kTRUE or
496 /// asynchronous=kFALSE) will time-out (in ms).
497 
499 {
500  if (!fTimers) return -1;
501 
502  TOrdCollectionIter it((TOrdCollection*)fTimers);
503  TTimer *t, *to = 0;
504  Long64_t tt, tnow = Now();
505  Long_t timeout = -1;
506 
507  while ((t = (TTimer *) it.Next())) {
508  if (t->IsSync() == mode) {
509  tt = (Long64_t)t->GetAbsTime() - tnow;
510  if (tt < 0) tt = 0;
511  if (timeout == -1) {
512  timeout = (Long_t)tt;
513  to = t;
514  }
515  if (tt < timeout) {
516  timeout = (Long_t)tt;
517  to = t;
518  }
519  }
520  }
521 
522  if (to && to->IsAsync() && timeout > 0) {
523  if (to->IsInterruptingSyscalls())
524  SigAlarmInterruptsSyscalls(kTRUE);
525  else
526  SigAlarmInterruptsSyscalls(kFALSE);
527  }
528 
529  return timeout;
530 }
531 
532 ////////////////////////////////////////////////////////////////////////////////
533 /// Add a signal handler to list of system signal handlers. Only adds
534 /// the handler if it is not already in the list of signal handlers.
535 
537 {
538  if (h && fSignalHandler && (fSignalHandler->FindObject(h) == 0))
539  fSignalHandler->Add(h);
540 }
541 
542 ////////////////////////////////////////////////////////////////////////////////
543 /// Remove a signal handler from list of signal handlers. Returns
544 /// the handler or 0 if the handler was not in the list of signal handlers.
545 
547 {
548  if (fSignalHandler)
549  return (TSignalHandler *)fSignalHandler->Remove(h);
550 
551  return 0;
552 }
553 
554 ////////////////////////////////////////////////////////////////////////////////
555 /// Add a file handler to the list of system file handlers. Only adds
556 /// the handler if it is not already in the list of file handlers.
557 
559 {
560  if (h && fFileHandler && (fFileHandler->FindObject(h) == 0))
561  fFileHandler->Add(h);
562 }
563 
564 ////////////////////////////////////////////////////////////////////////////////
565 /// Remove a file handler from the list of file handlers. Returns
566 /// the handler or 0 if the handler was not in the list of file handlers.
567 
569 {
570  if (fFileHandler)
571  return (TFileHandler *)fFileHandler->Remove(h);
572 
573  return 0;
574 }
575 
576 ////////////////////////////////////////////////////////////////////////////////
577 /// If reset is true reset the signal handler for the specified signal
578 /// to the default handler, else restore previous behaviour.
579 
580 void TSystem::ResetSignal(ESignals /*sig*/, Bool_t /*reset*/)
581 {
582  AbstractMethod("ResetSignal");
583 }
584 
585 ////////////////////////////////////////////////////////////////////////////////
586 /// Reset signals handlers to previous behaviour.
587 
589 {
590  AbstractMethod("ResetSignals");
591 }
592 
593 ////////////////////////////////////////////////////////////////////////////////
594 /// If ignore is true ignore the specified signal, else restore previous
595 /// behaviour.
596 
597 void TSystem::IgnoreSignal(ESignals /*sig*/, Bool_t /*ignore*/)
598 {
599  AbstractMethod("IgnoreSignal");
600 }
601 
602 ////////////////////////////////////////////////////////////////////////////////
603 /// If ignore is true ignore the interrupt signal, else restore previous
604 /// behaviour. Typically call ignore interrupt before writing to disk.
605 
607 {
608  IgnoreSignal(kSigInterrupt, ignore);
609 }
610 
611 ////////////////////////////////////////////////////////////////////////////////
612 /// Add an exception handler to list of system exception handlers. Only adds
613 /// the handler if it is not already in the list of exception handlers.
614 
616 {
617  if (eh && fStdExceptionHandler && (fStdExceptionHandler->FindObject(eh) == 0))
618  fStdExceptionHandler->Add(eh);
619 }
620 
621 ////////////////////////////////////////////////////////////////////////////////
622 /// Remove an exception handler from list of exception handlers. Returns
623 /// the handler or 0 if the handler was not in the list of exception handlers.
624 
626 {
627  if (fStdExceptionHandler)
628  return (TStdExceptionHandler *)fStdExceptionHandler->Remove(eh);
629 
630  return 0;
631 }
632 
633 ////////////////////////////////////////////////////////////////////////////////
634 /// Return the bitmap of conditions that trigger a floating point exception.
635 
637 {
638  AbstractMethod("GetFPEMask");
639  return 0;
640 }
641 
642 ////////////////////////////////////////////////////////////////////////////////
643 /// Set which conditions trigger a floating point exception.
644 /// Return the previous set of conditions.
645 
647 {
648  AbstractMethod("SetFPEMask");
649  return 0;
650 }
651 
652 //---- Processes ---------------------------------------------------------------
653 
654 ////////////////////////////////////////////////////////////////////////////////
655 /// Execute a command.
656 
657 int TSystem::Exec(const char*)
658 {
659  AbstractMethod("Exec");
660  return -1;
661 }
662 
663 ////////////////////////////////////////////////////////////////////////////////
664 /// Open a pipe.
665 
666 FILE *TSystem::OpenPipe(const char*, const char*)
667 {
668  AbstractMethod("OpenPipe");
669  return 0;
670 }
671 
672 ////////////////////////////////////////////////////////////////////////////////
673 /// Close the pipe.
674 
676 {
677  AbstractMethod("ClosePipe");
678  return -1;
679 }
680 
681 ////////////////////////////////////////////////////////////////////////////////
682 /// Execute command and return output in TString.
683 
684 TString TSystem::GetFromPipe(const char *command)
685 {
686  TString out;
687 
688  FILE *pipe = OpenPipe(command, "r");
689  if (!pipe) {
690  SysError("GetFromPipe", "cannot run command \"%s\"", command);
691  return out;
692  }
693 
694  TString line;
695  while (line.Gets(pipe)) {
696  if (out != "")
697  out += "\n";
698  out += line;
699  }
700 
701  Int_t r = ClosePipe(pipe);
702  if (r) {
703  Error("GetFromPipe", "command \"%s\" returned %d", command, r);
704  }
705  return out;
706 }
707 
708 ////////////////////////////////////////////////////////////////////////////////
709 /// Get process id.
710 
712 {
713  AbstractMethod("GetPid");
714  return -1;
715 }
716 
717 ////////////////////////////////////////////////////////////////////////////////
718 /// Exit the application.
719 
721 {
722  AbstractMethod("Exit");
723 }
724 
725 ////////////////////////////////////////////////////////////////////////////////
726 /// Abort the application.
727 
728 void TSystem::Abort(int)
729 {
730  AbstractMethod("Abort");
731 }
732 
733 ////////////////////////////////////////////////////////////////////////////////
734 /// Print a stack trace.
735 
737 {
738  AbstractMethod("StackTrace");
739 }
740 
741 
742 //---- Directories -------------------------------------------------------------
743 
744 ////////////////////////////////////////////////////////////////////////////////
745 /// Create helper TSystem to handle file and directory operations that
746 /// might be special for remote file access, like via rfiod or rootd.
747 
748 TSystem *TSystem::FindHelper(const char *path, void *dirptr)
749 {
750  if (!fHelpers)
751  fHelpers = new TOrdCollection;
752 
753  TPluginHandler *h;
754  TSystem *helper = 0;
755  if (path) {
756  if (!GetDirPtr()) {
757  TUrl url(path, kTRUE);
758  if (!strcmp(url.GetProtocol(), "file"))
759  return 0;
760  }
761  }
762 
763  // look for existing helpers
764  TIter next(fHelpers);
765  while ((helper = (TSystem*) next()))
766  if (helper->ConsistentWith(path, dirptr))
767  return helper;
768 
769  if (!path)
770  return 0;
771 
772  // create new helper
773  TRegexp re("^root.*:"); // also roots, rootk, etc
774  TString pname = path;
775  if (pname.BeginsWith("xroot:") || pname.Index(re) != kNPOS) {
776  // (x)rootd daemon ...
777  if ((h = gROOT->GetPluginManager()->FindHandler("TSystem", path))) {
778  if (h->LoadPlugin() == -1)
779  return 0;
780  helper = (TSystem*) h->ExecPlugin(2, path, kFALSE);
781  }
782  } else if ((h = gROOT->GetPluginManager()->FindHandler("TSystem", path))) {
783  if (h->LoadPlugin() == -1)
784  return 0;
785  helper = (TSystem*) h->ExecPlugin(0);
786  }
787 
788  if (helper)
789  fHelpers->Add(helper);
790 
791  return helper;
792 }
793 
794 ////////////////////////////////////////////////////////////////////////////////
795 /// Check consistency of this helper with the one required
796 /// by 'path' or 'dirptr'
797 
798 Bool_t TSystem::ConsistentWith(const char *path, void *dirptr)
799 {
800  Bool_t checkproto = kFALSE;
801  if (path) {
802  if (!GetDirPtr()) {
803  TUrl url(path, kTRUE);
804  if (!strncmp(url.GetProtocol(), GetName(), strlen(GetName())))
805  checkproto = kTRUE;
806  }
807  }
808 
809  Bool_t checkdir = kFALSE;
810  if (GetDirPtr() && GetDirPtr() == dirptr)
811  checkdir = kTRUE;
812 
813  return (checkproto || checkdir);
814 }
815 
816 ////////////////////////////////////////////////////////////////////////////////
817 /// Make a directory. Returns 0 in case of success and
818 /// -1 if the directory could not be created (either already exists or
819 /// illegal path name).
820 
821 int TSystem::MakeDirectory(const char*)
822 {
823  AbstractMethod("MakeDirectory");
824  return 0;
825 }
826 
827 ////////////////////////////////////////////////////////////////////////////////
828 /// Open a directory. Returns 0 if directory does not exist.
829 
830 void *TSystem::OpenDirectory(const char*)
831 {
832  AbstractMethod("OpenDirectory");
833  return 0;
834 }
835 
836 ////////////////////////////////////////////////////////////////////////////////
837 /// Free a directory.
838 
840 {
841  AbstractMethod("FreeDirectory");
842 }
843 
844 ////////////////////////////////////////////////////////////////////////////////
845 /// Get a directory entry. Returns 0 if no more entries.
846 
847 const char *TSystem::GetDirEntry(void*)
848 {
849  AbstractMethod("GetDirEntry");
850  return 0;
851 }
852 
853 ////////////////////////////////////////////////////////////////////////////////
854 /// Change directory.
855 
857 {
858  AbstractMethod("ChangeDirectory");
859  return kFALSE;
860 }
861 
862 ////////////////////////////////////////////////////////////////////////////////
863 /// Return working directory.
864 
866 {
867  return 0;
868 }
869 
870 //////////////////////////////////////////////////////////////////////////////
871 /// Return working directory.
872 
873 std::string TSystem::GetWorkingDirectory() const
874 {
875  return std::string();
876 }
877 
878 ////////////////////////////////////////////////////////////////////////////////
879 /// Return the user's home directory.
880 
881 const char *TSystem::HomeDirectory(const char*)
882 {
883  return 0;
884 }
885 
886 //////////////////////////////////////////////////////////////////////////////
887 /// Return the user's home directory.
888 
889 std::string TSystem::GetHomeDirectory(const char*) const
890 {
891  return std::string();
892 }
893 
894 ////////////////////////////////////////////////////////////////////////////////
895 /// Make a file system directory. Returns 0 in case of success and
896 /// -1 if the directory could not be created (either already exists or
897 /// illegal path name).
898 /// If 'recursive' is true, makes parent directories as needed.
899 
900 int TSystem::mkdir(const char *name, Bool_t recursive)
901 {
902  if (recursive) {
903  TString safeName = name; // local copy in case 'name' is output from
904  // TSystem::DirName as it uses static buffers
905  TString dirname = DirName(safeName);
906  if (!dirname.Length()) {
907  // well we should not have to make the root of the file system!
908  // (and this avoid infinite recursions!)
909  return -1;
910  }
911  if (AccessPathName(dirname, kFileExists)) {
912  int res = mkdir(dirname, kTRUE);
913  if (res) return res;
914  }
915  if (!AccessPathName(safeName, kFileExists)) {
916  return -1;
917  }
918  }
919 
920  return MakeDirectory(name);
921 }
922 
923 //---- Paths & Files -----------------------------------------------------------
924 
925 ////////////////////////////////////////////////////////////////////////////////
926 /// Base name of a file name. Base name of /user/root is root.
927 
928 const char *TSystem::BaseName(const char *name)
929 {
930  if (name) {
931  if (name[0] == '/' && name[1] == '\0')
932  return name;
933  char *cp;
934  if ((cp = (char*)strrchr(name, '/')))
935  return ++cp;
936  return name;
937  }
938  Error("BaseName", "name = 0");
939  return 0;
940 }
941 
942 ////////////////////////////////////////////////////////////////////////////////
943 /// Return true if dir is an absolute pathname.
944 
946 {
947  if (dir)
948  return dir[0] == '/';
949  return kFALSE;
950 }
951 
952 ////////////////////////////////////////////////////////////////////////////////
953 /// Return true if 'name' is a file that can be found in the ROOT include
954 /// path or the current directory.
955 /// If 'name' contains any ACLiC style information (e.g. trailing +[+][g|O]),
956 /// it will be striped off 'name'.
957 /// If fullpath is != 0, the full path to the file is returned in *fullpath,
958 /// which must be deleted by the caller.
959 
960 Bool_t TSystem::IsFileInIncludePath(const char *name, char **fullpath)
961 {
962  if (!name || !name[0]) return kFALSE;
963 
964  TString aclicMode;
965  TString arguments;
966  TString io;
967  TString realname = SplitAclicMode(name, aclicMode, arguments, io);
968 
969  TString fileLocation = DirName(realname);
970 
971  TString incPath = gSystem->GetIncludePath(); // of the form -Idir1 -Idir2 -Idir3
972  incPath.Append(":").Prepend(" ");
973  incPath.ReplaceAll(" -I",":"); // of form :dir1 :dir2:dir3
974  while ( incPath.Index(" :") != -1 ) {
975  incPath.ReplaceAll(" :",":");
976  }
977  incPath.Prepend(fileLocation+":.:");
978 
979  char *actual = Which(incPath,realname);
980 
981  if (!actual) {
982  return kFALSE;
983  } else {
984  if (fullpath)
985  *fullpath = actual;
986  else
987  delete [] actual;
988  return kTRUE;
989  }
990 }
991 
992 ////////////////////////////////////////////////////////////////////////////////
993 /// Return the directory name in pathname. DirName of /user/root is /user.
994 /// In case no dirname is specified "." is returned.
995 
996 const char *TSystem::DirName(const char *pathname)
997 {
998  if (pathname && strchr(pathname, '/')) {
999  R__LOCKGUARD2(gSystemMutex);
1000 
1001  static int len = 0;
1002  static char *buf = 0;
1003  int pathlen = strlen(pathname);
1004  if (pathlen > len) {
1005  delete [] buf;
1006  len = pathlen;
1007  buf = new char [len+1];
1008  }
1009  strcpy(buf, pathname);
1010 
1011  char *r = buf+pathlen-1;
1012  // First skip the trailing '/'
1013  while ( r>buf && *(r)=='/') { --r; }
1014  // Then find the next non slash
1015  while ( r>buf && *(r)!='/') { --r; }
1016  // Then skip duplicate slashes
1017  // Note the 'r>buf' is a strict comparison to allows '/topdir' to return '/'
1018  while ( r>buf && *(r)=='/') { --r; }
1019  // If all was cut away, we encountered a rel. path like 'subdir/'
1020  // and ended up at '.'.
1021  if (r==buf && *(r)!='/') {
1022  return ".";
1023  }
1024  // And finally terminate the string to drop off the filename
1025  *(r+1) = '\0';
1026 
1027  return buf;
1028  }
1029  return ".";
1030 }
1031 
1032 ////////////////////////////////////////////////////////////////////////////////
1033 /// Convert from a Unix pathname to a local pathname. E.g. from `/user/root` to
1034 /// `\user\root`.
1035 
1036 const char *TSystem::UnixPathName(const char *name)
1037 {
1038  return name;
1039 }
1040 
1041 ////////////////////////////////////////////////////////////////////////////////
1042 /// Concatenate a directory and a file name. User must delete returned string.
1043 
1044 char *TSystem::ConcatFileName(const char *dir, const char *name)
1045 {
1046  TString nameString(name);
1047  PrependPathName(dir, nameString);
1048  return StrDup(nameString.Data());
1049 }
1050 
1051 ////////////////////////////////////////////////////////////////////////////////
1052 /// Concatenate a directory and a file name.
1053 
1054 const char *TSystem::PrependPathName(const char *, TString&)
1055 {
1056  AbstractMethod("PrependPathName");
1057  return 0;
1058 }
1059 
1060 
1061 //---- Paths & Files -----------------------------------------------------------
1062 
1063 ////////////////////////////////////////////////////////////////////////////////
1064 /// Expand a pathname getting rid of special shell characters like ~.$, etc.
1065 /// For Unix/Win32 compatibility use $(XXX) instead of $XXX when using
1066 /// environment variables in a pathname. If compatibility is not an issue
1067 /// you can use on Unix directly $XXX. This is a protected function called
1068 /// from the OS specific system classes, like TUnixSystem and TWinNTSystem.
1069 /// Returns the expanded filename or 0 in case of error.
1070 
1071 const char *TSystem::ExpandFileName(const char *fname)
1072 {
1073  const int kBufSize = kMAXPATHLEN;
1074  TTHREAD_TLS_ARRAY(char, kBufSize, xname);
1075 
1076  Bool_t res = ExpandFileName(fname, xname, kBufSize);
1077  if (res)
1078  return nullptr;
1079  else
1080  return xname;
1081 }
1082 
1083 //////////////////////////////////////////////////////////////////////////////
1084 /// Expand a pathname getting rid of special shell characters like ~.$, etc.
1085 /// This function is analogous to ExpandFileName(const char *), except that
1086 /// it receives a TString reference of the pathname to be expanded.
1087 /// Returns kTRUE in case of error and kFALSE otherwise.
1088 
1090 {
1091  const int kBufSize = kMAXPATHLEN;
1092  char xname[kBufSize];
1093 
1094  Bool_t res = ExpandFileName(fname.Data(), xname, kBufSize);
1095  if (!res)
1096  fname = xname;
1097 
1098  return res;
1099 }
1100 
1101 ////////////////////////////////////////////////////////////////////////////
1102 /// Private method for pathname expansion.
1103 /// Returns kTRUE in case of error and kFALSE otherwise.
1104 
1105 Bool_t TSystem::ExpandFileName(const char *fname, char *xname, const int kBufSize)
1106 {
1107  int n, ier, iter, lx, ncopy;
1108  char *inp, *out, *x, *t, buff[kBufSize*4];
1109  const char *b, *c, *e;
1110  const char *p;
1111 
1112  iter = 0; xname[0] = 0; inp = buff + kBufSize; out = inp + kBufSize;
1113  inp[-1] = ' '; inp[0] = 0; out[-1] = ' ';
1114  c = fname + strspn(fname, " \t\f\r");
1115  //VP if (isalnum(c[0])) { strcpy(inp, WorkingDirectory()); strcat(inp, "/"); } // add $cwd
1116 
1117  strlcat(inp, c, kBufSize);
1118 
1119 again:
1120  iter++; c = inp; ier = 0;
1121  x = out; x[0] = 0;
1122 
1123  p = 0; e = 0;
1124  if (c[0] == '~' && c[1] == '/') { // ~/ case
1125  std::string hd = GetHomeDirectory();
1126  p = hd.c_str();
1127  e = c + 1;
1128  if (p) { // we have smth to copy
1129  strlcpy(x, p, kBufSize);
1130  x += strlen(p);
1131  c = e;
1132  } else {
1133  ++ier;
1134  ++c;
1135  }
1136  } else if (c[0] == '~' && c[1] != '/') { // ~user case
1137  n = strcspn(c+1, "/ ");
1138  buff[0] = 0;
1139  strncat(buff, c+1, n);
1140  std::string hd = GetHomeDirectory(buff);
1141  p = hd.c_str();
1142  e = c+1+n;
1143  if (p) { // we have smth to copy
1144  strlcpy(x, p, kBufSize);
1145  x += strlen(p);
1146  c = e;
1147  } else {
1148  ++ier;
1149  ++c;
1150  }
1151  }
1152 
1153  for ( ; c[0]; c++) {
1154 
1155  p = 0; e = 0;
1156 
1157  if (c[0] == '.' && c[1] == '/' && c[-1] == ' ') { // $cwd
1158  std::string wd = GetWorkingDirectory();
1159  strlcpy(buff, wd.c_str(), kBufSize);
1160  p = buff;
1161  e = c + 1;
1162  }
1163  if (p) { // we have smth to copy */
1164  strlcpy(x, p, kBufSize); x += strlen(p); c = e-1; continue;
1165  }
1166 
1167  if (c[0] != '$') { // not $, simple copy
1168  x++[0] = c[0];
1169  } else { // we have a $
1170  b = c+1;
1171  if (c[1] == '(') b++;
1172  if (c[1] == '{') b++;
1173  if (b[0] == '$')
1174  e = b+1;
1175  else
1176  for (e = b; isalnum(e[0]) || e[0] == '_'; e++) ;
1177  buff[0] = 0; strncat(buff, b, e-b);
1178  p = Getenv(buff);
1179  if (!p) { // too bad, try UPPER case
1180  for (t = buff; (t[0] = toupper(t[0])); t++) ;
1181  p = Getenv(buff);
1182  }
1183  if (!p) { // too bad, try Lower case
1184  for (t = buff; (t[0] = tolower(t[0])); t++) ;
1185  p = Getenv(buff);
1186  }
1187  if (!p && !strcmp(buff, "cwd")) { // it is $cwd
1188  std::string wd = GetWorkingDirectory();
1189  strlcpy(buff, wd.c_str(), kBufSize);
1190  p = buff;
1191  }
1192  if (!p && !strcmp(buff, "$")) { // it is $$ (replace by GetPid())
1193  snprintf(buff,kBufSize*4, "%d", GetPid());
1194  p = buff;
1195  }
1196  if (!p) { // too bad, nothing can help
1197 #ifdef WIN32
1198  // if we're on windows, we can have \\SomeMachine\C$ - don't
1199  // complain about that, if '$' is followed by nothing or a
1200  // path delimiter.
1201  if (c[1] && c[1]!='\\' && c[1]!=';' && c[1]!='/')
1202  ier++;
1203 #else
1204  ier++;
1205 #endif
1206  x++[0] = c[0];
1207  } else { // It is OK, copy result
1208  int lp = strlen(p);
1209  if (lp >= kBufSize) {
1210  // make sure lx will be >= kBufSize (see below)
1211  strlcpy(x, p, kBufSize);
1212  x += kBufSize;
1213  break;
1214  }
1215  strcpy(x,p);
1216  x += lp;
1217  c = (b==c+1) ? e-1 : e;
1218  }
1219  }
1220  }
1221 
1222  x[0] = 0; lx = x - out;
1223  if (ier && iter < 3) { strlcpy(inp, out, kBufSize); goto again; }
1224  ncopy = (lx >= kBufSize) ? kBufSize-1 : lx;
1225  xname[0] = 0; strncat(xname, out, ncopy);
1226 
1227  if (ier || ncopy != lx) {
1228  ::Error("TSystem::ExpandFileName", "input: %s, output: %s", fname, xname);
1229  return kTRUE;
1230  }
1231 
1232  return kFALSE;
1233 }
1234 
1235 
1236 ////////////////////////////////////////////////////////////////////////////////
1237 /// Expand a pathname getting rid of special shell characters like ~.$, etc.
1238 /// For Unix/Win32 compatibility use $(XXX) instead of $XXX when using
1239 /// environment variables in a pathname. If compatibility is not an issue
1240 /// you can use on Unix directly $XXX.
1241 
1243 {
1244  return kFALSE;
1245 }
1246 
1247 ////////////////////////////////////////////////////////////////////////////////
1248 /// Expand a pathname getting rid of special shell characters like ~.$, etc.
1249 /// For Unix/Win32 compatibility use $(XXX) instead of $XXX when using
1250 /// environment variables in a pathname. If compatibility is not an issue
1251 /// you can use on Unix directly $XXX. The user must delete returned string.
1252 
1253 char *TSystem::ExpandPathName(const char *)
1254 {
1255  return 0;
1256 }
1257 
1258 ////////////////////////////////////////////////////////////////////////////////
1259 /// Returns FALSE if one can access a file using the specified access mode.
1260 /// The file name must not contain any special shell characters line ~ or $,
1261 /// in those cases first call ExpandPathName().
1262 /// Attention, bizarre convention of return value!!
1263 
1265 {
1266  return kFALSE;
1267 }
1268 
1269 ////////////////////////////////////////////////////////////////////////////////
1270 /// Returns TRUE if the url in 'path' points to the local file system.
1271 /// This is used to avoid going through the NIC card for local operations.
1272 
1273 Bool_t TSystem::IsPathLocal(const char *path)
1274 {
1275  Bool_t localPath = kTRUE;
1276 
1277  TUrl url(path);
1278  if (strlen(url.GetHost()) > 0) {
1279  // Check locality
1280  localPath = kFALSE;
1281  TInetAddress a(gSystem->GetHostByName(url.GetHost()));
1282  TInetAddress b(gSystem->GetHostByName(gSystem->HostName()));
1283  if (!strcmp(a.GetHostName(), b.GetHostName()) ||
1284  !strcmp(a.GetHostAddress(), b.GetHostAddress())) {
1285  // Host OK
1286  localPath = kTRUE;
1287  // Check the user if specified
1288  if (strlen(url.GetUser()) > 0) {
1289  UserGroup_t *u = gSystem->GetUserInfo();
1290  if (u) {
1291  if (strcmp(u->fUser, url.GetUser()))
1292  // Requested a different user
1293  localPath = kFALSE;
1294  delete u;
1295  }
1296  }
1297  }
1298  }
1299  // Done
1300  return localPath;
1301 }
1302 
1303 ////////////////////////////////////////////////////////////////////////////////
1304 /// Copy a file. If overwrite is true and file already exists the
1305 /// file will be overwritten. Returns 0 when successful, -1 in case
1306 /// of file open failure, -2 in case the file already exists and overwrite
1307 /// was false and -3 in case of error during copy.
1308 
1309 int TSystem::CopyFile(const char *, const char *, Bool_t)
1310 {
1311  AbstractMethod("CopyFile");
1312  return -1;
1313 }
1314 
1315 ////////////////////////////////////////////////////////////////////////////////
1316 /// Rename a file.
1317 
1318 int TSystem::Rename(const char *, const char *)
1319 {
1320  AbstractMethod("Rename");
1321  return -1;
1322 }
1323 
1324 ////////////////////////////////////////////////////////////////////////////////
1325 /// Create a link from file1 to file2.
1326 
1327 int TSystem::Link(const char *, const char *)
1328 {
1329  AbstractMethod("Link");
1330  return -1;
1331 }
1332 
1333 ////////////////////////////////////////////////////////////////////////////////
1334 /// Create a symbolic link from file1 to file2.
1335 
1336 int TSystem::Symlink(const char *, const char *)
1337 {
1338  AbstractMethod("Symlink");
1339  return -1;
1340 }
1341 
1342 ////////////////////////////////////////////////////////////////////////////////
1343 /// Unlink, i.e. remove, a file.
1344 
1345 int TSystem::Unlink(const char *)
1346 {
1347  AbstractMethod("Unlink");
1348  return -1;
1349 }
1350 
1351 ////////////////////////////////////////////////////////////////////////////////
1352 /// Get info about a file: id, size, flags, modification time.
1353 /// - Id is (statbuf.st_dev << 24) + statbuf.st_ino
1354 /// - Size is the file size
1355 /// - Flags is file type: 0 is regular file, bit 0 set executable,
1356 /// bit 1 set directory, bit 2 set special file
1357 /// (socket, fifo, pipe, etc.)
1358 /// Modtime is modification time.
1359 /// The function returns 0 in case of success and 1 if the file could
1360 /// not be stat'ed.
1361 
1362 int TSystem::GetPathInfo(const char *path, Long_t *id, Long_t *size,
1363  Long_t *flags, Long_t *modtime)
1364 {
1365  Long64_t lsize;
1366 
1367  int res = GetPathInfo(path, id, &lsize, flags, modtime);
1368 
1369  if (res == 0 && size) {
1370  if (sizeof(Long_t) == 4 && lsize > kMaxInt) {
1371  Error("GetPathInfo", "file %s > 2 GB, use GetPathInfo() with Long64_t size", path);
1372  *size = kMaxInt;
1373  } else {
1374  *size = (Long_t)lsize;
1375  }
1376  }
1377 
1378  return res;
1379 }
1380 
1381 ////////////////////////////////////////////////////////////////////////////////
1382 /// Get info about a file: id, size, flags, modification time.
1383 /// - Id is (statbuf.st_dev << 24) + statbuf.st_ino
1384 /// - Size is the file size
1385 /// - Flags is file type: 0 is regular file, bit 0 set executable,
1386 /// bit 1 set directory, bit 2 set special file
1387 /// (socket, fifo, pipe, etc.)
1388 /// Modtime is modification time.
1389 /// The function returns 0 in case of success and 1 if the file could
1390 /// not be stat'ed.
1391 
1392 int TSystem::GetPathInfo(const char *path, Long_t *id, Long64_t *size,
1393  Long_t *flags, Long_t *modtime)
1394 {
1395  FileStat_t buf;
1396 
1397  int res = GetPathInfo(path, buf);
1398 
1399  if (res == 0) {
1400  if (id)
1401  *id = (buf.fDev << 24) + buf.fIno;
1402  if (size)
1403  *size = buf.fSize;
1404  if (modtime)
1405  *modtime = buf.fMtime;
1406  if (flags) {
1407  *flags = 0;
1408  if (buf.fMode & (kS_IXUSR|kS_IXGRP|kS_IXOTH))
1409  *flags |= 1;
1410  if (R_ISDIR(buf.fMode))
1411  *flags |= 2;
1412  if (!R_ISREG(buf.fMode) && !R_ISDIR(buf.fMode))
1413  *flags |= 4;
1414  }
1415  }
1416 
1417  return res;
1418 }
1419 
1420 ////////////////////////////////////////////////////////////////////////////////
1421 /// Get info about a file. Info is returned in the form of a FileStat_t
1422 /// structure (see TSystem.h).
1423 /// The function returns 0 in case of success and 1 if the file could
1424 /// not be stat'ed.
1425 
1426 int TSystem::GetPathInfo(const char *, FileStat_t &)
1427 {
1428  AbstractMethod("GetPathInfo(const char*, FileStat_t&)");
1429  return 1;
1430 }
1431 
1432 ////////////////////////////////////////////////////////////////////////////////
1433 /// Get info about a file system: fs type, block size, number of blocks,
1434 /// number of free blocks.
1435 
1436 int TSystem::GetFsInfo(const char *, Long_t *, Long_t *, Long_t *, Long_t *)
1437 {
1438  AbstractMethod("GetFsInfo");
1439  return 1;
1440 }
1441 
1442 ////////////////////////////////////////////////////////////////////////////////
1443 /// Return a user configured or systemwide directory to create
1444 /// temporary files in.
1445 
1446 const char *TSystem::TempDirectory() const
1447 {
1448  AbstractMethod("TempDirectory");
1449  return 0;
1450 }
1451 
1452 ////////////////////////////////////////////////////////////////////////////////
1453 /// Create a secure temporary file by appending a unique
1454 /// 6 letter string to base. The file will be created in
1455 /// a standard (system) directory or in the directory
1456 /// provided in dir. The full filename is returned in base
1457 /// and a filepointer is returned for safely writing to the file
1458 /// (this avoids certain security problems). Returns 0 in case
1459 /// of error.
1460 
1461 FILE *TSystem::TempFileName(TString &, const char *)
1462 {
1463  AbstractMethod("TempFileName");
1464  return 0;
1465 }
1466 
1467 ////////////////////////////////////////////////////////////////////////////////
1468 /// Set the file permission bits. Returns -1 in case or error, 0 otherwise.
1469 
1470 int TSystem::Chmod(const char *, UInt_t)
1471 {
1472  AbstractMethod("Chmod");
1473  return -1;
1474 }
1475 
1476 ////////////////////////////////////////////////////////////////////////////////
1477 /// Set the process file creation mode mask.
1478 
1480 {
1481  AbstractMethod("Umask");
1482  return -1;
1483 }
1484 
1485 ////////////////////////////////////////////////////////////////////////////////
1486 /// Set the a files modification and access times. If actime = 0 it will be
1487 /// set to the modtime. Returns 0 on success and -1 in case of error.
1488 
1489 int TSystem::Utime(const char *, Long_t, Long_t)
1490 {
1491  AbstractMethod("Utime");
1492  return -1;
1493 }
1494 
1495 ////////////////////////////////////////////////////////////////////////////////
1496 /// Find location of file in a search path. Return value points to TString for
1497 /// compatibility with Which(const char *, const char *, EAccessMode).
1498 /// Returns 0 in case file is not found.
1499 
1500 const char *TSystem::FindFile(const char *, TString&, EAccessMode)
1501 {
1502  AbstractMethod("FindFile");
1503  return 0;
1504 }
1505 
1506 ////////////////////////////////////////////////////////////////////////////////
1507 /// Find location of file in a search path. User must delete returned string.
1508 /// Returns 0 in case file is not found.
1509 
1510 char *TSystem::Which(const char *search, const char *wfil, EAccessMode mode)
1511 {
1512  TString wfilString(wfil);
1513  FindFile(search, wfilString, mode);
1514  if (wfilString.IsNull()) return 0;
1515  return StrDup(wfilString.Data());
1516 }
1517 
1518 //---- Users & Groups ----------------------------------------------------------
1519 
1520 ////////////////////////////////////////////////////////////////////////////////
1521 /// Returns the user's id. If user = 0, returns current user's id.
1522 
1523 Int_t TSystem::GetUid(const char * /*user*/)
1524 {
1525  AbstractMethod("GetUid");
1526  return 0;
1527 }
1528 
1529 ////////////////////////////////////////////////////////////////////////////////
1530 /// Returns the effective user id. The effective id corresponds to the
1531 /// set id bit on the file being executed.
1532 
1534 {
1535  AbstractMethod("GetEffectiveUid");
1536  return 0;
1537 }
1538 
1539 ////////////////////////////////////////////////////////////////////////////////
1540 /// Returns the group's id. If group = 0, returns current user's group.
1541 
1542 Int_t TSystem::GetGid(const char * /*group*/)
1543 {
1544  AbstractMethod("GetGid");
1545  return 0;
1546 }
1547 
1548 ////////////////////////////////////////////////////////////////////////////////
1549 /// Returns the effective group id. The effective group id corresponds
1550 /// to the set id bit on the file being executed.
1551 
1553 {
1554  AbstractMethod("GetEffectiveGid");
1555  return 0;
1556 }
1557 
1558 ////////////////////////////////////////////////////////////////////////////////
1559 /// Returns all user info in the UserGroup_t structure. The returned
1560 /// structure must be deleted by the user. In case of error 0 is returned.
1561 
1563 {
1564  AbstractMethod("GetUserInfo");
1565  return 0;
1566 }
1567 
1568 ////////////////////////////////////////////////////////////////////////////////
1569 /// Returns all user info in the UserGroup_t structure. If user = 0, returns
1570 /// current user's id info. The returned structure must be deleted by the
1571 /// user. In case of error 0 is returned.
1572 
1573 UserGroup_t *TSystem::GetUserInfo(const char * /*user*/)
1574 {
1575  AbstractMethod("GetUserInfo");
1576  return 0;
1577 }
1578 
1579 ////////////////////////////////////////////////////////////////////////////////
1580 /// Returns all group info in the UserGroup_t structure. The only active
1581 /// fields in the UserGroup_t structure for this call are:
1582 /// - fGid and fGroup
1583 /// The returned structure must be deleted by the user. In case of
1584 /// error 0 is returned.
1585 
1587 {
1588  AbstractMethod("GetGroupInfo");
1589  return 0;
1590 }
1591 
1592 ////////////////////////////////////////////////////////////////////////////////
1593 /// Returns all group info in the UserGroup_t structure. The only active
1594 /// fields in the UserGroup_t structure for this call are:
1595 /// - fGid and fGroup
1596 /// If group = 0, returns current user's group. The returned structure
1597 /// must be deleted by the user. In case of error 0 is returned.
1598 
1599 UserGroup_t *TSystem::GetGroupInfo(const char * /*group*/)
1600 {
1601  AbstractMethod("GetGroupInfo");
1602  return 0;
1603 }
1604 
1605 //---- environment manipulation ------------------------------------------------
1606 
1607 ////////////////////////////////////////////////////////////////////////////////
1608 /// Set environment variable.
1609 
1610 void TSystem::Setenv(const char*, const char*)
1611 {
1612  AbstractMethod("Setenv");
1613 }
1614 
1615 ////////////////////////////////////////////////////////////////////////////////
1616 /// Unset environment variable.
1617 
1618 void TSystem::Unsetenv(const char *name)
1619 {
1620  Setenv(name, "");
1621 }
1622 
1623 ////////////////////////////////////////////////////////////////////////////////
1624 /// Get environment variable.
1625 
1626 const char *TSystem::Getenv(const char*)
1627 {
1628  AbstractMethod("Getenv");
1629  return 0;
1630 }
1631 
1632 //---- System Logging ----------------------------------------------------------
1633 
1634 ////////////////////////////////////////////////////////////////////////////////
1635 /// Open connection to system log daemon. For the use of the options and
1636 /// facility see the Unix openlog man page.
1637 
1639 {
1640  AbstractMethod("Openlog");
1641 }
1642 
1643 ////////////////////////////////////////////////////////////////////////////////
1644 /// Send mess to syslog daemon. Level is the logging level and mess the
1645 /// message that will be written on the log.
1646 
1647 void TSystem::Syslog(ELogLevel, const char *)
1648 {
1649  AbstractMethod("Syslog");
1650 }
1651 
1652 ////////////////////////////////////////////////////////////////////////////////
1653 /// Close connection to system log daemon.
1654 
1656 {
1657  AbstractMethod("Closelog");
1658 }
1659 
1660 //---- Standard output redirection ---------------------------------------------
1661 
1662 ////////////////////////////////////////////////////////////////////////////////
1663 /// Redirect standard output (stdout, stderr) to the specified file.
1664 /// If the file argument is 0 the output is set again to stderr, stdout.
1665 /// The second argument specifies whether the output should be added to the
1666 /// file ("a", default) or the file be truncated before ("w").
1667 /// The implementations of this function save internally the current state into
1668 /// a static structure.
1669 ///
1670 /// The call can be made reentrant by specifying the opaque structure pointed
1671 /// by 'h', which is filled with the relevant information. The handle 'h'
1672 /// obtained on the first call must then be used in any subsequent call,
1673 /// included ShowOutput, to display the redirected output.
1674 /// Returns 0 on success, -1 in case of error.
1675 
1676 Int_t TSystem::RedirectOutput(const char *, const char *, RedirectHandle_t *)
1677 {
1678  AbstractMethod("RedirectOutput");
1679  return -1;
1680 }
1681 
1682 ////////////////////////////////////////////////////////////////////////////////
1683 /// Display the content associated with the redirection described by the
1684 /// opaque handle 'h'.
1685 
1687 {
1688  // Check input ...
1689  if (!h) {
1690  Error("ShowOutput", "handle not specified");
1691  return;
1692  }
1693 
1694  // ... and file access
1695  if (gSystem->AccessPathName(h->fFile, kReadPermission)) {
1696  Error("ShowOutput", "file '%s' cannot be read", h->fFile.Data());
1697  return;
1698  }
1699 
1700  // Open the file
1701  FILE *f = 0;
1702  if (!(f = fopen(h->fFile.Data(), "r"))) {
1703  Error("ShowOutput", "file '%s' cannot be open", h->fFile.Data());
1704  return;
1705  }
1706 
1707  // Determine the number of bytes to be read from the file.
1708  off_t ltot = lseek(fileno(f), (off_t) 0, SEEK_END);
1709  Int_t begin = (h->fReadOffSet > 0 && h->fReadOffSet < ltot) ? h->fReadOffSet : 0;
1710  lseek(fileno(f), (off_t) begin, SEEK_SET);
1711  Int_t left = ltot - begin;
1712 
1713  // Now readout from file
1714  const Int_t kMAXBUF = 16384;
1715  char buf[kMAXBUF];
1716  Int_t wanted = (left > kMAXBUF-1) ? kMAXBUF-1 : left;
1717  Int_t len;
1718  do {
1719  while ((len = read(fileno(f), buf, wanted)) < 0 &&
1720  TSystem::GetErrno() == EINTR)
1722 
1723  if (len < 0) {
1724  SysError("ShowOutput", "error reading log file");
1725  break;
1726  }
1727 
1728  // Null-terminate
1729  buf[len] = 0;
1730  fprintf(stderr,"%s", buf);
1731 
1732  // Update counters
1733  left -= len;
1734  wanted = (left > kMAXBUF) ? kMAXBUF : left;
1735 
1736  } while (len > 0 && left > 0);
1737 
1738  // Do not display twice the same thing
1739  h->fReadOffSet = ltot;
1740  fclose(f);
1741 }
1742 
1743 //---- Dynamic Loading ---------------------------------------------------------
1744 
1745 ////////////////////////////////////////////////////////////////////////////////
1746 /// Add a new directory to the dynamic path.
1747 
1748 void TSystem::AddDynamicPath(const char *)
1749 {
1750  AbstractMethod("AddDynamicPath");
1751 }
1752 
1753 ////////////////////////////////////////////////////////////////////////////////
1754 /// Return the dynamic path (used to find shared libraries).
1755 
1757 {
1758  AbstractMethod("GetDynamicPath");
1759  return 0;
1760 }
1761 
1762 ////////////////////////////////////////////////////////////////////////////////
1763 /// Set the dynamic path to a new value.
1764 /// If the value of 'path' is zero, the dynamic path is reset to its
1765 /// default value.
1766 
1767 void TSystem::SetDynamicPath(const char *)
1768 {
1769  AbstractMethod("SetDynamicPath");
1770 }
1771 
1772 
1773 ////////////////////////////////////////////////////////////////////////////////
1774 /// Figure out if left and right points to the same
1775 /// object in the file system.
1776 
1777 static bool R__MatchFilename(const char *left, const char *right)
1778 {
1779  if (left == right) return kTRUE;
1780 
1781  if (left==0 || right==0) return kFALSE;
1782 
1783  if ( (strcmp(right,left)==0) ) {
1784  return kTRUE;
1785  }
1786 
1787 #ifdef G__WIN32
1788 
1789  char leftname[_MAX_PATH];
1790  char rightname[_MAX_PATH];
1791  _fullpath( leftname, left, _MAX_PATH );
1792  _fullpath( rightname, right, _MAX_PATH );
1793  return ((stricmp(leftname, rightname)==0));
1794 #else
1795  struct stat rightBuf;
1796  struct stat leftBuf;
1797  return ( ( 0 == stat( left, & leftBuf ) )
1798  && ( 0 == stat( right, & rightBuf ) )
1799  && ( leftBuf.st_dev == rightBuf.st_dev ) // Files on same device
1800  && ( leftBuf.st_ino == rightBuf.st_ino ) // Files on same inode (but this is not unique on AFS so we need the next 2 test
1801  && ( leftBuf.st_size == rightBuf.st_size ) // Files of same size
1802  && ( leftBuf.st_mtime == rightBuf.st_mtime ) // Files modified at the same time
1803  );
1804 #endif
1805 }
1806 
1807 ////////////////////////////////////////////////////////////////////////////////
1808 /// Load a shared library. Returns 0 on successful loading, 1 in
1809 /// case lib was already loaded, -1 in case lib does not exist
1810 /// or in case of error and -2 in case of version mismatch.
1811 /// When entry is specified the loaded lib is
1812 /// searched for this entry point (return -1 when entry does not exist,
1813 /// 0 otherwise). When the system flag is kTRUE, the library is considered
1814 /// a permanent system library that should not be unloaded during the
1815 /// course of the session.
1816 
1817 int TSystem::Load(const char *module, const char *entry, Bool_t system)
1818 {
1819  // don't load libraries that have already been loaded
1820  TString libs( GetLibraries() );
1821  TString moduleBasename( BaseName(module) );
1822  TString l(moduleBasename);
1823 
1824  Ssiz_t idx = l.Last('.');
1825  if (idx != kNPOS) {
1826  l.Remove(idx+1);
1827  }
1828  for (idx = libs.Index(l); idx != kNPOS; idx = libs.Index(l,idx+1)) {
1829  // The libs contains the sub-string 'l', let's make sure it is
1830  // not just part of a larger name.
1831  if (idx == 0 || libs[idx-1] == '/' || libs[idx-1] == '\\') {
1832  Ssiz_t len = libs.Length();
1833  idx += l.Length();
1834  if (!l.EndsWith(".") && libs[idx]=='.')
1835  idx++;
1836  // Skip the soversion.
1837  while (idx < len && isdigit(libs[idx])) {
1838  ++idx;
1839  // No need to test for len here, at worse idx==len and lib[idx]=='\0'
1840  if (libs[idx] == '.') {
1841  ++idx;
1842  }
1843  }
1844  while (idx < len && libs[idx] != '.') {
1845  if (libs[idx] == ' ' || idx+1 == len) {
1846  return 1;
1847  }
1848  ++idx;
1849  }
1850  }
1851  }
1852  if (l[l.Length()-1] == '.') {
1853  l.Remove(l.Length()-1);
1854  }
1855  if (l.BeginsWith("lib")) {
1856  l.Replace(0, 3, "-l");
1857  for(idx = libs.Index(l); idx != kNPOS; idx = libs.Index(l,idx+1)) {
1858  if ((idx == 0 || libs[idx-1] == ' ') &&
1859  (libs[idx+l.Length()] == ' ' || libs[idx+l.Length()] == 0)) {
1860  return 1;
1861  }
1862  }
1863  }
1864 
1865  char *path = DynamicPathName(module);
1866 
1867  int ret = -1;
1868  if (path) {
1869  // load any dependent libraries
1870  TString deplibs = gInterpreter->GetSharedLibDeps(moduleBasename);
1871  if (deplibs.IsNull()) {
1872  TString libmapfilename;
1873  libmapfilename = path;
1874  idx = libmapfilename.Last('.');
1875  if (idx != kNPOS) {
1876  libmapfilename.Remove(idx);
1877  }
1878  libmapfilename += ".rootmap";
1879  if (gSystem->GetPathInfo(libmapfilename, 0, (Long_t*)0, 0, 0) == 0) {
1880  if (gDebug > 0) Info("Load", "loading %s", libmapfilename.Data());
1881  gInterpreter->LoadLibraryMap(libmapfilename);
1882  deplibs = gInterpreter->GetSharedLibDeps(moduleBasename);
1883  }
1884  } else {
1885  TString delim(" ");
1886  TObjArray *tokens = deplibs.Tokenize(delim);
1887  for (Int_t i = tokens->GetEntriesFast()-1; i > 0; i--) {
1888  const char *deplib = ((TObjString*)tokens->At(i))->GetName();
1889  if (strcmp(module,deplib)==0) {
1890  continue;
1891  }
1892  if (gDebug > 0)
1893  Info("Load", "loading dependent library %s for library %s",
1894  deplib, ((TObjString*)tokens->At(0))->GetName());
1895  if ((ret = Load(deplib, "", system)) < 0) {
1896  delete tokens;
1897  delete [] path;
1898  return ret;
1899  }
1900  }
1901  delete tokens;
1902  }
1903  if (!system) {
1904  // Mark the library in $ROOTSYS/lib as system.
1905  const char *dirname = DirName(path);
1906  system = R__MatchFilename(TROOT::GetLibDir(), dirname);
1907 
1908  if (!system) {
1909  system = R__MatchFilename(TROOT::GetBinDir(), dirname);
1910  }
1911  }
1912 
1915  gLibraryVersionMax *= 2;
1917  }
1918  ret = gInterpreter->Load(path, system);
1919  if (ret < 0) ret = -1;
1920  if (gDebug > 0)
1921  Info("Load", "loaded library %s, status %d", path, ret);
1922  if (ret == 0 && gLibraryVersion[gLibraryVersionIdx]) {
1923  int v = TROOT::ConvertVersionCode2Int(gLibraryVersion[gLibraryVersionIdx]);
1924  Error("Load", "version mismatch, %s = %d, ROOT = %d",
1925  path, v, gROOT->GetVersionInt());
1926  ret = -2;
1928  }
1929  gLibraryVersionIdx--;
1930  delete [] path;
1931  }
1932 
1933  if (!entry || !entry[0] || ret < 0) return ret;
1934 
1935  Func_t f = DynFindSymbol(module, entry);
1936  if (f) return 0;
1937  return -1;
1938 }
1939 
1940 ////////////////////////////////////////////////////////////////////////////////
1941 /// Find a dynamic library called lib using the system search paths.
1942 /// Appends known extensions if needed. Returned string must be deleted
1943 /// by the user!
1944 
1945 char *TSystem::DynamicPathName(const char *lib, Bool_t quiet /*=kFALSE*/)
1946 {
1947  TString sLib(lib);
1948  if (FindDynamicLibrary(sLib, quiet))
1949  return StrDup(sLib);
1950  return 0;
1951 }
1952 
1953 ////////////////////////////////////////////////////////////////////////////////
1954 /// Find a dynamic library using the system search paths. lib will be updated
1955 /// to contain the absolute filename if found. Returns lib if found, or NULL
1956 /// if a library called lib was not found.
1957 /// This function does not open the library.
1958 
1960 {
1961  AbstractMethod("FindDynamicLibrary");
1962  return 0;
1963 }
1964 
1965 ////////////////////////////////////////////////////////////////////////////////
1966 /// Find specific entry point in specified library. Specify "*" for lib
1967 /// to search in all libraries.
1968 
1969 Func_t TSystem::DynFindSymbol(const char * /*lib*/, const char *entry)
1970 {
1971  return (Func_t) gInterpreter->FindSym(entry);
1972 }
1973 
1974 ////////////////////////////////////////////////////////////////////////////////
1975 /// Unload a shared library.
1976 
1977 void TSystem::Unload(const char *module)
1978 {
1979  char *path;
1980  if ((path = DynamicPathName(module))) {
1981  gInterpreter->UnloadFile(path);
1982  delete [] path;
1983  }
1984 }
1985 
1986 ////////////////////////////////////////////////////////////////////////////////
1987 /// List symbols in a shared library.
1988 
1989 void TSystem::ListSymbols(const char *, const char *)
1990 {
1991  AbstractMethod("ListSymbols");
1992 }
1993 
1994 ////////////////////////////////////////////////////////////////////////////////
1995 /// List all loaded shared libraries. Regexp is a wildcard expression,
1996 /// see TRegexp::MakeWildcard.
1997 
1998 void TSystem::ListLibraries(const char *regexp)
1999 {
2000  TString libs = GetLibraries(regexp);
2001  TRegexp separator("[^ \\t\\s]+");
2002  TString s;
2003  Ssiz_t start = 0, index = 0, end = 0;
2004  int i = 0;
2005 
2006  Printf(" ");
2007  Printf("Loaded shared libraries");
2008  Printf("=======================");
2009 
2010  while ((start < libs.Length()) && (index != kNPOS)) {
2011  index = libs.Index(separator, &end, start);
2012  if (index >= 0) {
2013  s = libs(index, end);
2014  if (s.BeginsWith("-")) {
2015  if (s.BeginsWith("-l")) {
2016  Printf("%s", s.Data());
2017  i++;
2018  }
2019  } else {
2020  Printf("%s", s.Data());
2021  i++;
2022  }
2023  }
2024  start += end+1;
2025  }
2026 
2027  Printf("-----------------------");
2028  Printf("%d libraries loaded", i);
2029  Printf("=======================");
2030 }
2031 
2032 ////////////////////////////////////////////////////////////////////////////////
2033 /// Return the thread local storage for the custom last error message
2034 
2036 {
2037  TTHREAD_TLS_DECL( TString, gLastErrorString);
2038  return gLastErrorString;
2039 }
2040 
2041 ////////////////////////////////////////////////////////////////////////////////
2042 /// Return the thread local storage for the custom last error message
2043 
2045 {
2046  return const_cast<TSystem*>(this)->GetLastErrorString();
2047 }
2048 
2049 ////////////////////////////////////////////////////////////////////////////////
2050 /// Get list of shared libraries loaded at the start of the executable.
2051 /// Returns 0 in case list cannot be obtained or in case of error.
2052 
2054 {
2055  return 0;
2056 }
2057 
2058 ////////////////////////////////////////////////////////////////////////////////
2059 /// Return a space separated list of loaded shared libraries.
2060 /// Regexp is a wildcard expression, see TRegexp::MakeWildcard.
2061 /// This list is of a format suitable for a linker, i.e it may contain
2062 /// -Lpathname and/or -lNameOfLib.
2063 /// Option can be any of:
2064 /// - S: shared libraries loaded at the start of the executable, because
2065 /// they were specified on the link line.
2066 /// - D: shared libraries dynamically loaded after the start of the program.
2067 /// For MacOS only:
2068 /// - L: list the .dylib rather than the .so (this is intended for linking)
2069 /// This options is not the default
2070 
2071 const char *TSystem::GetLibraries(const char *regexp, const char *options,
2072  Bool_t isRegexp)
2073 {
2074  fListLibs.Clear();
2075 
2076  TString libs;
2077  TString opt(options);
2078  Bool_t so2dylib = (opt.First('L') != kNPOS);
2079  if (so2dylib)
2080  opt.ReplaceAll("L", "");
2081 
2082  if (opt.IsNull() || opt.First('D') != kNPOS)
2083  libs += gInterpreter->GetSharedLibs();
2084 
2085  // Cint currently register all libraries that
2086  // are loaded and have a dictionary in them, this
2087  // includes all the libraries that are included
2088  // in the list of (hard) linked libraries.
2089 
2090  TString slinked;
2091  const char *linked;
2092  if ((linked = GetLinkedLibraries())) {
2093  if (fLinkedLibs != LINKEDLIBS) {
2094  // This is not the default value, we need to keep the custom part.
2095  TString custom = fLinkedLibs;
2096  custom.ReplaceAll(LINKEDLIBS,linked);
2097  if (custom == fLinkedLibs) {
2098  // no replacement done, let's append linked
2099  slinked.Append(linked);
2100  slinked.Append(" ");
2101  }
2102  slinked.Append(custom);
2103  } else {
2104  slinked.Append(linked);
2105  }
2106  } else {
2107  slinked.Append(fLinkedLibs);
2108  }
2109 
2110  if (opt.IsNull() || opt.First('S') != kNPOS) {
2111  // We are done, the statically linked libraries are already included.
2112  if (libs.Length() == 0) {
2113  libs = slinked;
2114  } else {
2115  // We need to add the missing linked library
2116 
2117  static TString lastLinked;
2118  static TString lastAddMissing;
2119  if ( lastLinked != slinked ) {
2120  // Recalculate only if there was a change.
2121  static TRegexp separator("[^ \\t\\s]+");
2122  lastLinked = slinked;
2123  lastAddMissing.Clear();
2124 
2125  Ssiz_t start, index, end;
2126  start = index = end = 0;
2127 
2128  while ((start < slinked.Length()) && (index != kNPOS)) {
2129  index = slinked.Index(separator,&end,start);
2130  if (index >= 0) {
2131  TString sub = slinked(index,end);
2132  if (sub[0]=='-' && sub[1]=='L') {
2133  lastAddMissing.Prepend(" ");
2134  lastAddMissing.Prepend(sub);
2135  } else {
2136  if (libs.Index(sub) == kNPOS) {
2137  lastAddMissing.Prepend(" ");
2138  lastAddMissing.Prepend(sub);
2139  }
2140  }
2141  }
2142  start += end+1;
2143  }
2144  }
2145  libs.Prepend(lastAddMissing);
2146  }
2147  } else if (libs.Length() != 0) {
2148  // Let remove the statically linked library
2149  // from the list.
2150  static TRegexp separator("[^ \\t\\s]+");
2151  Ssiz_t start, index, end;
2152  start = index = end = 0;
2153 
2154  while ((start < slinked.Length()) && (index != kNPOS)) {
2155  index = slinked.Index(separator,&end,start);
2156  if (index >= 0) {
2157  TString sub = slinked(index,end);
2158  if (sub[0]!='-' && sub[1]!='L') {
2159  libs.ReplaceAll(sub,"");
2160  }
2161  }
2162  start += end+1;
2163  }
2164  libs = libs.Strip(TString::kBoth);
2165  }
2166 
2167  // Select according to regexp
2168  if (regexp && *regexp) {
2169  static TRegexp separator("[^ \\t\\s]+");
2170  TRegexp user_re(regexp, kTRUE);
2171  TString s;
2172  Ssiz_t start, index, end;
2173  start = index = end = 0;
2174 
2175  while ((start < libs.Length()) && (index != kNPOS)) {
2176  index = libs.Index(separator,&end,start);
2177  if (index >= 0) {
2178  s = libs(index,end);
2179  if ((isRegexp && s.Index(user_re) != kNPOS) ||
2180  (!isRegexp && s.Index(regexp) != kNPOS)) {
2181  if (!fListLibs.IsNull())
2182  fListLibs.Append(" ");
2183  fListLibs.Append(s);
2184  }
2185  }
2186  start += end+1;
2187  }
2188  } else
2189  fListLibs = libs;
2190 
2191 #if defined(R__MACOSX) && !defined(MAC_OS_X_VERSION_10_5)
2192  if (so2dylib) {
2193  TString libs2 = fListLibs;
2194  TString maclibs;
2195 
2196  static TRegexp separator("[^ \\t\\s]+");
2197  static TRegexp user_so("\\.so$");
2198 
2199  Ssiz_t start, index, end;
2200  start = index = end = 0;
2201 
2202  while ((start < libs2.Length()) && (index != kNPOS)) {
2203  index = libs2.Index(separator, &end, start);
2204  if (index >= 0) {
2205  // Change .so into .dylib and remove the
2206  // path info if it is not accessible
2207  TString s = libs2(index, end);
2208  if (s.Index(user_so) != kNPOS) {
2209  s.ReplaceAll(".so",".dylib");
2210  if ( GetPathInfo( s, 0, (Long_t*)0, 0, 0 ) != 0 ) {
2211  s.Replace( 0, s.Last('/')+1, 0, 0);
2212  s.Replace( 0, s.Last('\\')+1, 0, 0);
2213  }
2214  }
2215  if (!maclibs.IsNull()) maclibs.Append(" ");
2216  maclibs.Append(s);
2217  }
2218  start += end+1;
2219  }
2220  fListLibs = maclibs;
2221  }
2222 #endif
2223 
2224  return fListLibs;
2225 }
2226 
2227 //---- RPC ---------------------------------------------------------------------
2228 
2229 ////////////////////////////////////////////////////////////////////////////////
2230 /// Get Internet Protocol (IP) address of host.
2231 
2233 {
2234  AbstractMethod("GetHostByName");
2235  return TInetAddress();
2236 }
2237 
2238 ////////////////////////////////////////////////////////////////////////////////
2239 /// Get Internet Protocol (IP) address of remote host and port #.
2240 
2242 {
2243  AbstractMethod("GetPeerName");
2244  return TInetAddress();
2245 }
2246 
2247 ////////////////////////////////////////////////////////////////////////////////
2248 /// Get Internet Protocol (IP) address of host and port #.
2249 
2251 {
2252  AbstractMethod("GetSockName");
2253  return TInetAddress();
2254 }
2255 
2256 ////////////////////////////////////////////////////////////////////////////////
2257 /// Get port # of internet service.
2258 
2259 int TSystem::GetServiceByName(const char *)
2260 {
2261  AbstractMethod("GetServiceByName");
2262  return -1;
2263 }
2264 
2265 ////////////////////////////////////////////////////////////////////////////////
2266 /// Get name of internet service.
2267 
2269 {
2270  AbstractMethod("GetServiceByPort");
2271  return 0;
2272 }
2273 
2274 ////////////////////////////////////////////////////////////////////////////////
2275 /// Open a connection to another host.
2276 
2277 int TSystem::OpenConnection(const char*, int, int, const char*)
2278 {
2279  AbstractMethod("OpenConnection");
2280  return -1;
2281 }
2282 
2283 ////////////////////////////////////////////////////////////////////////////////
2284 /// Announce TCP/IP service.
2285 
2287 {
2288  AbstractMethod("AnnounceTcpService");
2289  return -1;
2290 }
2291 
2292 ////////////////////////////////////////////////////////////////////////////////
2293 /// Announce UDP service.
2294 
2296 {
2297  AbstractMethod("AnnounceUdpService");
2298  return -1;
2299 }
2300 
2301 ////////////////////////////////////////////////////////////////////////////////
2302 /// Announce unix domain service.
2303 
2305 {
2306  AbstractMethod("AnnounceUnixService");
2307  return -1;
2308 }
2309 
2310 ////////////////////////////////////////////////////////////////////////////////
2311 /// Announce unix domain service.
2312 
2313 int TSystem::AnnounceUnixService(const char *, int)
2314 {
2315  AbstractMethod("AnnounceUnixService");
2316  return -1;
2317 }
2318 
2319 ////////////////////////////////////////////////////////////////////////////////
2320 /// Accept a connection.
2321 
2323 {
2324  AbstractMethod("AcceptConnection");
2325  return -1;
2326 }
2327 
2328 ////////////////////////////////////////////////////////////////////////////////
2329 /// Close socket connection.
2330 
2332 {
2333  AbstractMethod("CloseConnection");
2334 }
2335 
2336 ////////////////////////////////////////////////////////////////////////////////
2337 /// Receive exactly length bytes into buffer. Use opt to receive out-of-band
2338 /// data or to have a peek at what is in the buffer (see TSocket).
2339 
2340 int TSystem::RecvRaw(int, void *, int, int)
2341 {
2342  AbstractMethod("RecvRaw");
2343  return -1;
2344 }
2345 
2346 ////////////////////////////////////////////////////////////////////////////////
2347 /// Send exactly length bytes from buffer. Use opt to send out-of-band
2348 /// data (see TSocket).
2349 
2350 int TSystem::SendRaw(int, const void *, int, int)
2351 {
2352  AbstractMethod("SendRaw");
2353  return -1;
2354 }
2355 
2356 ////////////////////////////////////////////////////////////////////////////////
2357 /// Receive a buffer headed by a length indicator.
2358 
2359 int TSystem::RecvBuf(int, void *, int)
2360 {
2361  AbstractMethod("RecvBuf");
2362  return -1;
2363 }
2364 
2365 ////////////////////////////////////////////////////////////////////////////////
2366 /// Send a buffer headed by a length indicator.
2367 
2368 int TSystem::SendBuf(int, const void *, int)
2369 {
2370  AbstractMethod("SendBuf");
2371  return -1;
2372 }
2373 
2374 ////////////////////////////////////////////////////////////////////////////////
2375 /// Set socket option.
2376 
2377 int TSystem::SetSockOpt(int, int, int)
2378 {
2379  AbstractMethod("SetSockOpt");
2380  return -1;
2381 }
2382 
2383 ////////////////////////////////////////////////////////////////////////////////
2384 /// Get socket option.
2385 
2386 int TSystem::GetSockOpt(int, int, int*)
2387 {
2388  AbstractMethod("GetSockOpt");
2389  return -1;
2390 }
2391 
2392 //---- System, CPU and Memory info ---------------------------------------------
2393 
2394 ////////////////////////////////////////////////////////////////////////////////
2395 /// Returns static system info, like OS type, CPU type, number of CPUs
2396 /// RAM size, etc into the SysInfo_t structure. Returns -1 in case of error,
2397 /// 0 otherwise.
2398 
2400 {
2401  AbstractMethod("GetSysInfo");
2402  return -1;
2403 }
2404 
2405 ////////////////////////////////////////////////////////////////////////////////
2406 /// Returns cpu load average and load info into the CpuInfo_t structure.
2407 /// Returns -1 in case of error, 0 otherwise. Use sampleTime to set the
2408 /// interval over which the CPU load will be measured, in ms (default 1000).
2409 
2411 {
2412  AbstractMethod("GetCpuInfo");
2413  return -1;
2414 }
2415 
2416 ////////////////////////////////////////////////////////////////////////////////
2417 /// Returns ram and swap memory usage info into the MemInfo_t structure.
2418 /// Returns -1 in case of error, 0 otherwise.
2419 
2421 {
2422  AbstractMethod("GetMemInfo");
2423  return -1;
2424 }
2425 
2426 ////////////////////////////////////////////////////////////////////////////////
2427 /// Returns cpu and memory used by this process into the ProcInfo_t structure.
2428 /// Returns -1 in case of error, 0 otherwise.
2429 
2431 {
2432  AbstractMethod("GetProcInfo");
2433  return -1;
2434 }
2435 
2436 //---- Script Compiler ---------------------------------------------------------
2437 
2438 void AssignAndDelete(TString& target, char *tobedeleted)
2439 {
2440  // Assign the char* value to the TString and then delete it.
2441 
2442  target = tobedeleted;
2443  delete [] tobedeleted;
2444 }
2445 
2446 #ifdef WIN32
2447 
2448 static TString R__Exec(const char *cmd)
2449 {
2450  // Execute a command and return the stdout in a string.
2451 
2452  FILE * f = gSystem->OpenPipe(cmd,"r");
2453  if (!f) {
2454  return "";
2455  }
2456  TString result;
2457 
2458  char x;
2459  while ((x = fgetc(f))!=EOF ) {
2460  if (x=='\n' || x=='\r') break;
2461  result += x;
2462  }
2463 
2464  fclose(f);
2465  return result;
2466 }
2467 
2468 static void R__FixLink(TString &cmd)
2469 {
2470  // Replace the call to 'link' by a full path name call based on where cl.exe is.
2471  // This prevents us from using inadvertently the link.exe provided by cygwin.
2472 
2473  // check if link is the microsoft one...
2474  TString res = R__Exec("link 2>&1");
2475  if (res.Length()) {
2476  if (res.Contains("Microsoft (R) Incremental Linker"))
2477  return;
2478  }
2479  // else check availability of cygpath...
2480  res = R__Exec("cygpath . 2>&1");
2481  if (res.Length()) {
2482  if (res != ".")
2483  return;
2484  }
2485 
2486  res = R__Exec("which cl.exe 2>&1|grep cl|sed 's,cl\\.exe$,link\\.exe,' 2>&1");
2487  if (res.Length()) {
2488  res = R__Exec(Form("cygpath -w '%s' 2>&1",res.Data()));
2489  if (res.Length()) {
2490  cmd.ReplaceAll(" link ",Form(" \"%s\" ",res.Data()));
2491  }
2492  }
2493 }
2494 #endif
2495 
2496 #ifndef WIN32
2497 static void R__AddPath(TString &target, const TString &path) {
2498  target += path;
2499 }
2500 #else
2501 static void R__AddPath(TString &target, const TString &path) {
2502  if (path.Length() > 2 && path[1]==':') {
2503  target += TString::Format("/cygdrive/%c",path[0]) + path(2,path.Length()-2);
2504  } else {
2505  target += path;
2506  }
2507 }
2508 #endif
2509 
2510 #ifndef WIN32
2511 static void R__WriteDependencyFile(const TString & build_loc, const TString &depfilename, const TString &filename, const TString &library, const TString &libname,
2512  const TString &extension, const char *version_var_prefix, const TString &includes, const TString &defines, const TString &incPath)
2513 #else
2514 static void R__WriteDependencyFile(const TString &build_loc, const TString &depfilename, const TString &filename, const TString &library, const TString &libname,
2515  const TString &extension, const char *version_var_prefix, const TString &includes, const TString &defines, const TString &incPath)
2516 #endif
2517 {
2518  // Generate the dependency via standard output, not searching the
2519  // standard include directories,
2520 
2521 #ifndef WIN32
2522  const char * stderrfile = "/dev/null";
2523 #else
2524  TString stderrfile;
2525  AssignAndDelete( stderrfile, gSystem->ConcatFileName(build_loc,"stderr.tmp") );
2526 #endif
2527  TString bakdepfilename = depfilename + ".bak";
2528 
2529 #ifdef WIN32
2530  TString touch = "echo # > "; touch += "\"" + depfilename + "\"";
2531 #else
2532  TString touch = "echo > "; touch += "\"" + depfilename + "\"";
2533 #endif
2534  TString builddep = "rmkdepend";
2535  gSystem->PrependPathName(TROOT::GetBinDir(), builddep);
2536  builddep += " \"-f";
2537  builddep += depfilename;
2538  builddep += "\" -o_" + extension + "." + gSystem->GetSoExt() + " ";
2539  if (build_loc.BeginsWith(gSystem->WorkingDirectory())) {
2540  Int_t len = strlen(gSystem->WorkingDirectory());
2541  if ( build_loc.Length() > (len+1) ) {
2542  builddep += " \"-p";
2543  if (build_loc[len] == '/' || build_loc[len+1] != '\\' ) {
2544  // Since the path is now ran through TSystem::ExpandPathName the single \ is also possible.
2545  R__AddPath(builddep, build_loc.Data() + len + 1 );
2546  } else {
2547  // Case of dir\\name
2548  R__AddPath(builddep, build_loc.Data() + len + 2 );
2549  }
2550  builddep += "/\" ";
2551  }
2552  } else {
2553  builddep += " \"-p";
2554  R__AddPath(builddep, build_loc);
2555  builddep += "/\" ";
2556  }
2557  builddep += " -Y -- ";
2558  TString rootsysInclude = TROOT::GetIncludeDir();
2559  builddep += " \"-I"+rootsysInclude+"\" "; // cflags
2560  builddep += includes;
2561  builddep += defines;
2562  builddep += " -- \"";
2563  builddep += filename;
2564  builddep += "\" ";
2565  TString targetname;
2566  if (library.BeginsWith(gSystem->WorkingDirectory())) {
2567  Int_t len = strlen(gSystem->WorkingDirectory());
2568  if ( library.Length() > (len+1) ) {
2569  if (library[len] == '/' || library[len+1] != '\\' ) {
2570  targetname = library.Data() + len + 1;
2571  } else {
2572  targetname = library.Data() + len + 2;
2573  }
2574  } else {
2575  targetname = library;
2576  }
2577  } else {
2578  targetname = library;
2579  }
2580  builddep += " \"";
2581  builddep += "-t";
2582  R__AddPath(builddep, targetname);
2583  builddep += "\" > ";
2584  builddep += stderrfile;
2585  builddep += " 2>&1 ";
2586 
2587  TString adddictdep = "echo ";
2588  R__AddPath(adddictdep,targetname);
2589  adddictdep += ": ";
2590 #if defined(R__HAS_CLING_DICTVERSION)
2591  {
2592  char *clingdictversion = gSystem->Which(incPath,"clingdictversion.h");
2593  if (clingdictversion) {
2594  R__AddPath(adddictdep,clingdictversion);
2595  adddictdep += " ";
2596  delete [] clingdictversion;
2597  } else {
2598  R__AddPath(adddictdep,rootsysInclude+"/clingdictversion.h ");
2599  }
2600  }
2601 #endif
2602  {
2603  const char *dictHeaders[] = { "RVersion.h", "RConfig.h", "TClass.h",
2604  "TDictAttributeMap.h","TInterpreter.h","TROOT.h","TBuffer.h",
2605  "TMemberInspector.h","TError.h","RtypesImp.h","TIsAProxy.h",
2606  "TFileMergeInfo.h","TCollectionProxyInfo.h"};
2607 
2608  for (unsigned int h=0; h < sizeof(dictHeaders)/sizeof(dictHeaders[0]); ++h)
2609  {
2610  char *rootVersion = gSystem->Which(incPath,dictHeaders[h]);
2611  if (rootVersion) {
2612  R__AddPath(adddictdep,rootVersion);
2613  adddictdep += " ";
2614  delete [] rootVersion;
2615  } else {
2616  R__AddPath(adddictdep,rootsysInclude + "/" + dictHeaders[h]);
2617  }
2618  }
2619  }
2620  adddictdep += " >> \""+depfilename+"\"";
2621 
2622  TString addversiondep( "echo ");
2623  addversiondep += libname + version_var_prefix + " \"" + ROOT_RELEASE + "\" >> \""+depfilename+"\"";
2624 
2625  if (gDebug > 4) {
2626  ::Info("ACLiC", "%s", touch.Data());
2627  ::Info("ACLiC", "%s", builddep.Data());
2628  ::Info("ACLiC", "%s", adddictdep.Data());
2629  }
2630 
2631  Int_t depbuilt = !gSystem->Exec(touch);
2632  if (depbuilt) depbuilt = !gSystem->Exec(builddep);
2633  if (depbuilt) depbuilt = !gSystem->Exec(adddictdep);
2634  if (depbuilt) depbuilt = !gSystem->Exec(addversiondep);
2635 
2636  if (!depbuilt) {
2637  ::Warning("ACLiC","Failed to generate the dependency file for %s",
2638  library.Data());
2639  } else {
2640 #ifdef WIN32
2641  gSystem->Unlink(stderrfile);
2642 #endif
2643  gSystem->Unlink(bakdepfilename);
2644  }
2645 }
2646 
2647 ////////////////////////////////////////////////////////////////////////////////
2648 /// This method compiles and loads a shared library containing
2649 /// the code from the file "filename".
2650 ///
2651 /// The return value is true (1) in case of success and false (0)
2652 /// in case of error.
2653 ///
2654 /// The possible options are:
2655 /// - k : keep the shared library after the session end.
2656 /// - f : force recompilation.
2657 /// - g : compile with debug symbol
2658 /// - O : optimized the code
2659 /// - c : compile only, do not attempt to load the library.
2660 /// - s : silence all informational output
2661 /// - v : output all information output
2662 /// - d : debug ACLiC, keep all the output files.
2663 /// - - : if buildir is set, use a flat structure (see buildir below)
2664 ///
2665 /// If library_specified is specified, CompileMacro generates the file
2666 /// "library_specified".soext where soext is the shared library extension for
2667 /// the current platform.
2668 ///
2669 /// If build_dir is specified, it is used as an alternative 'root' for the
2670 /// generation of the shared library. The library is stored in a sub-directories
2671 /// of 'build_dir' including the full pathname of the script unless a flat
2672 /// directory structure is requested ('-' option). With the '-' option the libraries
2673 /// are created directly in the directory 'build_dir'; in particular this means that
2674 /// 2 scripts with the same name in different source directory will over-write each
2675 /// other's library.
2676 /// See also TSystem::SetBuildDir.
2677 ///
2678 /// If dirmode is not zero and we need to create the target directory, the
2679 /// file mode bit will be change to 'dirmode' using chmod.
2680 ///
2681 /// If library_specified is not specified, CompileMacro generate a default name
2682 /// for library by taking the name of the file "filename" but replacing the
2683 /// dot before the extension by an underscore and by adding the shared
2684 /// library extension for the current platform.
2685 /// For example on most platform, hsimple.cxx will generate hsimple_cxx.so
2686 ///
2687 /// It uses the directive fMakeSharedLibs to create a shared library.
2688 /// If loading the shared library fails, it tries to output a list of missing
2689 /// symbols by creating an executable (on some platforms like OSF, this does
2690 /// not HAVE to be an executable) containing the script. It uses the
2691 /// directive fMakeExe to do so.
2692 /// For both directives, before passing them to TSystem::Exec, it expands the
2693 /// variables $SourceFiles, $SharedLib, $LibName, $IncludePath, $LinkedLibs,
2694 /// $DepLibs, $ExeName and $ObjectFiles. See SetMakeSharedLib() for more
2695 /// information on those variables.
2696 ///
2697 /// This method is used to implement the following feature:
2698 ///
2699 /// Synopsis:
2700 ///
2701 /// The purpose of this addition is to allow the user to use an external
2702 /// compiler to create a shared library from its C++ macro (scripts).
2703 /// Currently in order to execute a script, a user has to type at the root
2704 /// prompt
2705 /// ~~~ {.cpp}
2706 /// .X myfunc.C(arg1,arg2)
2707 /// ~~~
2708 /// We allow them to type:
2709 /// ~~~ {.cpp}
2710 /// .X myfunc.C++(arg1,arg2)
2711 /// ~~~
2712 /// or
2713 /// ~~~ {.cpp}
2714 /// .X myfunc.C+(arg1,arg2)
2715 /// ~~~
2716 /// In which case an external compiler will be called to create a shared
2717 /// library. This shared library will then be loaded and the function
2718 /// myfunc will be called with the two arguments. With '++' the shared library
2719 /// is always recompiled. With '+' the shared library is recompiled only
2720 /// if it does not exist yet or the macro file is newer than the shared
2721 /// library.
2722 ///
2723 /// Of course the + and ++ notation is supported in similar way for .x and .L.
2724 ///
2725 /// Through the function TSystem::SetMakeSharedLib(), the user will be able to
2726 /// indicate, with shell commands, how to build a shared library (a good
2727 /// default will be provided). The most common change, namely where to find
2728 /// header files, will be available through the function
2729 /// TSystem::SetIncludePath().
2730 /// A good default will be provided so that a typical user session should be at
2731 /// most:
2732 /// ~~~ {.cpp}
2733 /// root[1] gSystem->SetIncludePath("-I$ROOTSYS/include
2734 /// -I$HOME/mypackage/include");
2735 /// root[2] .x myfunc.C++(10,20);
2736 /// ~~~
2737 /// The user may sometimes try to compile a script before it has loaded all the
2738 /// needed shared libraries. In this case we want to be helpfull and output a
2739 /// list of the unresolved symbols. So if the loading of the created shared
2740 /// library fails, we will try to build a executable that contains the
2741 /// script. The linker should then output a list of missing symbols.
2742 ///
2743 /// To support this we provide a TSystem::SetMakeExe() function, that sets the
2744 /// directive telling how to create an executable. The loader will need
2745 /// to be informed of all the libraries available. The information about
2746 /// the libraries that has been loaded by .L and TSystem::Load() is accesible
2747 /// to the script compiler. However, the information about
2748 /// the libraries that have been selected at link time by the application
2749 /// builder (like the root libraries for root.exe) are not available and need
2750 /// to be explicitly listed in fLinkedLibs (either by default or by a call to
2751 /// TSystem::SetLinkedLibs()).
2752 ///
2753 /// To simplify customization we could also add to the .rootrc support for the
2754 /// variables
2755 /// ~~~ {.cpp}
2756 /// Unix.*.Root.IncludePath: -I$ROOTSYS/include
2757 /// WinNT.*.Root.IncludePath: -I%ROOTSYS%/include
2758 ///
2759 /// Unix.*.Root.LinkedLibs: -L$ROOTSYS/lib -lBase ....
2760 /// WinNT.*.Root.LinkedLibs: %ROOTSYS%/lib/*.lib msvcrt.lib ....
2761 /// ~~~
2762 /// And also support for MakeSharedLibs() and MakeExe().
2763 ///
2764 /// (the ... have to be replaced by the actual values and are here only to
2765 /// shorten this comment).
2766 
2767 int TSystem::CompileMacro(const char *filename, Option_t *opt,
2768  const char *library_specified,
2769  const char *build_dir,
2770  UInt_t dirmode)
2771 {
2772  static const char *version_var_prefix = "__ROOTBUILDVERSION=";
2773 
2774  // ======= Analyze the options
2775  Bool_t keep = kFALSE;
2776  Bool_t recompile = kFALSE;
2777  EAclicMode mode = fAclicMode;
2778  Bool_t loadLib = kTRUE;
2779  Bool_t withInfo = kTRUE;
2780  Bool_t verbose = kFALSE;
2781  Bool_t internalDebug = kFALSE;
2782  if (opt) {
2783  keep = (strchr(opt,'k')!=0);
2784  recompile = (strchr(opt,'f')!=0);
2785  if (strchr(opt,'O')!=0) {
2786  mode = kOpt;
2787  }
2788  if (strchr(opt,'g')!=0) {
2789  mode = kDebug;
2790  }
2791  if (strchr(opt,'c')!=0) {
2792  loadLib = kFALSE;
2793  }
2794  withInfo = strchr(opt, 's') == 0;
2795  verbose = strchr(opt, 'v') != 0;
2796  internalDebug = strchr(opt, 'd') != 0;
2797  }
2798  if (mode==kDefault) {
2799  TString rootbuild = ROOTBUILD;
2800  if (rootbuild.Index("debug",0,TString::kIgnoreCase)==kNPOS) {
2801  mode=kOpt;
2802  } else {
2803  mode=kDebug;
2804  }
2805  }
2806  UInt_t verboseLevel = verbose ? 7 : gDebug;
2807  Bool_t flatBuildDir = (fAclicProperties & kFlatBuildDir) || (strchr(opt,'-')!=0);
2808 
2809  // if non-zero, build_loc indicates where to build the shared library.
2810  TString build_loc = ExpandFileName(GetBuildDir());
2811  if (build_dir && strlen(build_dir)) build_loc = build_dir;
2812  if (build_loc == ".") {
2813  build_loc = WorkingDirectory();
2814  } else if (build_loc.Length() && (!IsAbsoluteFileName(build_loc)) ) {
2815  AssignAndDelete( build_loc , ConcatFileName( WorkingDirectory(), build_loc ) );
2816  }
2817 
2818  // Get the include directory list in the dir1:dir2:dir3 format
2819  // [Used for generating the .d file and to look for header files for
2820  // the linkdef file]
2821  TString incPath = GetIncludePath(); // of the form -Idir1 -Idir2 -Idir3
2822  incPath.Append(":").Prepend(" ");
2823  if (gEnv) {
2824  TString fromConfig = gEnv->GetValue("ACLiC.IncludePaths","");
2825  incPath.Append(fromConfig);
2826  }
2827  incPath.ReplaceAll(" -I",":"); // of form :dir1 :dir2:dir3
2828  while ( incPath.Index(" :") != -1 ) {
2829  incPath.ReplaceAll(" :",":");
2830  }
2831  incPath.Prepend(":.:");
2832  incPath.Prepend(WorkingDirectory());
2833 
2834  // ======= Get the right file names for the dictionary and the shared library
2835  TString expFileName(filename);
2836  ExpandPathName( expFileName );
2837  TString library = expFileName;
2838  if (! IsAbsoluteFileName(library) )
2839  {
2840  const char *whichlibrary = Which(incPath,library);
2841  if (whichlibrary) {
2842  library = whichlibrary;
2843  delete [] whichlibrary;
2844  } else {
2845  ::Error("ACLiC","The file %s can not be found in the include path: %s",filename,incPath.Data());
2846  return kFALSE;
2847  }
2848  } else {
2849  if (gSystem->AccessPathName(library)) {
2850  ::Error("ACLiC","The file %s can not be found.",filename);
2851  return kFALSE;
2852  }
2853  }
2854  { // Remove multiple '/' characters, rootcint treats them as comments.
2855  Ssiz_t pos = 0;
2856  while ((pos = library.Index("//", 2, pos, TString::kExact)) != kNPOS) {
2857  library.Remove(pos, 1);
2858  }
2859  }
2860  TString filename_fullpath = library;
2861 
2862  TString file_dirname = DirName( filename_fullpath );
2863  // For some probably good reason, DirName on Windows returns the 'name' of
2864  // the directory, omitting the drive letter (even if there was one). In
2865  // consequence the result is not useable as a 'root directory', we need to
2866  // add the drive letter if there was one..
2867  if (library.Length()>1 && isalpha(library[0]) && library[1]==':') {
2868  file_dirname.Prepend(library(0,2));
2869  }
2870  TString file_location( file_dirname ); // Location of the script.
2871  incPath.Prepend( file_location + ":" );
2872 
2873  Ssiz_t dot_pos = library.Last('.');
2874  TString extension = library;
2875  extension.Replace( 0, dot_pos+1, 0 , 0);
2876  TString libname_noext = library;
2877  if (dot_pos>=0) libname_noext.Remove( dot_pos );
2878 
2879  // Extension of shared library is platform dependent!!
2880  library.Replace( dot_pos, library.Length()-dot_pos,
2881  TString("_") + extension + "." + fSoExt );
2882 
2883  TString libname ( BaseName( libname_noext ) );
2884  libname.Append("_").Append(extension);
2885 
2886  if (library_specified && strlen(library_specified) ) {
2887  // Use the specified name instead of the default
2888  libname = BaseName( library_specified );
2889  library = library_specified;
2890  ExpandPathName( library );
2891  if (! IsAbsoluteFileName(library) ) {
2892  AssignAndDelete( library , ConcatFileName( WorkingDirectory(), library ) );
2893  }
2894  library = TString(library) + "." + fSoExt;
2895  }
2896 
2897  TString libname_ext ( libname );
2898  libname_ext += "." + fSoExt;
2899 
2900  TString lib_dirname = DirName( library );
2901  // For some probably good reason, DirName on Windows returns the 'name' of
2902  // the directory, omitting the drive letter (even if there was one). In
2903  // consequence the result is not useable as a 'root directory', we need to
2904  // add the drive letter if there was one..
2905  if (library.Length()>1 && isalpha(library[0]) && library[1]==':') {
2906  lib_dirname.Prepend(library(0,2));
2907  }
2908  // Strip potential, somewhat redundant '/.' from the pathname ...
2909  if ( strncmp( &(lib_dirname[lib_dirname.Length()-2]), "/.", 2) == 0 ) {
2910  lib_dirname.Remove(lib_dirname.Length()-2);
2911  }
2912  if ( strncmp( &(lib_dirname[lib_dirname.Length()-2]), "\\.", 2) == 0 ) {
2913  lib_dirname.Remove(lib_dirname.Length()-2);
2914  }
2915  TString lib_location( lib_dirname );
2916  Bool_t mkdirFailed = kFALSE;
2917 
2918  if (build_loc.Length()==0) {
2919  build_loc = lib_location;
2920  } else {
2921  // Removes an existing disk specification from the names
2922  TRegexp disk_finder ("[A-z]:");
2923  Int_t pos = library.Index( disk_finder );
2924  if (pos==0) library.Remove(pos,3);
2925  pos = lib_location.Index( disk_finder );
2926  if (pos==0) lib_location.Remove(pos,3);
2927 
2928  if (flatBuildDir) {
2929  AssignAndDelete( library, ConcatFileName( build_loc, libname_ext) );
2930  } else {
2931  AssignAndDelete( library, ConcatFileName( build_loc, library) );
2932  }
2933 
2934  Bool_t canWriteBuild_loc = !gSystem->AccessPathName(build_loc,kWritePermission);
2935  TString build_loc_store( build_loc );
2936  if (!flatBuildDir) {
2937  AssignAndDelete( build_loc, ConcatFileName( build_loc, lib_location) );
2938  }
2939 
2940  if (gSystem->AccessPathName(build_loc,kFileExists)) {
2941  mkdirFailed = (0 != mkdir(build_loc, true));
2942  if (mkdirFailed && !canWriteBuild_loc) {
2943  // The mkdir failed __and__ we can not write to the target directory,
2944  // let make sure the error message will be about the target directory
2945  build_loc = build_loc_store;
2946  mkdirFailed = kFALSE;
2947  } else if (!mkdirFailed && dirmode!=0) {
2948  Chmod(build_loc,dirmode);
2949  }
2950  }
2951  }
2952 
2953  // ======= Check if the library need to loaded or compiled
2954  if ( gInterpreter->IsLoaded(expFileName) &&
2955  !gInterpreter->IsLoaded(library) ) {
2956  // the script has already been loaded in interpreted mode
2957  // Let's warn the user and unload it.
2958 
2959  if (withInfo) {
2960  ::Info("ACLiC","script has already been loaded in interpreted mode");
2961  ::Info("ACLiC","unloading %s and compiling it", filename);
2962  }
2963 
2964  if ( gInterpreter->UnloadFile( expFileName ) != 0 ) {
2965  // We can not unload it.
2966  return kFALSE;
2967  }
2968  }
2969 
2970  // Calculate the -I lines
2971  TString includes = GetIncludePath();
2972  includes.Prepend(' ');
2973 
2974  {
2975  // I need to replace the -Isomerelativepath by -I../ (or -I..\ on NT)
2976  TRegexp rel_inc(" -I[^\"/\\$%-][^:-]+");
2977  Int_t len,pos;
2978  pos = rel_inc.Index(includes,&len);
2979  while( len != 0 ) {
2980  TString sub = includes(pos,len);
2981  sub.Remove(0,3); // Remove ' -I'
2982  AssignAndDelete( sub, ConcatFileName( WorkingDirectory(), sub ) );
2983  sub.Prepend(" -I\"");
2984  sub.Append("\"");
2985  includes.Replace(pos,len,sub);
2986  pos = rel_inc.Index(includes,&len);
2987  }
2988  }
2989  {
2990  // I need to replace the -I"somerelativepath" by -I"$cwd/ (or -I"$cwd\ on NT)
2991  TRegexp rel_inc(" -I\"[^/\\$%-][^:-]+");
2992  Int_t len,pos;
2993  pos = rel_inc.Index(includes,&len);
2994  while( len != 0 ) {
2995  TString sub = includes(pos,len);
2996  sub.Remove(0,4); // Remove ' -I"'
2997  AssignAndDelete( sub, ConcatFileName( WorkingDirectory(), sub ) );
2998  sub.Prepend(" -I\"");
2999  includes.Replace(pos,len,sub);
3000  pos = rel_inc.Index(includes,&len);
3001  }
3002  }
3003  //includes += " -I\"" + build_loc;
3004  //includes += "\" -I\"";
3005  //includes += WorkingDirectory();
3006 // if (includes[includes.Length()-1] == '\\') {
3007 // // The current directory is (most likely) the root of a windows drive and
3008 // // has a trailing \ which would espace the quote if left by itself.
3009 // includes += '\\';
3010 // }
3011 // includes += "\"";
3012  if (gEnv) {
3013  TString fromConfig = gEnv->GetValue("ACLiC.IncludePaths","");
3014  includes.Append(" ").Append(fromConfig).Append(" ");
3015  }
3016 
3017  // Extract the -D for the dependency generation.
3018  TString defines = " ";
3019  {
3020  TString cmd = GetMakeSharedLib();
3021  TRegexp rel_def("-D[^\\s\\t\\n\\r]*");
3022  Int_t len,pos;
3023  pos = rel_def.Index(cmd,&len);
3024  while( len != 0 ) {
3025  defines += cmd(pos,len);
3026  defines += " ";
3027  pos = rel_def.Index(cmd,&len,pos+1);
3028  }
3029 
3030  }
3031 
3032  TString emergency_loc;
3033  {
3034  UserGroup_t *ug = gSystem->GetUserInfo(gSystem->GetUid());
3035  if (ug) {
3036  AssignAndDelete( emergency_loc, ConcatFileName( TempDirectory(), ug->fUser ) );
3037  delete ug;
3038  } else {
3039  emergency_loc = TempDirectory();
3040  }
3041  }
3042 
3043  Bool_t canWrite = !gSystem->AccessPathName(build_loc,kWritePermission);
3044 
3045  Bool_t modified = kFALSE;
3046 
3047  // Generate the dependency filename
3048  TString depdir = build_loc;
3049  TString depfilename;
3050  AssignAndDelete( depfilename, ConcatFileName(depdir, BaseName(libname_noext)) );
3051  depfilename += "_" + extension + ".d";
3052 
3053  if ( !recompile ) {
3054 
3055  Long_t lib_time, file_time;
3056 
3057  if ((gSystem->GetPathInfo( library, 0, (Long_t*)0, 0, &lib_time ) != 0) ||
3058  (gSystem->GetPathInfo( expFileName, 0, (Long_t*)0, 0, &file_time ) == 0 &&
3059  (lib_time < file_time))) {
3060 
3061  // the library does not exist or is older than the script.
3062  recompile = kTRUE;
3063  modified = kTRUE;
3064 
3065  } else {
3066 
3067  if ( gSystem->GetPathInfo( depfilename, 0,(Long_t*) 0, 0, &file_time ) != 0 ) {
3068  if (!canWrite) {
3069  depdir = emergency_loc;
3070  AssignAndDelete( depfilename, ConcatFileName(depdir, BaseName(libname_noext)) );
3071  depfilename += "_" + extension + ".d";
3072  }
3073  R__WriteDependencyFile(build_loc, depfilename, filename_fullpath, library, libname, extension, version_var_prefix, includes, defines, incPath);
3074  }
3075  }
3076 
3077  if (!modified) {
3078 
3079  // We need to check the dependencies
3080  FILE * depfile = fopen(depfilename.Data(),"r");
3081  if (depfile==0) {
3082  // there is no accessible dependency file, let's assume the library has been
3083  // modified
3084  modified = kTRUE;
3085  recompile = kTRUE;
3086 
3087  } else {
3088 
3089  TString version_var = libname + version_var_prefix;
3090 
3091  Int_t sz = 256;
3092  char *line = new char[sz];
3093  line[0] = 0;
3094 
3095  int c;
3096  Int_t current = 0;
3097  Int_t nested = 0;
3098  Bool_t hasversion = false;
3099 
3100  while ((c = fgetc(depfile)) != EOF) {
3101  if (c=='#') {
3102  // skip comment
3103  while ((c = fgetc(depfile)) != EOF) {
3104  if (c=='\n') {
3105  break;
3106  }
3107  }
3108  continue;
3109  }
3110  if (current && line[current-1]=='=' && strncmp(version_var.Data(),line,current)==0) {
3111 
3112  // The next word will be the version number.
3113  hasversion = kTRUE;
3114  line[0] = 0;
3115  current = 0;
3116  } else if (isspace(c) && !nested) {
3117  if (current) {
3118  if (line[current-1]!=':') {
3119  // ignore target
3120  line[current] = 0;
3121 
3122  Long_t filetime;
3123  if (hasversion) {
3124  modified |= strcmp(ROOT_RELEASE,line)!=0;
3125  hasversion = kFALSE;
3126  } else if ( gSystem->GetPathInfo( line, 0, (Long_t*)0, 0, &filetime ) == 0 ) {
3127  modified |= ( lib_time <= filetime );
3128  }
3129  }
3130  }
3131  current = 0;
3132  line[0] = 0;
3133  } else {
3134  if (current==sz-1) {
3135  sz = 2*sz;
3136  char *newline = new char[sz];
3137  strcpy(newline,line);
3138  delete [] line;
3139  line = newline;
3140  }
3141  if (c=='"') nested = !nested;
3142  else {
3143  line[current] = c;
3144  current++;
3145  }
3146  }
3147  }
3148  delete [] line;
3149  fclose(depfile);
3150  recompile = modified;
3151 
3152  }
3153 
3154  }
3155  }
3156 
3157  if ( gInterpreter->IsLoaded(library)
3158  || strlen(GetLibraries(library,"D",kFALSE)) != 0 ) {
3159  // The library has already been built and loaded.
3160 
3161  Bool_t reload = kFALSE;
3162  TNamed *libinfo = (TNamed*)fCompiled->FindObject(library);
3163  if (libinfo) {
3164  Long_t load_time = libinfo->GetUniqueID();
3165  Long_t lib_time;
3166  if ( gSystem->GetPathInfo( library, 0, (Long_t*)0, 0, &lib_time ) == 0
3167  && (lib_time>load_time)) {
3168  reload = kTRUE;
3169  }
3170  }
3171 
3172  if ( !recompile && reload ) {
3173 
3174  if (withInfo) {
3175  ::Info("ACLiC","%s has been modified and will be reloaded",
3176  libname.Data());
3177  }
3178  if ( gInterpreter->UnloadFile( library.Data() ) != 0 ) {
3179  // The library is being used. We can not unload it.
3180  return kFALSE;
3181  }
3182  if (libinfo) {
3183  fCompiled->Remove(libinfo);
3184  delete libinfo;
3185  libinfo = 0;
3186  }
3187  TNamed *k = new TNamed(library,library);
3188  Long_t lib_time;
3189  gSystem->GetPathInfo( library, 0, (Long_t*)0, 0, &lib_time );
3190  k->SetUniqueID(lib_time);
3191  if (!keep) k->SetBit(kMustCleanup);
3192  fCompiled->Add(k);
3193 
3194  return !gSystem->Load(library);
3195  }
3196 
3197  if (withInfo) {
3198  ::Info("ACLiC","%s script has already been compiled and loaded",
3199  modified ? "modified" : "unmodified");
3200  }
3201 
3202  if ( !recompile ) {
3203  return kTRUE;
3204  } else {
3205  if (withInfo) {
3206  ::Info("ACLiC","it will be regenerated and reloaded!");
3207  }
3208  if ( gInterpreter->UnloadFile( library.Data() ) != 0 ) {
3209  // The library is being used. We can not unload it.
3210  return kFALSE;
3211  }
3212  if (libinfo) {
3213  fCompiled->Remove(libinfo);
3214  delete libinfo;
3215  libinfo = 0;
3216  }
3217  Unlink(library);
3218  }
3219 
3220  }
3221 
3222  TString libmapfilename;
3223  AssignAndDelete( libmapfilename, ConcatFileName( build_loc, libname ) );
3224  libmapfilename += ".rootmap";
3225 #if (defined(R__MACOSX) && !defined(MAC_OS_X_VERSION_10_5)) || defined(R__WIN32)
3226  Bool_t produceRootmap = kTRUE;
3227 #else
3228  Bool_t produceRootmap = kFALSE;
3229 #endif
3230  Bool_t linkDepLibraries = !produceRootmap;
3231  if (gEnv) {
3232 #if (defined(R__MACOSX) && !defined(MAC_OS_X_VERSION_10_5))
3233  Int_t linkLibs = gEnv->GetValue("ACLiC.LinkLibs",2);
3234 #elif defined(R__WIN32)
3235  Int_t linkLibs = gEnv->GetValue("ACLiC.LinkLibs",3);
3236 #else
3237  Int_t linkLibs = gEnv->GetValue("ACLiC.LinkLibs",1);
3238 #endif
3239  produceRootmap = linkLibs & 0x2;
3240  linkDepLibraries = linkLibs & 0x1;
3241  }
3242 
3243  if (!recompile) {
3244  // The library already exist, let's just load it.
3245  if (loadLib) {
3246  TNamed *k = new TNamed(library,library);
3247  Long_t lib_time;
3248  gSystem->GetPathInfo( library, 0, (Long_t*)0, 0, &lib_time );
3249  k->SetUniqueID(lib_time);
3250  if (!keep) k->SetBit(kMustCleanup);
3251  fCompiled->Add(k);
3252 
3253  if (gInterpreter->GetSharedLibDeps(libname) == 0) {
3254  gInterpreter->LoadLibraryMap(libmapfilename);
3255  }
3256 
3257  return !gSystem->Load(library);
3258  }
3259  else return kTRUE;
3260  }
3261 
3262  if (!canWrite && recompile) {
3263 
3264  if (mkdirFailed) {
3265  ::Warning("ACLiC","Could not create the directory: %s",
3266  build_loc.Data());
3267  } else {
3268  ::Warning("ACLiC","%s is not writable!",
3269  build_loc.Data());
3270  }
3271  if (emergency_loc == build_dir ) {
3272  ::Error("ACLiC","%s is the last resort location (i.e. temp location)",build_loc.Data());
3273  return kFALSE;
3274  }
3275  ::Warning("ACLiC","Output will be written to %s",
3276  emergency_loc.Data());
3277  return CompileMacro(expFileName, opt, library_specified, emergency_loc, dirmode);
3278  }
3279 
3280  if (withInfo) {
3281  Info("ACLiC","creating shared library %s",library.Data());
3282  }
3283 
3284  R__WriteDependencyFile(build_loc, depfilename, filename_fullpath, library, libname, extension, version_var_prefix, includes, defines, incPath);
3285 
3286  // ======= Select the dictionary name
3287  TString dict = libname + "_ACLiC_dict";
3288 
3289  // the file name end up in the file produced
3290  // by rootcint as a variable name so all character need to be valid!
3291  static const int maxforbidden = 27;
3292  static const char *forbidden_chars[maxforbidden] =
3293  { "+","-","*","/","&","%","|","^",">","<",
3294  "=","~",".","(",")","[","]","!",",","$",
3295  " ",":","'","#","@","\\","\"" };
3296  for( int ic = 0; ic < maxforbidden; ic++ ) {
3297  dict.ReplaceAll( forbidden_chars[ic],"_" );
3298  }
3299  if ( dict.Last('.')!=dict.Length()-1 ) dict.Append(".");
3300  AssignAndDelete( dict, ConcatFileName( build_loc, dict ) );
3301  TString dicth = dict;
3302  TString dictObj = dict;
3303  dict += "cxx"; //no need to keep the extension of the original file, any extension will do
3304  dicth += "h";
3305  dictObj += fObjExt;
3306 
3307  // ======= Generate a linkdef file
3308 
3309  TString linkdef;
3310  AssignAndDelete( linkdef, ConcatFileName( build_loc, libname ) );
3311  linkdef += "_ACLiC_linkdef.h";
3312  std::ofstream linkdefFile( linkdef, std::ios::out );
3313  linkdefFile << "// File Automatically generated by the ROOT Script Compiler "
3314  << std::endl;
3315  linkdefFile << std::endl;
3316  linkdefFile << "#ifdef __CINT__" << std::endl;
3317  linkdefFile << std::endl;
3318  linkdefFile << "#pragma link C++ nestedclasses;" << std::endl;
3319  linkdefFile << "#pragma link C++ nestedtypedefs;" << std::endl;
3320  linkdefFile << std::endl;
3321 
3322  // We want to look for a header file that has the same name as the macro
3323 
3324  const char * extensions[] = { ".h", ".hh", ".hpp", ".hxx", ".hPP", ".hXX" };
3325 
3326  int i;
3327  for (i = 0; i < 6; i++ ) {
3328  char * name;
3329  TString extra_linkdef = BaseName( libname_noext );
3330  extra_linkdef.Append(GetLinkdefSuffix());
3331  extra_linkdef.Append(extensions[i]);
3332  name = Which(incPath,extra_linkdef);
3333  if (name) {
3334  if (verboseLevel>4 && withInfo) {
3335  Info("ACLiC","including extra linkdef file: %s",name);
3336  }
3337  linkdefFile << "#include \"" << name << "\"" << std::endl;
3338  delete [] name;
3339  }
3340  }
3341 
3342  if (verboseLevel>5 && withInfo) {
3343  Info("ACLiC","looking for header in: %s",incPath.Data());
3344  }
3345  for (i = 0; i < 6; i++ ) {
3346  char * name;
3347  TString lookup = BaseName( libname_noext );
3348  lookup.Append(extensions[i]);
3349  name = Which(incPath,lookup);
3350  if (name) {
3351  linkdefFile << "#pragma link C++ defined_in "<<name<<";"<< std::endl;
3352  delete [] name;
3353  }
3354  }
3355  linkdefFile << "#pragma link C++ defined_in \""<<filename_fullpath << "\";" << std::endl;
3356  linkdefFile << std::endl;
3357  linkdefFile << "#endif" << std::endl;
3358  linkdefFile.close();
3359 
3360  // ======= Generate the list of rootmap files to be looked at
3361 
3362  TString mapfile;
3363  AssignAndDelete( mapfile, ConcatFileName( build_loc, libname ) );
3364  mapfile += "_ACLiC_map";
3365  TString mapfilein = mapfile + ".in";
3366  TString mapfileout = mapfile + ".out";
3367 
3368  Bool_t needLoadMap = kFALSE;
3369  if (gInterpreter->GetSharedLibDeps(libname) !=0 ) {
3370  gInterpreter->UnloadLibraryMap(libname);
3371  needLoadMap = kTRUE;
3372  }
3373 
3374  std::ofstream mapfileStream( mapfilein, std::ios::out );
3375  {
3376  TString name = ".rootmap";
3377  TString sname = "system.rootmap";
3378  TString file;
3379  AssignAndDelete(file, ConcatFileName(TROOT::GetEtcDir(), sname) );
3380  if (gSystem->AccessPathName(file)) {
3381  // for backward compatibility check also $ROOTSYS/system<name> if
3382  // $ROOTSYS/etc/system<name> does not exist
3383  AssignAndDelete(file, ConcatFileName(TROOT::GetRootSys(), sname));
3384  if (gSystem->AccessPathName(file)) {
3385  // for backward compatibility check also $ROOTSYS/<name> if
3386  // $ROOTSYS/system<name> does not exist
3387  AssignAndDelete(file, ConcatFileName(TROOT::GetRootSys(), name));
3388  }
3389  }
3390  mapfileStream << file << std::endl;
3391  AssignAndDelete(file, ConcatFileName(gSystem->HomeDirectory(), name) );
3392  mapfileStream << file << std::endl;
3393  mapfileStream << name << std::endl;
3394  if (gInterpreter->GetRootMapFiles()) {
3395  for (i = 0; i < gInterpreter->GetRootMapFiles()->GetEntriesFast(); i++) {
3396  mapfileStream << ((TNamed*)gInterpreter->GetRootMapFiles()->At(i))->GetTitle() << std::endl;
3397  }
3398  }
3399  }
3400  mapfileStream.close();
3401 
3402  // ======= Generate the rootcling command line
3403  TString rcling = "rootcling";
3404  PrependPathName(TROOT::GetBinDir(), rcling);
3405  rcling += " -v0 \"--lib-list-prefix=";
3406  rcling += mapfile;
3407  rcling += "\" -f \"";
3408  rcling.Append(dict).Append("\" -c -p ");
3409  if (produceRootmap) {
3410  rcling += " -rml " + libname + " -rmf \"" + libmapfilename + "\" ";
3411  }
3412  rcling.Append(GetIncludePath()).Append(" -D__ACLIC__ ");
3413  if (produceRootmap) {
3414  rcling.Append("-DR__ACLIC_ROOTMAP ");
3415  }
3416  if (gEnv) {
3417  TString fromConfig = gEnv->GetValue("ACLiC.IncludePaths","");
3418  rcling.Append(fromConfig).Append(" \"");
3419  }
3420  rcling.Append(filename_fullpath).Append("\" \"").Append(linkdef).Append("\"");;
3421 
3422  // ======= Run rootcint
3423  if (withInfo) {
3424  if (verboseLevel>3) {
3425  ::Info("ACLiC","creating the dictionary files");
3426  if (verboseLevel>4) ::Info("ACLiC", "%s", rcling.Data());
3427  }
3428  }
3429 
3430  Int_t dictResult = gSystem->Exec(rcling);
3431  if (dictResult) {
3432  if (dictResult==139) ::Error("ACLiC","Dictionary generation failed with a core dump!");
3433  else ::Error("ACLiC","Dictionary generation failed!");
3434  }
3435 
3436  Bool_t result = !dictResult;
3437  TString depLibraries;
3438 
3439  // ======= Load the library the script might depend on
3440  if (result) {
3441  TString linkedlibs = GetLibraries("", "S");
3442  TString libtoload;
3443  TString all_libtoload;
3444  std::ifstream liblist(mapfileout);
3445 
3446  while ( liblist >> libtoload ) {
3447  // Load the needed library except for the library we are currently building!
3448  if (libtoload == "#") {
3449  // The comment terminates the list of libraries.
3450  std::string toskipcomment;
3451  std::getline(liblist,toskipcomment);
3452  break;
3453  }
3454  if (libtoload != library && libtoload != libname && libtoload != libname_ext) {
3455  if (produceRootmap) {
3456  if (loadLib || linkDepLibraries /* For GetLibraries to Work */) {
3457  result = gROOT->LoadClass("", libtoload) >= 0;
3458  if (!result) {
3459  // We failed to load one of the dependency.
3460  break;
3461  }
3462  }
3463  if (!linkedlibs.Contains(libtoload)) {
3464  all_libtoload.Append(" ").Append(libtoload);
3465  depLibraries.Append(" ");
3466  depLibraries.Append(GetLibraries(libtoload,"DSL",kFALSE));
3467  depLibraries = depLibraries.Strip(); // Remove any trailing spaces.
3468  }
3469  } else {
3470  gROOT->LoadClass("", libtoload);
3471  }
3472  }
3473  unsigned char c = liblist.peek();
3474  if (c=='\n' || c=='\r') {
3475  // Consume the character
3476  liblist.get();
3477  break;
3478  }
3479  }
3480 
3481 // depLibraries = all_libtoload;
3482 // depLibraries.ReplaceAll(" lib"," -l");
3483 // depLibraries.ReplaceAll(TString::Format(".%s",fSoExt.Data()),"");
3484  }
3485 
3486  // ======= Calculate the libraries for linking:
3487  TString linkLibraries;
3488  /*
3489  this is intentionally disabled until it can become useful
3490  if (gEnv) {
3491  linkLibraries = gEnv->GetValue("ACLiC.Libraries","");
3492  linkLibraries.Prepend(" ");
3493  }
3494  */
3495  TString linkLibrariesNoQuotes(GetLibraries("","SDL"));
3496  // We need to enclose the single paths in quotes to account for paths with spaces
3497  TString librariesWithQuotes;
3498  TString singleLibrary;
3499  Bool_t collectingSingleLibraryNameTokens = kFALSE;
3500  for (auto tokenObj : *linkLibrariesNoQuotes.Tokenize(" ")) {
3501  singleLibrary = ((TObjString*)tokenObj)->GetString();
3502  if (!AccessPathName(singleLibrary)) {
3503  if (collectingSingleLibraryNameTokens) {
3504  librariesWithQuotes.Chop();
3505  librariesWithQuotes += "\" \"" + singleLibrary + "\"";
3506  collectingSingleLibraryNameTokens = kFALSE;
3507  } else {
3508  librariesWithQuotes += " \"" + singleLibrary + "\"";
3509  }
3510  } else {
3511  if (collectingSingleLibraryNameTokens) {
3512  librariesWithQuotes += singleLibrary + " ";
3513  } else {
3514  collectingSingleLibraryNameTokens = kTRUE;
3515  librariesWithQuotes += " \"" + singleLibrary + " ";
3516  }
3517  }
3518  }
3519 
3520  linkLibraries.Prepend(librariesWithQuotes);
3521 
3522  // ======= Generate the build command lines
3523  TString cmd = fMakeSharedLib;
3524  // we do not add filename because it is already included via the dictionary(in dicth) !
3525  // dict.Append(" ").Append(filename);
3526  cmd.ReplaceAll("$SourceFiles","-D__ACLIC__ \"$SourceFiles\"");
3527  cmd.ReplaceAll("$SourceFiles",dict);
3528  cmd.ReplaceAll("$ObjectFiles","\"$ObjectFiles\"");
3529  cmd.ReplaceAll("$ObjectFiles",dictObj);
3530  cmd.ReplaceAll("$IncludePath",includes);
3531  cmd.ReplaceAll("$SharedLib","\"$SharedLib\"");
3532  cmd.ReplaceAll("$SharedLib",library);
3533  if (linkDepLibraries) {
3534  if (produceRootmap) {
3535  cmd.ReplaceAll("$DepLibs",depLibraries);
3536  } else {
3537  cmd.ReplaceAll("$DepLibs",linkLibraries);
3538  }
3539  }
3540  cmd.ReplaceAll("$LinkedLibs",linkLibraries);
3541  cmd.ReplaceAll("$LibName",libname);
3542  cmd.ReplaceAll("\"$BuildDir","$BuildDir");
3543  cmd.ReplaceAll("$BuildDir","\"$BuildDir\"");
3544  cmd.ReplaceAll("$BuildDir",build_loc);
3545  if (mode==kDebug) {
3546  cmd.ReplaceAll("$Opt",fFlagsDebug);
3547  } else {
3548  cmd.ReplaceAll("$Opt",fFlagsOpt);
3549  }
3550 #ifdef WIN32
3551  R__FixLink(cmd);
3552 #endif
3553 
3554  TString testcmd = fMakeExe;
3555  TString fakeMain;
3556  AssignAndDelete( fakeMain, ConcatFileName( build_loc, libname ) );
3557  fakeMain += "_ACLiC_main";
3558  fakeMain += extension;
3559  std::ofstream fakeMainFile( fakeMain, std::ios::out );
3560  fakeMainFile << "// File Automatically generated by the ROOT Script Compiler "
3561  << std::endl;
3562  fakeMainFile << "int main(char*argc,char**argvv) {};" << std::endl;
3563  fakeMainFile.close();
3564  // We could append this fake main routine to the compilation line.
3565  // But in this case compiler may output the name of the dictionary file
3566  // and of the fakeMain file while it compiles it. (this would be useless
3567  // confusing output).
3568  // We could also the fake main routine to the end of the dictionary file
3569  // however compilation would fail if a main is already there
3570  // (like stress.cxx)
3571  // dict.Append(" ").Append(fakeMain);
3572  TString exec;
3573  AssignAndDelete( exec, ConcatFileName( build_loc, libname ) );
3574  exec += "_ACLiC_exec";
3575  testcmd.ReplaceAll("$SourceFiles","-D__ACLIC__ \"$SourceFiles\"");
3576  testcmd.ReplaceAll("$SourceFiles",dict);
3577  testcmd.ReplaceAll("$ObjectFiles","\"$ObjectFiles\"");
3578  testcmd.ReplaceAll("$ObjectFiles",dictObj);
3579  testcmd.ReplaceAll("$IncludePath",includes);
3580  testcmd.ReplaceAll("$ExeName",exec);
3581  testcmd.ReplaceAll("$LinkedLibs",linkLibraries);
3582  testcmd.ReplaceAll("$BuildDir",build_loc);
3583  if (mode==kDebug)
3584  testcmd.ReplaceAll("$Opt",fFlagsDebug);
3585  else
3586  testcmd.ReplaceAll("$Opt",fFlagsOpt);
3587 
3588 #ifdef WIN32
3589  R__FixLink(testcmd);
3590 #endif
3591 
3592  // ======= Build the library
3593  if (result) {
3594  if (verboseLevel>3 && withInfo) {
3595  ::Info("ACLiC","compiling the dictionary and script files");
3596  if (verboseLevel>4) ::Info("ACLiC", "%s", cmd.Data());
3597  }
3598  Int_t compilationResult = gSystem->Exec( cmd );
3599  if (compilationResult) {
3600  if (compilationResult==139) ::Error("ACLiC","Compilation failed with a core dump!");
3601  else ::Error("ACLiC","Compilation failed!");
3602  if (produceRootmap) {
3603  gSystem->Unlink(libmapfilename);
3604  }
3605  }
3606  result = !compilationResult;
3607  }
3608 
3609  if ( result ) {
3610 
3611  TNamed *k = new TNamed(library,library);
3612  Long_t lib_time;
3613  gSystem->GetPathInfo( library, 0, (Long_t*)0, 0, &lib_time );
3614  k->SetUniqueID(lib_time);
3615  if (!keep) k->SetBit(kMustCleanup);
3616  fCompiled->Add(k);
3617 
3618  if (needLoadMap) {
3619  gInterpreter->LoadLibraryMap(libmapfilename);
3620  }
3621  if (verboseLevel>3 && withInfo) ::Info("ACLiC","loading the shared library");
3622  if (loadLib) result = !gSystem->Load(library);
3623  else result = kTRUE;
3624 
3625  if ( !result ) {
3626  if (verboseLevel>3 && withInfo) {
3627  ::Info("ACLiC","testing for missing symbols:");
3628  if (verboseLevel>4) ::Info("ACLiC", "%s", testcmd.Data());
3629  }
3630  gSystem->Exec(testcmd);
3631  gSystem->Unlink( exec );
3632  }
3633 
3634  };
3635 
3636  if (verboseLevel<=5 && !internalDebug) {
3637  gSystem->Unlink( dict );
3638  gSystem->Unlink( dicth );
3639  gSystem->Unlink( dictObj );
3640  gSystem->Unlink( linkdef );
3641  gSystem->Unlink( mapfilein );
3642  gSystem->Unlink( mapfileout );
3643  gSystem->Unlink( fakeMain );
3644  gSystem->Unlink( exec );
3645  }
3646  if (verboseLevel>6) {
3647  rcling.Prepend("echo ");
3648  cmd.Prepend("echo \" ").Append(" \" ");
3649  testcmd.Prepend("echo \" ").Append(" \" ");
3650  gSystem->Exec(rcling);
3651  gSystem->Exec( cmd );
3652  gSystem->Exec(testcmd);
3653  }
3654 
3655  return result;
3656 }
3657 
3658 ////////////////////////////////////////////////////////////////////////////////
3659 /// Return the ACLiC properties field. See EAclicProperties for details
3660 /// on the semantic of each bit.
3661 
3663 {
3664  return fAclicProperties;
3665 }
3666 
3667 ////////////////////////////////////////////////////////////////////////////////
3668 /// Return the build architecture.
3669 
3670 const char *TSystem::GetBuildArch() const
3671 {
3672  return fBuildArch;
3673 }
3674 
3675 ////////////////////////////////////////////////////////////////////////////////
3676 /// Return the build compiler
3677 
3678 const char *TSystem::GetBuildCompiler() const
3679 {
3680  return fBuildCompiler;
3681 }
3682 
3683 ////////////////////////////////////////////////////////////////////////////////
3684 /// Return the build compiler version
3685 
3687 {
3688  return fBuildCompilerVersion;
3689 }
3690 
3691 ////////////////////////////////////////////////////////////////////////////////
3692 /// Return the build node name.
3693 
3694 const char *TSystem::GetBuildNode() const
3695 {
3696  return fBuildNode;
3697 }
3698 
3699 ////////////////////////////////////////////////////////////////////////////////
3700 /// Return the path of the build directory.
3701 
3702 const char *TSystem::GetBuildDir() const
3703 {
3704  if (fBuildDir.Length()==0) {
3705  if (!gEnv) return "";
3706  const_cast<TSystem*>(this)->fBuildDir = gEnv->GetValue("ACLiC.BuildDir","");
3707  }
3708  return fBuildDir;
3709 }
3710 
3711 ////////////////////////////////////////////////////////////////////////////////
3712 /// Return the debug flags.
3713 
3714 const char *TSystem::GetFlagsDebug() const
3715 {
3716  return fFlagsDebug;
3717 }
3718 
3719 ////////////////////////////////////////////////////////////////////////////////
3720 /// Return the optimization flags.
3721 
3722 const char *TSystem::GetFlagsOpt() const
3723 {
3724  return fFlagsOpt;
3725 }
3726 
3727 ////////////////////////////////////////////////////////////////////////////////
3728 /// AclicMode indicates whether the library should be built in
3729 /// debug mode or optimized. The values are:
3730 /// - TSystem::kDefault : compile the same as the current ROOT
3731 /// - TSystem::kDebug : compiled in debug mode
3732 /// - TSystem::kOpt : optimized the library
3733 
3735 {
3736  return fAclicMode;
3737 }
3738 
3739 ////////////////////////////////////////////////////////////////////////////////
3740 /// Return the command line use to make a shared library.
3741 /// See TSystem::CompileMacro for more details.
3742 
3743 const char *TSystem::GetMakeSharedLib() const
3744 {
3745  return fMakeSharedLib;
3746 }
3747 
3748 ////////////////////////////////////////////////////////////////////////////////
3749 /// Return the command line use to make an executable.
3750 /// See TSystem::CompileMacro for more details.
3751 
3752 const char *TSystem::GetMakeExe() const
3753 {
3754  return fMakeExe;
3755 }
3756 
3757 ////////////////////////////////////////////////////////////////////////////////
3758 /// Get the list of include path.
3759 
3761 {
3762  fListPaths = fIncludePath;
3763  fListPaths.Append(" ").Append(gInterpreter->GetIncludePath());
3764  return fListPaths;
3765 }
3766 
3767 ////////////////////////////////////////////////////////////////////////////////
3768 /// Return the list of library linked to this executable.
3769 /// See TSystem::CompileMacro for more details.
3770 
3771 const char *TSystem::GetLinkedLibs() const
3772 {
3773  return fLinkedLibs;
3774 }
3775 
3776 ////////////////////////////////////////////////////////////////////////////////
3777 /// Return the linkdef suffix chosen by the user for ACLiC.
3778 /// See TSystem::CompileMacro for more details.
3779 
3780 const char *TSystem::GetLinkdefSuffix() const
3781 {
3782  if (fLinkdefSuffix.Length()==0) {
3783  if (!gEnv) return "_linkdef";
3784  const_cast<TSystem*>(this)->fLinkdefSuffix = gEnv->GetValue("ACLiC.Linkdef","_linkdef");
3785  }
3786  return fLinkdefSuffix;
3787 }
3788 
3789 ////////////////////////////////////////////////////////////////////////////////
3790 /// Get the shared library extension.
3791 
3792 const char *TSystem::GetSoExt() const
3793 {
3794  return fSoExt;
3795 }
3796 
3797 ////////////////////////////////////////////////////////////////////////////////
3798 /// Get the object file extension.
3799 
3800 const char *TSystem::GetObjExt() const
3801 {
3802  return fObjExt;
3803 }
3804 
3805 ////////////////////////////////////////////////////////////////////////////////
3806 /// Set the location where ACLiC will create libraries and use as
3807 /// a scratch area.
3808 ///
3809 /// If isflast is flase, then the libraries are actually stored in
3810 /// sub-directories of 'build_dir' including the full pathname of the
3811 /// script. If the script is location at /full/path/name/macro.C
3812 /// the library will be located at 'build_dir+/full/path/name/macro_C.so'
3813 /// If 'isflat' is true, then no subdirectory is created and the library
3814 /// is created directly in the directory 'build_dir'. Note that in this
3815 /// mode there is a risk than 2 script of the same in different source
3816 /// directory will over-write each other.
3817 
3818 void TSystem::SetBuildDir(const char* build_dir, Bool_t isflat)
3819 {
3820  fBuildDir = build_dir;
3821  if (isflat) fAclicProperties |= (kFlatBuildDir & kBitMask);
3822  else fAclicProperties &= ~(kFlatBuildDir & kBitMask);
3823 }
3824 
3825 ////////////////////////////////////////////////////////////////////////////////
3826 /// FlagsDebug should contain the options to pass to the C++ compiler
3827 /// in order to compile the library in debug mode.
3828 
3829 void TSystem::SetFlagsDebug(const char *flags)
3830 {
3831  fFlagsDebug = flags;
3832 }
3833 
3834 ////////////////////////////////////////////////////////////////////////////////
3835 /// FlagsOpt should contain the options to pass to the C++ compiler
3836 /// in order to compile the library in optimized mode.
3837 
3838 void TSystem::SetFlagsOpt(const char *flags)
3839 {
3840  fFlagsOpt = flags;
3841 }
3842 
3843 ////////////////////////////////////////////////////////////////////////////////
3844 /// AclicMode indicates whether the library should be built in
3845 /// debug mode or optimized. The values are:
3846 /// - TSystem::kDefault : compile the same as the current ROOT
3847 /// - TSystem::kDebug : compiled in debug mode
3848 /// - TSystem::kOpt : optimized the library
3849 
3851 {
3852  fAclicMode = mode;
3853 }
3854 
3855 ////////////////////////////////////////////////////////////////////////////////
3856 /// Directives has the same syntax as the argument of SetMakeSharedLib but is
3857 /// used to create an executable. This creation is used as a means to output
3858 /// a list of unresolved symbols, when loading a shared library has failed.
3859 /// The required variable is $ExeName rather than $SharedLib, e.g.:
3860 /// ~~~ {.cpp}
3861 /// gSystem->SetMakeExe(
3862 /// "g++ -Wall -fPIC $IncludePath $SourceFiles
3863 /// -o $ExeName $LinkedLibs -L/usr/X11R6/lib -lX11 -lm -ldl -rdynamic");
3864 /// ~~~
3865 
3866 void TSystem::SetMakeExe(const char *directives)
3867 {
3868  fMakeExe = directives;
3869  // NOTE: add verification that the directives has the required variables
3870 }
3871 
3872 ////////////////////////////////////////////////////////////////////////////////
3873 /// Directives should contain the description on how to compile and link a
3874 /// shared lib. This description can be any valid shell command, including
3875 /// the use of ';' to separate several instructions. However, shell specific
3876 /// construct should be avoided. In particular this description can contain
3877 /// environment variables, like $ROOTSYS (or %ROOTSYS% on windows).
3878 /// ~~~ {.cpp}
3879 /// Five special variables will be expanded before execution:
3880 /// Variable name Expands to
3881 /// ------------- ----------
3882 /// $SourceFiles Name of source files to be compiled
3883 /// $SharedLib Name of the shared library being created
3884 /// $LibName Name of shared library without extension
3885 /// $BuildDir Directory where the files will be created
3886 /// $IncludePath value of fIncludePath
3887 /// $LinkedLibs value of fLinkedLibs
3888 /// $DepLibs libraries on which this library depends on
3889 /// $ObjectFiles Name of source files to be compiler with
3890 /// their extension changed to .o or .obj
3891 /// $Opt location of the optimization/debug options
3892 /// set fFlagsDebug and fFlagsOpt
3893 /// ~~~
3894 /// e.g.:
3895 /// ~~~ {.cpp}
3896 /// gSystem->SetMakeSharedLib(
3897 /// "KCC -n32 --strict $IncludePath -K0 \$Opt $SourceFile
3898 /// --no_exceptions --signed_chars --display_error_number
3899 /// --diag_suppress 68 -o $SharedLib");
3900 ///
3901 /// gSystem->setMakeSharedLib(
3902 /// "Cxx $IncludePath -c $SourceFile;
3903 /// ld -L/usr/lib/cmplrs/cxx -rpath /usr/lib/cmplrs/cxx -expect_unresolved
3904 /// \$Opt -shared /usr/lib/cmplrs/cc/crt0.o /usr/lib/cmplrs/cxx/_main.o
3905 /// -o $SharedLib $ObjectFile -lcxxstd -lcxx -lexc -lots -lc"
3906 ///
3907 /// gSystem->SetMakeSharedLib(
3908 /// "$HOME/mygcc/bin/g++ \$Opt -Wall -fPIC $IncludePath $SourceFile
3909 /// -shared -o $SharedLib");
3910 ///
3911 /// gSystem->SetMakeSharedLib(
3912 /// "cl -DWIN32 -D_WIN32 -D_MT -D_DLL -MD /O2 /G5 /MD -DWIN32
3913 /// -D_WINDOWS $IncludePath $SourceFile
3914 /// /link -PDB:NONE /NODEFAULTLIB /INCREMENTAL:NO /RELEASE /NOLOGO
3915 /// $LinkedLibs -entry:_DllMainCRTStartup@12 -dll /out:$SharedLib")
3916 /// ~~~
3917 
3918 void TSystem::SetMakeSharedLib(const char *directives)
3919 {
3920  fMakeSharedLib = directives;
3921  // NOTE: add verification that the directives has the required variables
3922 }
3923 
3924 ////////////////////////////////////////////////////////////////////////////////
3925 /// Add includePath to the already set include path.
3926 
3927 void TSystem::AddIncludePath(const char *includePath)
3928 {
3929  if (includePath) {
3930  fIncludePath += " ";
3931  fIncludePath += includePath;
3932  }
3933 }
3934 
3935 ////////////////////////////////////////////////////////////////////////////////
3936 /// Add linkedLib to already set linked libs.
3937 
3938 void TSystem::AddLinkedLibs(const char *linkedLib)
3939 {
3940  if (linkedLib) {
3941  fLinkedLibs += " ";
3942  fLinkedLibs += linkedLib;
3943  }
3944 }
3945 
3946 ////////////////////////////////////////////////////////////////////////////////
3947 /// IncludePath should contain the list of compiler flags to indicate where
3948 /// to find user defined header files. It is used to expand $IncludePath in
3949 /// the directives given to SetMakeSharedLib() and SetMakeExe(), e.g.:
3950 /// ~~~ {.cpp}
3951 /// gSystem->SetInclude("-I$ROOTSYS/include -Imydirectory/include");
3952 /// ~~~
3953 /// the default value of IncludePath on Unix is:
3954 /// ~~~ {.cpp}
3955 /// "-I$ROOTSYS/include "
3956 /// ~~~
3957 /// and on Windows:
3958 /// ~~~ {.cpp}
3959 /// "/I%ROOTSYS%/include "
3960 /// ~~~
3961 
3962 void TSystem::SetIncludePath(const char *includePath)
3963 {
3964  fIncludePath = includePath;
3965 }
3966 
3967 ////////////////////////////////////////////////////////////////////////////////
3968 /// LinkedLibs should contain the library directory and list of libraries
3969 /// needed to recreate the current executable. It is used to expand $LinkedLibs
3970 /// in the directives given to SetMakeSharedLib() and SetMakeExe()
3971 /// The default value on Unix is: `root-config --glibs`
3972 
3973 void TSystem::SetLinkedLibs(const char *linkedLibs)
3974 {
3975  fLinkedLibs = linkedLibs;
3976 }
3977 
3978 ////////////////////////////////////////////////////////////////////////////////
3979 /// The 'suffix' will be appended to the name of a script loaded by ACLiC
3980 /// and used to locate any eventual additional linkdef information that
3981 /// ACLiC should used to produce the dictionary.
3982 ///
3983 /// So by default, when doing .L MyScript.cxx, ACLiC will look
3984 /// for a file name MyScript_linkdef and having one of the .h (.hpp,
3985 /// etc.) extensions. If such a file exist, it will be added to
3986 /// the end of the linkdef file used to created the ACLiC dictionary.
3987 /// This effectively enable the full customization of the creation
3988 /// of the dictionary. It should be noted that the file is intended
3989 /// as a linkdef `fragment`, so usually you would not list the
3990 /// typical:
3991 ///~~~ {.cpp}
3992 /// #pragma link off ....
3993 ///~~~
3994 
3995 void TSystem::SetLinkdefSuffix(const char *suffix)
3996 {
3997  fLinkdefSuffix = suffix;
3998 }
3999 
4000 
4001 ////////////////////////////////////////////////////////////////////////////////
4002 /// Set shared library extension, should be either .so, .sl, .a, .dll, etc.
4003 
4004 void TSystem::SetSoExt(const char *SoExt)
4005 {
4006  fSoExt = SoExt;
4007 }
4008 
4009 ////////////////////////////////////////////////////////////////////////////////
4010 /// Set object files extension, should be either .o, .obj, etc.
4011 
4012 void TSystem::SetObjExt(const char *ObjExt)
4013 {
4014  fObjExt = ObjExt;
4015 }
4016 
4017 ////////////////////////////////////////////////////////////////////////////////
4018 /// This method split a filename of the form:
4019 /// ~~~ {.cpp}
4020 /// [path/]macro.C[+|++[k|f|g|O|c|s|d|v|-]][(args)].
4021 /// ~~~
4022 /// It stores the ACliC mode [+|++[options]] in 'mode',
4023 /// the arguments (including parenthesis) in arg
4024 /// and the I/O indirection in io
4025 
4026 TString TSystem::SplitAclicMode(const char* filename, TString &aclicMode,
4027  TString &arguments, TString &io) const
4028 {
4029  char *fname = Strip(filename);
4030 
4031  char *arg = strchr(fname, '(');
4032  // special case for $(HOME)/aap.C(10)
4033  while (arg && *arg && (arg > fname && *(arg-1) == '$') && *(arg+1))
4034  arg = strchr(arg+1, '(');
4035  if (arg && arg > fname) {
4036  *arg = 0;
4037  char *t = arg-1;
4038  while (*t == ' ') {
4039  *t = 0; t--;
4040  }
4041  arg++;
4042  }
4043 
4044  // strip off I/O redirect tokens from filename
4045  {
4046  char *s2 = 0;
4047  char *s3;
4048  s2 = strstr(fname, ">>");
4049  if (!s2) s2 = strstr(fname, "2>");
4050  if (!s2) s2 = strchr(fname, '>');
4051  s3 = strchr(fname, '<');
4052  if (s2 && s3) s2 = s2<s3 ? s2 : s3;
4053  if (s3 && !s2) s2 = s3;
4054  if (s2==fname) {
4055  io = fname;
4056  aclicMode = "";
4057  arguments = "";
4058  delete []fname;
4059  return "";
4060  } else if (s2) {
4061  s2--;
4062  while (s2 && *s2 == ' ') s2--;
4063  s2++;
4064  io = s2; // ssave = *s2;
4065  *s2 = 0;
4066  } else
4067  io = "";
4068  }
4069 
4070  // remove the possible ACLiC + or ++ and g or O etc
4071  aclicMode.Clear();
4072  int len = strlen(fname);
4073  TString mode;
4074  while (len > 1) {
4075  if (strchr("kfgOcsdv-", fname[len - 1])) {
4076  mode += fname[len - 1];
4077  --len;
4078  } else {
4079  break;
4080  }
4081  }
4082  Bool_t compile = len && fname[len - 1] == '+';
4083  Bool_t remove = compile && len > 1 && fname[len - 2] == '+';
4084  if (compile) {
4085  if (mode.Length()) {
4086  fname[len] = 0;
4087  }
4088  if (remove) {
4089  fname[strlen(fname)-2] = 0;
4090  aclicMode = "++";
4091  } else {
4092  fname[strlen(fname)-1] = 0;
4093  aclicMode = "+";
4094  }
4095  if (mode.Length())
4096  aclicMode += mode;
4097  }
4098 
4099  TString resFilename = fname;
4100  arguments = "(";
4101  if (arg) arguments += arg;
4102  else arguments = "";
4103 
4104  delete []fname;
4105  return resFilename;
4106 }
4107 
4108 ////////////////////////////////////////////////////////////////////////////////
4109 /// Remove the shared libs produced by the CompileMacro() function.
4110 
4112 {
4113  TIter next(fCompiled);
4114  TNamed *lib;
4115  while ((lib = (TNamed*)next())) {
4116  if (lib->TestBit(kMustCleanup)) Unlink(lib->GetTitle());
4117  }
4118 }
4119 
4120 ////////////////////////////////////////////////////////////////////////////////
4121 /// Register version of plugin library.
4122 
4124 {
4125  if (versionCode != TROOT::RootVersionCode() && gLibraryVersion)
4126  gLibraryVersion[gLibraryVersionIdx] = versionCode;
4127 }
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:928
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
Definition: TObject.cxx:932
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1264
virtual void Add(TObject *obj)
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition: TObject.cxx:433
double read(const std::string &file_name)
reading
virtual Bool_t IsAbsoluteFileName(const char *dir)
Return true if dir is an absolute pathname.
Definition: TSystem.cxx:945
virtual int GetPid()
Get process id.
Definition: TSystem.cxx:711
An array of TObjects.
Definition: TObjArray.h:39
virtual int GetCpuInfo(CpuInfo_t *info, Int_t sampleTime=1000) const
Returns cpu load average and load info into the CpuInfo_t structure.
Definition: TSystem.cxx:2410
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:420
virtual void Syslog(ELogLevel level, const char *mess)
Send mess to syslog daemon.
Definition: TSystem.cxx:1647
virtual const char * GetFlagsOpt() const
Return the optimization flags.
Definition: TSystem.cxx:3722
int GetErrno()
return errno
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
virtual const char * GetBuildCompilerVersion() const
Return the build compiler version.
Definition: TSystem.cxx:3686
virtual Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in &#39;path&#39; points to the local file system.
Definition: TSystem.cxx:1273
const char * GetHostAddress() const
Returns the IP address string "%d.%d.%d.%d".
Bool_t ProcessEvents()
Process events if timer did time out.
Definition: TSystem.cxx:81
long long Long64_t
Definition: RtypesCore.h:69
Int_t fReadOffSet
Definition: TSystem.h:220
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:865
virtual void StackTrace()
Print a stack trace.
Definition: TSystem.cxx:736
EAclicMode
Definition: TSystem.h:261
void Reset()
Reset the timer.
Definition: TTimer.cxx:155
virtual void SetFlagsDebug(const char *)
FlagsDebug should contain the options to pass to the C++ compiler in order to compile the library in ...
Definition: TSystem.cxx:3829
virtual void NotifyApplicationCreated()
Hook to tell TSystem that the TApplication object has been created.
Definition: TSystem.cxx:315
TLine * line
Collectable string class.
Definition: TObjString.h:32
virtual const char * GetLinkedLibs() const
Return the list of library linked to this executable.
Definition: TSystem.cxx:3771
const char Option_t
Definition: RtypesCore.h:62
const char * GetHostName() const
Definition: TInetAddress.h:75
virtual int Link(const char *from, const char *to)
Create a link from file1 to file2.
Definition: TSystem.cxx:1327
virtual TString SplitAclicMode(const char *filename, TString &mode, TString &args, TString &io) const
This method split a filename of the form: ~~~ {.cpp} [path/]macro.C[+|++[k|f|g|O|c|s|d|v|-]][(args)]...
Definition: TSystem.cxx:4026
virtual void SetFlagsOpt(const char *)
FlagsOpt should contain the options to pass to the C++ compiler in order to compile the library in op...
Definition: TSystem.cxx:3838
virtual const char * GetLinkedLibraries()
Get list of shared libraries loaded at the start of the executable.
Definition: TSystem.cxx:2053
void RemoveOnExit(TObject *obj)
Objects that should be deleted on exit of the OS interface.
Definition: TSystem.cxx:296
virtual Int_t SetFPEMask(Int_t mask=kDefaultMask)
Set which conditions trigger a floating point exception.
Definition: TSystem.cxx:646
This class represents a WWW compatible URL.
Definition: TUrl.h:41
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
virtual const char * GetBuildNode() const
Return the build node name.
Definition: TSystem.cxx:3694
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.
Definition: TSystem.cxx:1362
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
const char * GetProtocol() const
Definition: TUrl.h:73
static Int_t RootVersionCode()
Return ROOT version code as defined in RVersion.h.
Definition: TROOT.cxx:2493
TH1 * h
Definition: legend2.C:5
virtual TString GetFromPipe(const char *command)
Execute command and return output in TString.
Definition: TSystem.cxx:684
This class represents an Internet Protocol (IP) address.
Definition: TInetAddress.h:40
virtual int MakeDirectory(const char *name)
Make a directory.
Definition: TSystem.cxx:821
virtual void AddSignalHandler(TSignalHandler *sh)
Add a signal handler to list of system signal handlers.
Definition: TSystem.cxx:536
virtual const char * HomeDirectory(const char *userName=0)
Return the user&#39;s home directory.
Definition: TSystem.cxx:881
virtual void CloseConnection(int sock, Bool_t force=kFALSE)
Close socket connection.
Definition: TSystem.cxx:2331
Regular expression class.
Definition: TRegexp.h:35
This class implements a mutex interface.
Definition: TVirtualMutex.h:34
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition: TSystem.cxx:856
static const char * filename()
TVersionCheck(int versionCode)
Register version of plugin library.
Definition: TSystem.cxx:4123
#define gROOT
Definition: TROOT.h:352
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
virtual UserGroup_t * GetGroupInfo(Int_t gid)
Returns all group info in the UserGroup_t structure.
Definition: TSystem.cxx:1586
virtual int GetFsInfo(const char *path, Long_t *id, Long_t *bsize, Long_t *blocks, Long_t *bfree)
Get info about a file system: fs type, block size, number of blocks, number of free blocks...
Definition: TSystem.cxx:1436
virtual void SetMakeExe(const char *directives)
Directives has the same syntax as the argument of SetMakeSharedLib but is used to create an executabl...
Definition: TSystem.cxx:3866
Int_t LoadPlugin()
Load the plugin library for this handler.
virtual void Remove()
Remove std::exception handler from system handler list.
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1817
virtual void AddStdExceptionHandler(TStdExceptionHandler *eh)
Add an exception handler to list of system exception handlers.
Definition: TSystem.cxx:615
Basic string class.
Definition: TString.h:137
virtual void ResetSignal(ESignals sig, Bool_t reset=kTRUE)
If reset is true reset the signal handler for the specified signal to the default handler...
Definition: TSystem.cxx:580
virtual int GetMemInfo(MemInfo_t *info) const
Returns ram and swap memory usage info into the MemInfo_t structure.
Definition: TSystem.cxx:2420
static void R__AddPath(TString &target, const TString &path)
Definition: TSystem.cxx:2497
int Int_t
Definition: RtypesCore.h:41
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:996
bool Bool_t
Definition: RtypesCore.h:59
virtual TTimer * RemoveTimer(TTimer *t)
Remove timer from list of system timers.
Definition: TSystem.cxx:485
TArc * a
Definition: textangle.C:12
const Bool_t kFALSE
Definition: Rtypes.h:92
#define ENDTRY
Definition: TException.h:79
static const TString & GetRootSys()
Get the rootsys directory in the installation. Static utility function.
Definition: TROOT.cxx:2517
virtual const char * GetSoExt() const
Get the shared library extension.
Definition: TSystem.cxx:3792
#define gInterpreter
Definition: TInterpreter.h:502
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1510
Long_t fMtime
Definition: TSystem.h:142
virtual void SetMakeSharedLib(const char *directives)
Directives should contain the description on how to compile and link a shared lib.
Definition: TSystem.cxx:3918
virtual int AnnounceUdpService(int port, int backlog)
Announce UDP service.
Definition: TSystem.cxx:2295
virtual FILE * OpenPipe(const char *command, const char *mode)
Open a pipe.
Definition: TSystem.cxx:666
virtual const char * GetFlagsDebug() const
Return the debug flags.
Definition: TSystem.cxx:3714
TString & Prepend(const char *cs)
Definition: TString.h:604
R__EXTERN TApplication * gApplication
Definition: TApplication.h:171
TObject * At(Int_t idx) const
Definition: TObjArray.h:167
virtual void ResetSignals()
Reset signals handlers to previous behaviour.
Definition: TSystem.cxx:588
virtual void IgnoreInterrupt(Bool_t ignore=kTRUE)
If ignore is true ignore the interrupt signal, else restore previous behaviour.
Definition: TSystem.cxx:606
Basic time type with millisecond precision.
Definition: TTime.h:29
static bool R__MatchFilename(const char *left, const char *right)
Figure out if left and right points to the same object in the file system.
Definition: TSystem.cxx:1777
Long64_t fSize
Definition: TSystem.h:141
virtual TInetAddress GetPeerName(int sock)
Get Internet Protocol (IP) address of remote host and port #.
Definition: TSystem.cxx:2241
static const TString & GetIncludeDir()
Get the include directory in the installation. Static utility function.
Definition: TROOT.cxx:2580
virtual int SendRaw(int sock, const void *buffer, int length, int flag)
Send exactly length bytes from buffer.
Definition: TSystem.cxx:2350
virtual TFileHandler * RemoveFileHandler(TFileHandler *fh)
Remove a file handler from the list of file handlers.
Definition: TSystem.cxx:568
Bool_t R_ISREG(Int_t mode)
Definition: TSystem.h:129
virtual char * GetServiceByPort(int port)
Get name of internet service.
Definition: TSystem.cxx:2268
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
Definition: TSystem.cxx:900
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
virtual const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1500
virtual const char * UnixPathName(const char *unixpathname)
Convert from a Unix pathname to a local pathname.
Definition: TSystem.cxx:1036
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition: TString.h:625
static Int_t GetErrno()
Static function returning system error number.
Definition: TSystem.cxx:264
Int_t fMode
Definition: TSystem.h:138
Bool_t IsInterruptingSyscalls() const
Definition: TTimer.h:88
virtual int Rename(const char *from, const char *to)
Rename a file.
Definition: TSystem.cxx:1318
virtual const char * GetLinkdefSuffix() const
Return the linkdef suffix chosen by the user for ACLiC.
Definition: TSystem.cxx:3780
const char * GetHost() const
Definition: TUrl.h:76
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition: TSystem.cxx:847
TTime GetAbsTime() const
Definition: TTimer.h:84
#define SafeDelete(p)
Definition: RConfig.h:449
virtual int Unlink(const char *name)
Unlink, i.e. remove, a file.
Definition: TSystem.cxx:1345
virtual std::string GetHomeDirectory(const char *userName=0) const
Return the user&#39;s home directory.
Definition: TSystem.cxx:889
Double_t x[n]
Definition: legend1.C:17
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2334
virtual int 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...
Definition: TSystem.cxx:2399
virtual FILE * TempFileName(TString &base, const char *dir=0)
Create a secure temporary file by appending a unique 6 letter string to base.
Definition: TSystem.cxx:1461
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition: TSystem.cxx:441
static const std::string separator("@@@")
TText * tt
Definition: textangle.C:16
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
Bool_t fTimeout
Definition: TTimer.h:62
TObject * Next()
Return next object in collection.
virtual const char * GetDynamicPath()
Return the dynamic path (used to find shared libraries).
Definition: TSystem.cxx:1756
void Clear()
Clear string without changing its capacity.
Definition: TString.cxx:1139
virtual int CompileMacro(const char *filename, Option_t *opt="", const char *library_name="", const char *build_dir="", UInt_t dirmode=0)
This method compiles and loads a shared library containing the code from the file "filename"...
Definition: TSystem.cxx:2767
virtual const char * Getenv(const char *env)
Get environment variable.
Definition: TSystem.cxx:1626
virtual void ListLibraries(const char *regexp="")
List all loaded shared libraries.
Definition: TSystem.cxx:1998
virtual const char * GetMakeExe() const
Return the command line use to make an executable.
Definition: TSystem.cxx:3752
virtual void SetDisplay()
Set DISPLAY environment variable based on utmp entry. Only for UNIX.
Definition: TSystem.cxx:235
TString & Append(const char *cs)
Definition: TString.h:492
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition: TSystem.cxx:1054
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2220
virtual EAclicMode GetAclicMode() const
AclicMode indicates whether the library should be built in debug mode or optimized.
Definition: TSystem.cxx:3734
virtual void ExitLoop()
Exit from event loop.
Definition: TSystem.cxx:396
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
Definition: TSystem.cxx:1562
virtual int RecvRaw(int sock, void *buffer, int length, int flag)
Receive exactly length bytes into buffer.
Definition: TSystem.cxx:2340
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:466
virtual ~TSystem()
Delete the OS interface.
Definition: TSystem.cxx:142
virtual void Unload(const char *module)
Unload a shared library.
Definition: TSystem.cxx:1977
virtual const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
Definition: TSystem.cxx:1446
static Int_t gLibraryVersionMax
Definition: TSystem.cxx:62
virtual Bool_t ConsistentWith(const char *path, void *dirptr=0)
Check consistency of this helper with the one required by &#39;path&#39; or &#39;dirptr&#39;.
Definition: TSystem.cxx:798
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
Definition: TSystem.cxx:2232
void Error(const char *location, const char *msgfmt,...)
ELogLevel
Definition: TSystem.h:66
virtual void Closelog()
Close connection to system log daemon.
Definition: TSystem.cxx:1655
virtual const char * GetBuildCompiler() const
Return the build compiler.
Definition: TSystem.cxx:3678
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition: TObject.cxx:743
A doubly linked list.
Definition: TList.h:47
TString & GetLastErrorString()
Return the thread local storage for the custom last error message.
Definition: TSystem.cxx:2035
const char * GetUser() const
Definition: TUrl.h:74
static Int_t * gLibraryVersion
Definition: TSystem.cxx:60
virtual EStatus Handle(std::exception &exc)=0
void Remove()
Definition: TTimer.h:91
virtual void AddDynamicPath(const char *pathname)
Add a new directory to the dynamic path.
Definition: TSystem.cxx:1748
ESignals
TString fUser
Definition: TSystem.h:152
virtual const char * GetBuildArch() const
Return the build architecture.
Definition: TSystem.cxx:3670
virtual TTime Now()
Get current time in milliseconds since 0:00 Jan 1 1995.
Definition: TSystem.cxx:467
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition: TObject.cxx:379
virtual void Setenv(const char *name, const char *value)
Set environment variable.
Definition: TSystem.cxx:1610
virtual TStdExceptionHandler * RemoveStdExceptionHandler(TStdExceptionHandler *eh)
Remove an exception handler from list of exception handlers.
Definition: TSystem.cxx:625
void ResetErrno()
reset errno
static void R__WriteDependencyFile(const TString &build_loc, const TString &depfilename, const TString &filename, const TString &library, const TString &libname, const TString &extension, const char *version_var_prefix, const TString &includes, const TString &defines, const TString &incPath)
Definition: TSystem.cxx:2511
ROOT::R::TRInterface & r
Definition: Object.C:4
virtual Bool_t Init()
Initialize the OS interface.
Definition: TSystem.cxx:186
SVector< double, 2 > v
Definition: Dict.h:5
virtual const char * GetLibraries(const char *regexp="", const char *option="", Bool_t isRegexp=kTRUE)
Return a space separated list of loaded shared libraries.
Definition: TSystem.cxx:2071
const char * gProgName
Definition: TSystem.cxx:54
Long_t ExecPlugin(int nargs, const T &... params)
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:480
virtual int AcceptConnection(int sock)
Accept a connection.
Definition: TSystem.cxx:2322
Bool_t Gets(FILE *fp, Bool_t chop=kTRUE)
Read one line from the stream, including the , or until EOF.
Definition: Stringio.cxx:198
void AssignAndDelete(TString &target, char *tobedeleted)
Definition: TSystem.cxx:2438
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:558
virtual void SetDynamicPath(const char *pathname)
Set the dynamic path to a new value.
Definition: TSystem.cxx:1767
virtual int AnnounceTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize=-1)
Announce TCP/IP service.
Definition: TSystem.cxx:2286
virtual const char * GetBuildDir() const
Return the path of the build directory.
Definition: TSystem.cxx:3702
virtual Long_t NextTimeOut(Bool_t mode)
Time when next timer of mode (synchronous=kTRUE or asynchronous=kFALSE) will time-out (in ms)...
Definition: TSystem.cxx:498
Bool_t IsSync() const
Definition: TTimer.h:86
static Int_t ConvertVersionCode2Int(Int_t code)
Convert version code to an integer, i.e. 331527 -> 51507.
Definition: TROOT.cxx:2474
unsigned int UInt_t
Definition: RtypesCore.h:42
Int_t GetEntriesFast() const
Definition: TObjArray.h:66
bool verbose
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
char * Form(const char *fmt,...)
Ssiz_t Length() const
Definition: TString.h:390
virtual int Umask(Int_t mask)
Set the process file creation mode mask.
Definition: TSystem.cxx:1479
virtual void SetBuildDir(const char *build_dir, Bool_t isflat=kFALSE)
Set the location where ACLiC will create libraries and use as a scratch area.
Definition: TSystem.cxx:3818
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition: TString.cxx:1069
virtual Int_t GetAclicProperties() const
Return the ACLiC properties field.
Definition: TSystem.cxx:3662
virtual int SendBuf(int sock, const void *buffer, int length)
Send a buffer headed by a length indicator.
Definition: TSystem.cxx:2368
const char * gProgPath
Definition: TSystem.cxx:55
TLine * l
Definition: textangle.C:4
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:57
virtual void ListSymbols(const char *module, const char *re="")
List symbols in a shared library.
Definition: TSystem.cxx:1989
const std::string sname
Definition: testIO.cxx:45
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition: TSystem.cxx:657
virtual void StopIdleing()
Called when system stops idleing.
virtual int Utime(const char *file, Long_t modtime, Long_t actime)
Set the a files modification and access times.
Definition: TSystem.cxx:1489
char * Strip(const char *str, char c=' ')
Strip leading and trailing c (blanks by default) from a string.
Definition: TString.cxx:2477
virtual void Abort(int code=0)
Abort the application.
Definition: TSystem.cxx:728
virtual void InnerLoop()
Inner event loop.
Definition: TSystem.cxx:404
virtual const char * GetMakeSharedLib() const
Return the command line use to make a shared library.
Definition: TSystem.cxx:3743
virtual void SetSoExt(const char *soExt)
Set shared library extension, should be either .so, .sl, .a, .dll, etc.
Definition: TSystem.cxx:4004
virtual void Unsetenv(const char *name)
Unset environment variable.
Definition: TSystem.cxx:1618
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition: TSystem.cxx:839
virtual int ClosePipe(FILE *pipe)
Close the pipe.
Definition: TSystem.cxx:675
virtual void Run()
System event loop.
Definition: TSystem.cxx:347
#define Printf
Definition: TGeoToOCC.h:18
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2513
#define R__LOCKGUARD2(mutex)
virtual int OpenConnection(const char *server, int port, int tcpwindowsize=-1, const char *protocol="tcp")
Open a connection to another host.
Definition: TSystem.cxx:2277
virtual int SetSockOpt(int sock, int kind, int val)
Set socket option.
Definition: TSystem.cxx:2377
const char * extension
Definition: civetweb.c:2467
virtual Int_t Select(TList *active, Long_t timeout)
Select on active file descriptors (called by TMonitor).
Definition: TSystem.cxx:449
virtual const char * FindDynamicLibrary(TString &lib, Bool_t quiet=kFALSE)
Find a dynamic library using the system search paths.
Definition: TSystem.cxx:1959
virtual Int_t RedirectOutput(const char *name, const char *mode="a", RedirectHandle_t *h=0)
Redirect standard output (stdout, stderr) to the specified file.
Definition: TSystem.cxx:1676
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
long Long_t
Definition: RtypesCore.h:50
int Ssiz_t
Definition: RtypesCore.h:63
virtual int Chmod(const char *file, UInt_t mode)
Set the file permission bits. Returns -1 in case or error, 0 otherwise.
Definition: TSystem.cxx:1470
virtual TSignalHandler * RemoveSignalHandler(TSignalHandler *sh)
Remove a signal handler from list of signal handlers.
Definition: TSystem.cxx:546
virtual void StartIdleing()
Called when system starts idleing.
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition: TString.cxx:2240
virtual Int_t GetEffectiveUid()
Returns the effective user id.
Definition: TSystem.cxx:1533
virtual const char * GetIncludePath()
Get the list of include path.
Definition: TSystem.cxx:3760
#define ClassImp(name)
Definition: Rtypes.h:279
double f(double x)
virtual Func_t DynFindSymbol(const char *module, const char *entry)
Find specific entry point in specified library.
Definition: TSystem.cxx:1969
virtual const char * HostName()
Return the system&#39;s host name.
Definition: TSystem.cxx:307
virtual int Symlink(const char *from, const char *to)
Create a symbolic link from file1 to file2.
Definition: TSystem.cxx:1336
Ssiz_t Index(const TString &str, Ssiz_t *len, Ssiz_t start=0) const
Find the first occurrence of the regexp in string and return the position, or -1 if there is no match...
Definition: TRegexp.cxx:208
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition: TString.cxx:864
char * DynamicPathName(const char *lib, Bool_t quiet=kFALSE)
Find a dynamic library called lib using the system search paths.
Definition: TSystem.cxx:1945
ELogFacility
Definition: TSystem.h:77
virtual void Remove()
Remove signal handler from system signal handler list.
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
virtual const char * ExpandFileName(const char *fname)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1071
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
Definition: TROOT.cxx:2601
virtual void SetProgname(const char *name)
Set the application name (from command line, argv[0]) and copy it in gProgName.
Definition: TSystem.cxx:227
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
virtual Int_t GetGid(const char *group=0)
Returns the group&#39;s id. If group = 0, returns current user&#39;s group.
Definition: TSystem.cxx:1542
void Beep(Int_t freq=-1, Int_t duration=-1, Bool_t setDefault=kFALSE)
Beep for duration milliseconds with a tone of frequency freq.
Definition: TSystem.cxx:328
virtual void DispatchOneEvent(Bool_t pendingOnly=kFALSE)
Dispatch a single event.
Definition: TSystem.cxx:433
virtual void CleanCompiledMacros()
Remove the shared libs produced by the CompileMacro() function.
Definition: TSystem.cxx:4111
virtual TInetAddress GetSockName(int sock)
Get Internet Protocol (IP) address of host and port #.
Definition: TSystem.cxx:2250
virtual Int_t GetUid(const char *user=0)
Returns the user&#39;s id. If user = 0, returns current user&#39;s id.
Definition: TSystem.cxx:1523
EAccessMode
Definition: TSystem.h:54
virtual void Remove()
Remove file event handler from system file handler list.
virtual void AddLinkedLibs(const char *linkedLib)
Add linkedLib to already set linked libs.
Definition: TSystem.cxx:3938
Bool_t IsNull() const
Definition: TString.h:387
virtual void SetAclicMode(EAclicMode mode)
AclicMode indicates whether the library should be built in debug mode or optimized.
Definition: TSystem.cxx:3850
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
virtual void SetObjExt(const char *objExt)
Set object files extension, should be either .o, .obj, etc.
Definition: TSystem.cxx:4012
virtual Bool_t IsFileInIncludePath(const char *name, char **fullpath=0)
Return true if &#39;name&#39; is a file that can be found in the ROOT include path or the current directory...
Definition: TSystem.cxx:960
const Int_t kMaxInt
Definition: Rtypes.h:103
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:459
virtual int RecvBuf(int sock, void *buffer, int length)
Receive a buffer headed by a length indicator.
Definition: TSystem.cxx:2359
virtual void Openlog(const char *name, Int_t options, ELogFacility facility)
Open connection to system log daemon.
Definition: TSystem.cxx:1638
Bool_t R_ISDIR(Int_t mode)
Definition: TSystem.h:126
virtual int GetServiceByName(const char *service)
Get port # of internet service.
Definition: TSystem.cxx:2259
virtual int AnnounceUnixService(int port, int backlog)
Announce unix domain service.
Definition: TSystem.cxx:2304
const Ssiz_t kNPOS
Definition: Rtypes.h:115
static const TString & GetLibDir()
Get the library directory in the installation. Static utility function.
Definition: TROOT.cxx:2559
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition: TSystem.cxx:475
virtual void ShowOutput(RedirectHandle_t *h)
Display the content associated with the redirection described by the opaque handle &#39;h&#39;...
Definition: TSystem.cxx:1686
virtual void SetLinkedLibs(const char *linkedLibs)
LinkedLibs should contain the library directory and list of libraries needed to recreate the current ...
Definition: TSystem.cxx:3973
virtual Int_t GetEffectiveGid()
Returns the effective group id.
Definition: TSystem.cxx:1552
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition: TSystem.cxx:720
#define ROOT_RELEASE
Definition: RVersion.h:17
virtual std::string GetWorkingDirectory() const
Return working directory.
Definition: TSystem.cxx:873
virtual int GetProcInfo(ProcInfo_t *info) const
Returns cpu and memory used by this process into the ProcInfo_t structure.
Definition: TSystem.cxx:2430
Long_t fIno
Definition: TSystem.h:137
virtual int CopyFile(const char *from, const char *to, Bool_t overwrite=kFALSE)
Copy a file.
Definition: TSystem.cxx:1309
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Definition: TSystem.cxx:830
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
Iterator of ordered collection.
virtual void AddIncludePath(const char *includePath)
Add includePath to the already set include path.
Definition: TSystem.cxx:3927
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...
Definition: TSystem.cxx:748
virtual void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
Definition: TSystem.cxx:558
static void ResetErrno()
Static function resetting system error number.
Definition: TSystem.cxx:280
static const TString & GetBinDir()
Get the binary directory in the installation. Static utility function.
Definition: TROOT.cxx:2538
double result[121]
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1242
void SetErrorStr(const char *errstr)
Set the system error string.
Definition: TSystem.cxx:245
Long_t fDev
Definition: TSystem.h:136
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
virtual int GetSockOpt(int sock, int kind, int *val)
Get socket option.
Definition: TSystem.cxx:2386
const char * gRootDir
Definition: TSystem.cxx:53
Abstract base class defining a generic interface to the underlying Operating System.
Definition: TSystem.h:258
const Bool_t kTRUE
Definition: Rtypes.h:91
Ordered collection.
virtual void SetLinkdefSuffix(const char *suffix)
The &#39;suffix&#39; will be appended to the name of a script loaded by ACLiC and used to locate any eventual...
Definition: TSystem.cxx:3995
virtual Int_t GetFPEMask()
Return the bitmap of conditions that trigger a floating point exception.
Definition: TSystem.cxx:636
#define RETRY
Definition: TException.h:59
module
Definition: ROOT.py:93
static Int_t gLibraryVersionIdx
Definition: TSystem.cxx:61
void AbstractMethod(const char *method) const
Use this method to implement an "abstract" method that you don&#39;t want to leave purely abstract...
Definition: TObject.cxx:960
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
Definition: TSystem.cxx:1044
Bool_t IsAsync() const
Definition: TTimer.h:87
const Int_t n
Definition: legend1.C:16
TString fFile
Definition: TSystem.h:215
virtual const char * GetObjExt() const
Get the object file extension.
Definition: TSystem.cxx:3800
virtual const char * GetError()
Return system error string.
Definition: TSystem.cxx:254
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904
static Int_t * ReAllocInt(Int_t *vp, size_t size, size_t oldsize)
Reallocate (i.e.
Definition: TStorage.cxx:289
virtual void SetIncludePath(const char *includePath)
IncludePath should contain the list of compiler flags to indicate where to find user defined header f...
Definition: TSystem.cxx:3962
if(line.BeginsWith("/*"))
Definition: HLFactory.cxx:443
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
TString & Chop()
Definition: TString.h:622
const char * Data() const
Definition: TString.h:349
virtual void IgnoreSignal(ESignals sig, Bool_t ignore=kTRUE)
If ignore is true ignore the specified signal, else restore previous behaviour.
Definition: TSystem.cxx:597