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