ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
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();
147  }
148 
149  if (fSignalHandler) {
152  }
153 
154  if (fFileHandler) {
155  fFileHandler->Delete();
157  }
158 
159  if (fStdExceptionHandler) {
162  }
163 
164  if (fTimers) {
165  fTimers->Delete();
167  }
168 
169  if (fCompiled) {
170  fCompiled->Delete();
172  }
173 
174  if (fHelpers) {
175  fHelpers->Delete();
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 
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;
211  fMakeSharedLib = MAKESHAREDLIB;
212  fMakeExe = MAKEEXE;
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)
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) {
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++;
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))
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 
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())
525  else
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))
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 {
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
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, '/')) {
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 
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 #ifdef ROOTLIBDIR
1856  TString rootlibdir = ROOTLIBDIR;
1857 #else
1858  TString rootlibdir = "lib";
1859  PrependPathName(gRootDir, rootlibdir);
1860 #endif
1861  system = R__MatchFilename(rootlibdir,dirname);
1862 
1863  if (!system) {
1864 #ifdef ROOTBINDIR
1865  TString rootbindir = ROOTBINDIR;
1866 #else
1867  TString rootbindir = "bin";
1868  PrependPathName(gRootDir, rootbindir);
1869 #endif
1870  system = R__MatchFilename(rootbindir,dirname);
1871  }
1872  }
1873 
1874  gLibraryVersionIdx++;
1875  if (gLibraryVersionIdx == gLibraryVersionMax) {
1876  gLibraryVersionMax *= 2;
1877  gLibraryVersion = TStorage::ReAllocInt(gLibraryVersion, gLibraryVersionMax, gLibraryVersionIdx);
1878  }
1879  ret = gInterpreter->Load(path, system);
1880  if (ret < 0) ret = -1;
1881  if (gDebug > 0)
1882  Info("Load", "loaded library %s, status %d", path, ret);
1883  if (ret == 0 && gLibraryVersion[gLibraryVersionIdx]) {
1884  int v = TROOT::ConvertVersionCode2Int(gLibraryVersion[gLibraryVersionIdx]);
1885  Error("Load", "version mismatch, %s = %d, ROOT = %d",
1886  path, v, gROOT->GetVersionInt());
1887  ret = -2;
1888  gLibraryVersion[gLibraryVersionIdx] = 0;
1889  }
1890  gLibraryVersionIdx--;
1891  delete [] path;
1892  }
1893 
1894  if (!entry || !entry[0] || ret < 0) return ret;
1895 
1896  Func_t f = DynFindSymbol(module, entry);
1897  if (f) return 0;
1898  return -1;
1899 }
1900 
1901 ////////////////////////////////////////////////////////////////////////////////
1902 /// Find a dynamic library called lib using the system search paths.
1903 /// Appends known extensions if needed. Returned string must be deleted
1904 /// by the user!
1905 
1906 char *TSystem::DynamicPathName(const char *lib, Bool_t quiet /*=kFALSE*/)
1907 {
1908  TString sLib(lib);
1909  if (FindDynamicLibrary(sLib, quiet))
1910  return StrDup(sLib);
1911  return 0;
1912 }
1913 
1914 ////////////////////////////////////////////////////////////////////////////////
1915 /// Find a dynamic library using the system search paths. lib will be updated
1916 /// to contain the absolute filename if found. Returns lib if found, or NULL
1917 /// if a library called lib was not found.
1918 /// This function does not open the library.
1919 
1921 {
1922  AbstractMethod("FindDynamicLibrary");
1923  return 0;
1924 }
1925 
1926 ////////////////////////////////////////////////////////////////////////////////
1927 /// Find specific entry point in specified library. Specify "*" for lib
1928 /// to search in all libraries.
1929 
1930 Func_t TSystem::DynFindSymbol(const char * /*lib*/, const char *entry)
1931 {
1932  return (Func_t) gInterpreter->FindSym(entry);
1933 }
1934 
1935 ////////////////////////////////////////////////////////////////////////////////
1936 /// Unload a shared library.
1937 
1938 void TSystem::Unload(const char *module)
1939 {
1940  char *path;
1941  if ((path = DynamicPathName(module))) {
1942  gInterpreter->UnloadFile(path);
1943  delete [] path;
1944  }
1945 }
1946 
1947 ////////////////////////////////////////////////////////////////////////////////
1948 /// List symbols in a shared library.
1949 
1950 void TSystem::ListSymbols(const char *, const char *)
1951 {
1952  AbstractMethod("ListSymbols");
1953 }
1954 
1955 ////////////////////////////////////////////////////////////////////////////////
1956 /// List all loaded shared libraries. Regexp is a wildcard expression,
1957 /// see TRegexp::MakeWildcard.
1958 
1960 {
1961  TString libs = GetLibraries(regexp);
1962  TRegexp separator("[^ \\t\\s]+");
1963  TString s;
1964  Ssiz_t start = 0, index = 0, end = 0;
1965  int i = 0;
1966 
1967  Printf(" ");
1968  Printf("Loaded shared libraries");
1969  Printf("=======================");
1970 
1971  while ((start < libs.Length()) && (index != kNPOS)) {
1972  index = libs.Index(separator, &end, start);
1973  if (index >= 0) {
1974  s = libs(index, end);
1975  if (s.BeginsWith("-")) {
1976  if (s.BeginsWith("-l")) {
1977  Printf("%s", s.Data());
1978  i++;
1979  }
1980  } else {
1981  Printf("%s", s.Data());
1982  i++;
1983  }
1984  }
1985  start += end+1;
1986  }
1987 
1988  Printf("-----------------------");
1989  Printf("%d libraries loaded", i);
1990  Printf("=======================");
1991 }
1992 
1993 ////////////////////////////////////////////////////////////////////////////////
1994 /// Return the thread local storage for the custom last error message
1995 
1997 {
1998  TTHREAD_TLS_DECL( TString, gLastErrorString);
1999  return gLastErrorString;
2000 }
2001 
2002 ////////////////////////////////////////////////////////////////////////////////
2003 /// Return the thread local storage for the custom last error message
2004 
2006 {
2007  return const_cast<TSystem*>(this)->GetLastErrorString();
2008 }
2009 
2010 ////////////////////////////////////////////////////////////////////////////////
2011 /// Get list of shared libraries loaded at the start of the executable.
2012 /// Returns 0 in case list cannot be obtained or in case of error.
2013 
2015 {
2016  return 0;
2017 }
2018 
2019 ////////////////////////////////////////////////////////////////////////////////
2020 /// Return a space separated list of loaded shared libraries.
2021 /// Regexp is a wildcard expression, see TRegexp::MakeWildcard.
2022 /// This list is of a format suitable for a linker, i.e it may contain
2023 /// -Lpathname and/or -lNameOfLib.
2024 /// Option can be any of:
2025 /// - S: shared libraries loaded at the start of the executable, because
2026 /// they were specified on the link line.
2027 /// - D: shared libraries dynamically loaded after the start of the program.
2028 /// For MacOS only:
2029 /// - L: list the .dylib rather than the .so (this is intended for linking)
2030 /// This options is not the default
2031 
2032 const char *TSystem::GetLibraries(const char *regexp, const char *options,
2033  Bool_t isRegexp)
2034 {
2035  fListLibs.Clear();
2036 
2037  TString libs;
2038  TString opt(options);
2039  Bool_t so2dylib = (opt.First('L') != kNPOS);
2040  if (so2dylib)
2041  opt.ReplaceAll("L", "");
2042 
2043  if (opt.IsNull() || opt.First('D') != kNPOS)
2044  libs += gInterpreter->GetSharedLibs();
2045 
2046  // Cint currently register all libraries that
2047  // are loaded and have a dictionary in them, this
2048  // includes all the libraries that are included
2049  // in the list of (hard) linked libraries.
2050 
2051  TString slinked;
2052  const char *linked;
2053  if ((linked = GetLinkedLibraries())) {
2054  if (fLinkedLibs != LINKEDLIBS) {
2055  // This is not the default value, we need to keep the custom part.
2056  TString custom = fLinkedLibs;
2057  custom.ReplaceAll(LINKEDLIBS,linked);
2058  if (custom == fLinkedLibs) {
2059  // no replacement done, let's append linked
2060  slinked.Append(linked);
2061  slinked.Append(" ");
2062  }
2063  slinked.Append(custom);
2064  } else {
2065  slinked.Append(linked);
2066  }
2067  } else {
2068  slinked.Append(fLinkedLibs);
2069  }
2070 
2071  if (opt.IsNull() || opt.First('S') != kNPOS) {
2072  // We are done, the statically linked libraries are already included.
2073  if (libs.Length() == 0) {
2074  libs = slinked;
2075  } else {
2076  // We need to add the missing linked library
2077 
2078  static TString lastLinked;
2079  static TString lastAddMissing;
2080  if ( lastLinked != slinked ) {
2081  // Recalculate only if there was a change.
2082  static TRegexp separator("[^ \\t\\s]+");
2083  lastLinked = slinked;
2084  lastAddMissing.Clear();
2085 
2086  Ssiz_t start, index, end;
2087  start = index = end = 0;
2088 
2089  while ((start < slinked.Length()) && (index != kNPOS)) {
2090  index = slinked.Index(separator,&end,start);
2091  if (index >= 0) {
2092  TString sub = slinked(index,end);
2093  if (sub[0]=='-' && sub[1]=='L') {
2094  lastAddMissing.Prepend(" ");
2095  lastAddMissing.Prepend(sub);
2096  } else {
2097  if (libs.Index(sub) == kNPOS) {
2098  lastAddMissing.Prepend(" ");
2099  lastAddMissing.Prepend(sub);
2100  }
2101  }
2102  }
2103  start += end+1;
2104  }
2105  }
2106  libs.Prepend(lastAddMissing);
2107  }
2108  } else if (libs.Length() != 0) {
2109  // Let remove the statically linked library
2110  // from the list.
2111  static TRegexp separator("[^ \\t\\s]+");
2112  Ssiz_t start, index, end;
2113  start = index = end = 0;
2114 
2115  while ((start < slinked.Length()) && (index != kNPOS)) {
2116  index = slinked.Index(separator,&end,start);
2117  if (index >= 0) {
2118  TString sub = slinked(index,end);
2119  if (sub[0]!='-' && sub[1]!='L') {
2120  libs.ReplaceAll(sub,"");
2121  }
2122  }
2123  start += end+1;
2124  }
2125  libs = libs.Strip(TString::kBoth);
2126  }
2127 
2128  // Select according to regexp
2129  if (regexp && *regexp) {
2130  static TRegexp separator("[^ \\t\\s]+");
2131  TRegexp user_re(regexp, kTRUE);
2132  TString s;
2133  Ssiz_t start, index, end;
2134  start = index = end = 0;
2135 
2136  while ((start < libs.Length()) && (index != kNPOS)) {
2137  index = libs.Index(separator,&end,start);
2138  if (index >= 0) {
2139  s = libs(index,end);
2140  if ((isRegexp && s.Index(user_re) != kNPOS) ||
2141  (!isRegexp && s.Index(regexp) != kNPOS)) {
2142  if (!fListLibs.IsNull())
2143  fListLibs.Append(" ");
2144  fListLibs.Append(s);
2145  }
2146  }
2147  start += end+1;
2148  }
2149  } else
2150  fListLibs = libs;
2151 
2152 #if defined(R__MACOSX) && !defined(MAC_OS_X_VERSION_10_5)
2153  if (so2dylib) {
2154  TString libs2 = fListLibs;
2155  TString maclibs;
2156 
2157  static TRegexp separator("[^ \\t\\s]+");
2158  static TRegexp user_so("\\.so$");
2159 
2160  Ssiz_t start, index, end;
2161  start = index = end = 0;
2162 
2163  while ((start < libs2.Length()) && (index != kNPOS)) {
2164  index = libs2.Index(separator, &end, start);
2165  if (index >= 0) {
2166  // Change .so into .dylib and remove the
2167  // path info if it is not accessible
2168  TString s = libs2(index, end);
2169  if (s.Index(user_so) != kNPOS) {
2170  s.ReplaceAll(".so",".dylib");
2171  if ( GetPathInfo( s, 0, (Long_t*)0, 0, 0 ) != 0 ) {
2172  s.Replace( 0, s.Last('/')+1, 0, 0);
2173  s.Replace( 0, s.Last('\\')+1, 0, 0);
2174  }
2175  }
2176  if (!maclibs.IsNull()) maclibs.Append(" ");
2177  maclibs.Append(s);
2178  }
2179  start += end+1;
2180  }
2181  fListLibs = maclibs;
2182  }
2183 #endif
2184 
2185  return fListLibs;
2186 }
2187 
2188 //---- RPC ---------------------------------------------------------------------
2189 
2190 ////////////////////////////////////////////////////////////////////////////////
2191 /// Get Internet Protocol (IP) address of host.
2192 
2194 {
2195  AbstractMethod("GetHostByName");
2196  return TInetAddress();
2197 }
2198 
2199 ////////////////////////////////////////////////////////////////////////////////
2200 /// Get Internet Protocol (IP) address of remote host and port #.
2201 
2203 {
2204  AbstractMethod("GetPeerName");
2205  return TInetAddress();
2206 }
2207 
2208 ////////////////////////////////////////////////////////////////////////////////
2209 /// Get Internet Protocol (IP) address of host and port #.
2210 
2212 {
2213  AbstractMethod("GetSockName");
2214  return TInetAddress();
2215 }
2216 
2217 ////////////////////////////////////////////////////////////////////////////////
2218 /// Get port # of internet service.
2219 
2220 int TSystem::GetServiceByName(const char *)
2221 {
2222  AbstractMethod("GetServiceByName");
2223  return -1;
2224 }
2225 
2226 ////////////////////////////////////////////////////////////////////////////////
2227 /// Get name of internet service.
2228 
2230 {
2231  AbstractMethod("GetServiceByPort");
2232  return 0;
2233 }
2234 
2235 ////////////////////////////////////////////////////////////////////////////////
2236 /// Open a connection to another host.
2237 
2238 int TSystem::OpenConnection(const char*, int, int, const char*)
2239 {
2240  AbstractMethod("OpenConnection");
2241  return -1;
2242 }
2243 
2244 ////////////////////////////////////////////////////////////////////////////////
2245 /// Announce TCP/IP service.
2246 
2248 {
2249  AbstractMethod("AnnounceTcpService");
2250  return -1;
2251 }
2252 
2253 ////////////////////////////////////////////////////////////////////////////////
2254 /// Announce UDP service.
2255 
2257 {
2258  AbstractMethod("AnnounceUdpService");
2259  return -1;
2260 }
2261 
2262 ////////////////////////////////////////////////////////////////////////////////
2263 /// Announce unix domain service.
2264 
2266 {
2267  AbstractMethod("AnnounceUnixService");
2268  return -1;
2269 }
2270 
2271 ////////////////////////////////////////////////////////////////////////////////
2272 /// Announce unix domain service.
2273 
2274 int TSystem::AnnounceUnixService(const char *, int)
2275 {
2276  AbstractMethod("AnnounceUnixService");
2277  return -1;
2278 }
2279 
2280 ////////////////////////////////////////////////////////////////////////////////
2281 /// Accept a connection.
2282 
2284 {
2285  AbstractMethod("AcceptConnection");
2286  return -1;
2287 }
2288 
2289 ////////////////////////////////////////////////////////////////////////////////
2290 /// Close socket connection.
2291 
2293 {
2294  AbstractMethod("CloseConnection");
2295 }
2296 
2297 ////////////////////////////////////////////////////////////////////////////////
2298 /// Receive exactly length bytes into buffer. Use opt to receive out-of-band
2299 /// data or to have a peek at what is in the buffer (see TSocket).
2300 
2301 int TSystem::RecvRaw(int, void *, int, int)
2302 {
2303  AbstractMethod("RecvRaw");
2304  return -1;
2305 }
2306 
2307 ////////////////////////////////////////////////////////////////////////////////
2308 /// Send exactly length bytes from buffer. Use opt to send out-of-band
2309 /// data (see TSocket).
2310 
2311 int TSystem::SendRaw(int, const void *, int, int)
2312 {
2313  AbstractMethod("SendRaw");
2314  return -1;
2315 }
2316 
2317 ////////////////////////////////////////////////////////////////////////////////
2318 /// Receive a buffer headed by a length indicator.
2319 
2320 int TSystem::RecvBuf(int, void *, int)
2321 {
2322  AbstractMethod("RecvBuf");
2323  return -1;
2324 }
2325 
2326 ////////////////////////////////////////////////////////////////////////////////
2327 /// Send a buffer headed by a length indicator.
2328 
2329 int TSystem::SendBuf(int, const void *, int)
2330 {
2331  AbstractMethod("SendBuf");
2332  return -1;
2333 }
2334 
2335 ////////////////////////////////////////////////////////////////////////////////
2336 /// Set socket option.
2337 
2338 int TSystem::SetSockOpt(int, int, int)
2339 {
2340  AbstractMethod("SetSockOpt");
2341  return -1;
2342 }
2343 
2344 ////////////////////////////////////////////////////////////////////////////////
2345 /// Get socket option.
2346 
2347 int TSystem::GetSockOpt(int, int, int*)
2348 {
2349  AbstractMethod("GetSockOpt");
2350  return -1;
2351 }
2352 
2353 //---- System, CPU and Memory info ---------------------------------------------
2354 
2355 ////////////////////////////////////////////////////////////////////////////////
2356 /// Returns static system info, like OS type, CPU type, number of CPUs
2357 /// RAM size, etc into the SysInfo_t structure. Returns -1 in case of error,
2358 /// 0 otherwise.
2359 
2361 {
2362  AbstractMethod("GetSysInfo");
2363  return -1;
2364 }
2365 
2366 ////////////////////////////////////////////////////////////////////////////////
2367 /// Returns cpu load average and load info into the CpuInfo_t structure.
2368 /// Returns -1 in case of error, 0 otherwise. Use sampleTime to set the
2369 /// interval over which the CPU load will be measured, in ms (default 1000).
2370 
2372 {
2373  AbstractMethod("GetCpuInfo");
2374  return -1;
2375 }
2376 
2377 ////////////////////////////////////////////////////////////////////////////////
2378 /// Returns ram and swap memory usage info into the MemInfo_t structure.
2379 /// Returns -1 in case of error, 0 otherwise.
2380 
2382 {
2383  AbstractMethod("GetMemInfo");
2384  return -1;
2385 }
2386 
2387 ////////////////////////////////////////////////////////////////////////////////
2388 /// Returns cpu and memory used by this process into the ProcInfo_t structure.
2389 /// Returns -1 in case of error, 0 otherwise.
2390 
2392 {
2393  AbstractMethod("GetProcInfo");
2394  return -1;
2395 }
2396 
2397 //---- Script Compiler ---------------------------------------------------------
2398 
2399 void AssignAndDelete(TString& target, char *tobedeleted)
2400 {
2401  // Assign the char* value to the TString and then delete it.
2402 
2403  target = tobedeleted;
2404  delete [] tobedeleted;
2405 }
2406 
2407 #ifdef WIN32
2408 
2409 static TString R__Exec(const char *cmd)
2410 {
2411  // Execute a command and return the stdout in a string.
2412 
2413  FILE * f = gSystem->OpenPipe(cmd,"r");
2414  if (!f) {
2415  return "";
2416  }
2417  TString result;
2418 
2419  char x;
2420  while ((x = fgetc(f))!=EOF ) {
2421  if (x=='\n' || x=='\r') break;
2422  result += x;
2423  }
2424 
2425  fclose(f);
2426  return result;
2427 }
2428 
2429 static void R__FixLink(TString &cmd)
2430 {
2431  // Replace the call to 'link' by a full path name call based on where cl.exe is.
2432  // This prevents us from using inadvertently the link.exe provided by cygwin.
2433 
2434  // check if link is the microsoft one...
2435  TString res = R__Exec("link 2>&1");
2436  if (res.Length()) {
2437  if (res.Contains("Microsoft (R) Incremental Linker"))
2438  return;
2439  }
2440  // else check availability of cygpath...
2441  res = R__Exec("cygpath . 2>&1");
2442  if (res.Length()) {
2443  if (res != ".")
2444  return;
2445  }
2446 
2447  res = R__Exec("which cl.exe 2>&1|grep cl|sed 's,cl\\.exe$,link\\.exe,' 2>&1");
2448  if (res.Length()) {
2449  res = R__Exec(Form("cygpath -w '%s' 2>&1",res.Data()));
2450  if (res.Length()) {
2451  cmd.ReplaceAll(" link ",Form(" \"%s\" ",res.Data()));
2452  }
2453  }
2454 }
2455 #endif
2456 
2457 #ifndef WIN32
2458 static void R__AddPath(TString &target, const TString &path) {
2459  target += path;
2460 }
2461 #else
2462 static void R__AddPath(TString &target, const TString &path) {
2463  if (path.Length() > 2 && path[1]==':') {
2464  target += TString::Format("/cygdrive/%c",path[0]) + path(2,path.Length()-2);
2465  } else {
2466  target += path;
2467  }
2468 }
2469 #endif
2470 
2471 #ifndef WIN32
2472 static void R__WriteDependencyFile(const TString & build_loc, const TString &depfilename, const TString &filename, const TString &library, const TString &libname,
2473  const TString &extension, const char *version_var_prefix, const TString &includes, const TString &defines, const TString &incPath)
2474 #else
2475 static void R__WriteDependencyFile(const TString &build_loc, const TString &depfilename, const TString &filename, const TString &library, const TString &libname,
2476  const TString &extension, const char *version_var_prefix, const TString &includes, const TString &defines, const TString &incPath)
2477 #endif
2478 {
2479  // Generate the dependency via standard output, not searching the
2480  // standard include directories,
2481 
2482 #ifndef WIN32
2483  const char * stderrfile = "/dev/null";
2484 #else
2485  TString stderrfile;
2486  AssignAndDelete( stderrfile, gSystem->ConcatFileName(build_loc,"stderr.tmp") );
2487 #endif
2488  TString bakdepfilename = depfilename + ".bak";
2489 
2490 #ifdef WIN32
2491  TString touch = "echo # > "; touch += "\"" + depfilename + "\"";
2492 #else
2493  TString touch = "echo > "; touch += "\"" + depfilename + "\"";
2494 #endif
2495 #ifdef ROOTBINDIR
2496  TString builddep = ROOTBINDIR;
2497 #else
2498  TString builddep = TString(gRootDir) + "/bin";
2499 #endif
2500  builddep += "/rmkdepend \"-f";
2501  builddep += depfilename;
2502  builddep += "\" -o_" + extension + "." + gSystem->GetSoExt() + " ";
2503  if (build_loc.BeginsWith(gSystem->WorkingDirectory())) {
2504  Int_t len = strlen(gSystem->WorkingDirectory());
2505  if ( build_loc.Length() > (len+1) ) {
2506  builddep += " \"-p";
2507  if (build_loc[len] == '/' || build_loc[len+1] != '\\' ) {
2508  // Since the path is now ran through TSystem::ExpandPathName the single \ is also possible.
2509  R__AddPath(builddep, build_loc.Data() + len + 1 );
2510  } else {
2511  // Case of dir\\name
2512  R__AddPath(builddep, build_loc.Data() + len + 2 );
2513  }
2514  builddep += "/\" ";
2515  }
2516  } else {
2517  builddep += " \"-p";
2518  R__AddPath(builddep, build_loc);
2519  builddep += "/\" ";
2520  }
2521  builddep += " -Y -- ";
2522 #ifndef ROOTINCDIR
2523  TString rootsysInclude = gSystem->Getenv("ROOTSYS");
2524  rootsysInclude += "/include";
2525 #else
2526  TString rootsysInclude = ROOTINCDIR;
2527 #endif
2528  builddep += " \"-I"+rootsysInclude+"\" "; // cflags
2529  builddep += includes;
2530  builddep += defines;
2531  builddep += " -- \"";
2532  builddep += filename;
2533  builddep += "\" ";
2534  TString targetname;
2535  if (library.BeginsWith(gSystem->WorkingDirectory())) {
2536  Int_t len = strlen(gSystem->WorkingDirectory());
2537  if ( library.Length() > (len+1) ) {
2538  if (library[len] == '/' || library[len+1] != '\\' ) {
2539  targetname = library.Data() + len + 1;
2540  } else {
2541  targetname = library.Data() + len + 2;
2542  }
2543  } else {
2544  targetname = library;
2545  }
2546  } else {
2547  targetname = library;
2548  }
2549  builddep += " \"";
2550  builddep += "-t";
2551  R__AddPath(builddep, targetname);
2552  builddep += "\" > ";
2553  builddep += stderrfile;
2554  builddep += " 2>&1 ";
2555 
2556  TString adddictdep = "echo ";
2557  R__AddPath(adddictdep,targetname);
2558  adddictdep += ": ";
2559 #if defined(R__HAS_CLING_DICTVERSION)
2560  {
2561  char *clingdictversion = gSystem->Which(incPath,"clingdictversion.h");
2562  if (clingdictversion) {
2563  R__AddPath(adddictdep,clingdictversion);
2564  adddictdep += " ";
2565  delete [] clingdictversion;
2566  } else {
2567  R__AddPath(adddictdep,rootsysInclude+"/clingdictversion.h ");
2568  }
2569  }
2570 #endif
2571  {
2572  const char *dictHeaders[] = { "RVersion.h", "RConfig.h", "TClass.h",
2573  "TDictAttributeMap.h","TInterpreter.h","TROOT.h","TBuffer.h",
2574  "TMemberInspector.h","TError.h","RtypesImp.h","TIsAProxy.h",
2575  "TFileMergeInfo.h","TCollectionProxyInfo.h"};
2576 
2577  for (unsigned int h=0; h < sizeof(dictHeaders)/sizeof(dictHeaders[0]); ++h)
2578  {
2579  char *rootVersion = gSystem->Which(incPath,dictHeaders[h]);
2580  if (rootVersion) {
2581  R__AddPath(adddictdep,rootVersion);
2582  adddictdep += " ";
2583  delete [] rootVersion;
2584  } else {
2585  R__AddPath(adddictdep,rootsysInclude + "/" + dictHeaders[h]);
2586  }
2587  }
2588  }
2589  adddictdep += " >> \""+depfilename+"\"";
2590 
2591  TString addversiondep( "echo ");
2592  addversiondep += libname + version_var_prefix + " \"" + ROOT_RELEASE + "\" >> \""+depfilename+"\"";
2593 
2594  if (gDebug > 4) {
2595  ::Info("ACLiC", "%s", touch.Data());
2596  ::Info("ACLiC", "%s", builddep.Data());
2597  ::Info("ACLiC", "%s", adddictdep.Data());
2598  }
2599 
2600  Int_t depbuilt = !gSystem->Exec(touch);
2601  if (depbuilt) depbuilt = !gSystem->Exec(builddep);
2602  if (depbuilt) depbuilt = !gSystem->Exec(adddictdep);
2603  if (depbuilt) depbuilt = !gSystem->Exec(addversiondep);
2604 
2605  if (!depbuilt) {
2606  ::Warning("ACLiC","Failed to generate the dependency file for %s",
2607  library.Data());
2608  } else {
2609 #ifdef WIN32
2610  gSystem->Unlink(stderrfile);
2611 #endif
2612  gSystem->Unlink(bakdepfilename);
2613  }
2614 }
2615 
2616 ////////////////////////////////////////////////////////////////////////////////
2617 /// This method compiles and loads a shared library containing
2618 /// the code from the file "filename".
2619 ///
2620 /// The return value is true (1) in case of success and false (0)
2621 /// in case of error.
2622 ///
2623 /// The possible options are:
2624 /// - k : keep the shared library after the session end.
2625 /// - f : force recompilation.
2626 /// - g : compile with debug symbol
2627 /// - O : optimized the code
2628 /// - c : compile only, do not attempt to load the library.
2629 /// - s : silence all informational output
2630 /// - v : output all information output
2631 /// - d : debug ACLiC, keep all the output files.
2632 /// - - : if buildir is set, use a flat structure (see buildir below)
2633 ///
2634 /// If library_specified is specified, CompileMacro generates the file
2635 /// "library_specified".soext where soext is the shared library extension for
2636 /// the current platform.
2637 ///
2638 /// If build_dir is specified, it is used as an alternative 'root' for the
2639 /// generation of the shared library. The library is stored in a sub-directories
2640 /// of 'build_dir' including the full pathname of the script unless a flat
2641 /// directory structure is requested ('-' option). With the '-' option the libraries
2642 /// are created directly in the directory 'build_dir'; in particular this means that
2643 /// 2 scripts with the same name in different source directory will over-write each
2644 /// other's library.
2645 /// See also TSystem::SetBuildDir.
2646 ///
2647 /// If dirmode is not zero and we need to create the target directory, the
2648 /// file mode bit will be change to 'dirmode' using chmod.
2649 ///
2650 /// If library_specified is not specified, CompileMacro generate a default name
2651 /// for library by taking the name of the file "filename" but replacing the
2652 /// dot before the extension by an underscore and by adding the shared
2653 /// library extension for the current platform.
2654 /// For example on most platform, hsimple.cxx will generate hsimple_cxx.so
2655 ///
2656 /// It uses the directive fMakeSharedLibs to create a shared library.
2657 /// If loading the shared library fails, it tries to output a list of missing
2658 /// symbols by creating an executable (on some platforms like OSF, this does
2659 /// not HAVE to be an executable) containing the script. It uses the
2660 /// directive fMakeExe to do so.
2661 /// For both directives, before passing them to TSystem::Exec, it expands the
2662 /// variables $SourceFiles, $SharedLib, $LibName, $IncludePath, $LinkedLibs,
2663 /// $DepLibs, $ExeName and $ObjectFiles. See SetMakeSharedLib() for more
2664 /// information on those variables.
2665 ///
2666 /// This method is used to implement the following feature:
2667 ///
2668 /// Synopsis:
2669 ///
2670 /// The purpose of this addition is to allow the user to use an external
2671 /// compiler to create a shared library from its C++ macro (scripts).
2672 /// Currently in order to execute a script, a user has to type at the root
2673 /// prompt
2674 /// ~~~ {.cpp}
2675 /// .X myfunc.C(arg1,arg2)
2676 /// ~~~
2677 /// We allow them to type:
2678 /// ~~~ {.cpp}
2679 /// .X myfunc.C++(arg1,arg2)
2680 /// ~~~
2681 /// or
2682 /// ~~~ {.cpp}
2683 /// .X myfunc.C+(arg1,arg2)
2684 /// ~~~
2685 /// In which case an external compiler will be called to create a shared
2686 /// library. This shared library will then be loaded and the function
2687 /// myfunc will be called with the two arguments. With '++' the shared library
2688 /// is always recompiled. With '+' the shared library is recompiled only
2689 /// if it does not exist yet or the macro file is newer than the shared
2690 /// library.
2691 ///
2692 /// Of course the + and ++ notation is supported in similar way for .x and .L.
2693 ///
2694 /// Through the function TSystem::SetMakeSharedLib(), the user will be able to
2695 /// indicate, with shell commands, how to build a shared library (a good
2696 /// default will be provided). The most common change, namely where to find
2697 /// header files, will be available through the function
2698 /// TSystem::SetIncludePath().
2699 /// A good default will be provided so that a typical user session should be at
2700 /// most:
2701 /// ~~~ {.cpp}
2702 /// root[1] gSystem->SetIncludePath("-I$ROOTSYS/include
2703 /// -I$HOME/mypackage/include");
2704 /// root[2] .x myfunc.C++(10,20);
2705 /// ~~~
2706 /// The user may sometimes try to compile a script before it has loaded all the
2707 /// needed shared libraries. In this case we want to be helpfull and output a
2708 /// list of the unresolved symbols. So if the loading of the created shared
2709 /// library fails, we will try to build a executable that contains the
2710 /// script. The linker should then output a list of missing symbols.
2711 ///
2712 /// To support this we provide a TSystem::SetMakeExe() function, that sets the
2713 /// directive telling how to create an executable. The loader will need
2714 /// to be informed of all the libraries available. The information about
2715 /// the libraries that has been loaded by .L and TSystem::Load() is accesible
2716 /// to the script compiler. However, the information about
2717 /// the libraries that have been selected at link time by the application
2718 /// builder (like the root libraries for root.exe) are not available and need
2719 /// to be explicitly listed in fLinkedLibs (either by default or by a call to
2720 /// TSystem::SetLinkedLibs()).
2721 ///
2722 /// To simplify customization we could also add to the .rootrc support for the
2723 /// variables
2724 /// ~~~ {.cpp}
2725 /// Unix.*.Root.IncludePath: -I$ROOTSYS/include
2726 /// WinNT.*.Root.IncludePath: -I%ROOTSYS%/include
2727 ///
2728 /// Unix.*.Root.LinkedLibs: -L$ROOTSYS/lib -lBase ....
2729 /// WinNT.*.Root.LinkedLibs: %ROOTSYS%/lib/*.lib msvcrt.lib ....
2730 /// ~~~
2731 /// And also support for MakeSharedLibs() and MakeExe().
2732 ///
2733 /// (the ... have to be replaced by the actual values and are here only to
2734 /// shorten this comment).
2735 
2736 int TSystem::CompileMacro(const char *filename, Option_t *opt,
2737  const char *library_specified,
2738  const char *build_dir,
2739  UInt_t dirmode)
2740 {
2741  static const char *version_var_prefix = "__ROOTBUILDVERSION=";
2742 
2743  // ======= Analyze the options
2744  Bool_t keep = kFALSE;
2745  Bool_t recompile = kFALSE;
2746  EAclicMode mode = fAclicMode;
2747  Bool_t loadLib = kTRUE;
2748  Bool_t withInfo = kTRUE;
2749  Bool_t verbose = kFALSE;
2750  Bool_t internalDebug = kFALSE;
2751  if (opt) {
2752  keep = (strchr(opt,'k')!=0);
2753  recompile = (strchr(opt,'f')!=0);
2754  if (strchr(opt,'O')!=0) {
2755  mode = kOpt;
2756  }
2757  if (strchr(opt,'g')!=0) {
2758  mode = kDebug;
2759  }
2760  if (strchr(opt,'c')!=0) {
2761  loadLib = kFALSE;
2762  }
2763  withInfo = strchr(opt, 's') == 0;
2764  verbose = strchr(opt, 'v') != 0;
2765  internalDebug = strchr(opt, 'd') != 0;
2766  }
2767  if (mode==kDefault) {
2768  TString rootbuild = ROOTBUILD;
2769  if (rootbuild.Index("debug",0,TString::kIgnoreCase)==kNPOS) {
2770  mode=kOpt;
2771  } else {
2772  mode=kDebug;
2773  }
2774  }
2775  UInt_t verboseLevel = verbose ? 7 : gDebug;
2776  Bool_t flatBuildDir = (fAclicProperties & kFlatBuildDir) || (strchr(opt,'-')!=0);
2777 
2778  // if non-zero, build_loc indicates where to build the shared library.
2779  TString build_loc = ExpandFileName(GetBuildDir());
2780  if (build_dir && strlen(build_dir)) build_loc = build_dir;
2781  if (build_loc == ".") {
2782  build_loc = WorkingDirectory();
2783  } else if (build_loc.Length() && (!IsAbsoluteFileName(build_loc)) ) {
2784  AssignAndDelete( build_loc , ConcatFileName( WorkingDirectory(), build_loc ) );
2785  }
2786 
2787  // Get the include directory list in the dir1:dir2:dir3 format
2788  // [Used for generating the .d file and to look for header files for
2789  // the linkdef file]
2790  TString incPath = GetIncludePath(); // of the form -Idir1 -Idir2 -Idir3
2791  incPath.Append(":").Prepend(" ");
2792  if (gEnv) {
2793  TString fromConfig = gEnv->GetValue("ACLiC.IncludePaths","");
2794  incPath.Append(fromConfig);
2795  }
2796  incPath.ReplaceAll(" -I",":"); // of form :dir1 :dir2:dir3
2797  while ( incPath.Index(" :") != -1 ) {
2798  incPath.ReplaceAll(" :",":");
2799  }
2800  incPath.Prepend(":.:");
2801  incPath.Prepend(WorkingDirectory());
2802 
2803  // ======= Get the right file names for the dictionary and the shared library
2804  TString expFileName(filename);
2805  ExpandPathName( expFileName );
2806  TString library = expFileName;
2807  if (! IsAbsoluteFileName(library) )
2808  {
2809  const char *whichlibrary = Which(incPath,library);
2810  if (whichlibrary) {
2811  library = whichlibrary;
2812  delete [] whichlibrary;
2813  } else {
2814  ::Error("ACLiC","The file %s can not be found in the include path: %s",filename,incPath.Data());
2815  return kFALSE;
2816  }
2817  } else {
2818  if (gSystem->AccessPathName(library)) {
2819  ::Error("ACLiC","The file %s can not be found.",filename);
2820  return kFALSE;
2821  }
2822  }
2823  { // Remove multiple '/' characters, rootcint treats them as comments.
2824  Ssiz_t pos = 0;
2825  while ((pos = library.Index("//", 2, pos, TString::kExact)) != kNPOS) {
2826  library.Remove(pos, 1);
2827  }
2828  }
2829  TString filename_fullpath = library;
2830 
2831  TString file_dirname = DirName( filename_fullpath );
2832  // For some probably good reason, DirName on Windows returns the 'name' of
2833  // the directory, omitting the drive letter (even if there was one). In
2834  // consequence the result is not useable as a 'root directory', we need to
2835  // add the drive letter if there was one..
2836  if (library.Length()>1 && isalpha(library[0]) && library[1]==':') {
2837  file_dirname.Prepend(library(0,2));
2838  }
2839  TString file_location( file_dirname ); // Location of the script.
2840  incPath.Prepend( file_location + ":" );
2841 
2842  Ssiz_t dot_pos = library.Last('.');
2843  TString extension = library;
2844  extension.Replace( 0, dot_pos+1, 0 , 0);
2845  TString libname_noext = library;
2846  if (dot_pos>=0) libname_noext.Remove( dot_pos );
2847 
2848  // Extension of shared library is platform dependent!!
2849  library.Replace( dot_pos, library.Length()-dot_pos,
2850  TString("_") + extension + "." + fSoExt );
2851 
2852  TString libname ( BaseName( libname_noext ) );
2853  libname.Append("_").Append(extension);
2854 
2855  if (library_specified && strlen(library_specified) ) {
2856  // Use the specified name instead of the default
2857  libname = BaseName( library_specified );
2858  library = library_specified;
2859  ExpandPathName( library );
2860  if (! IsAbsoluteFileName(library) ) {
2861  AssignAndDelete( library , ConcatFileName( WorkingDirectory(), library ) );
2862  }
2863  library = TString(library) + "." + fSoExt;
2864  }
2865 
2866  TString libname_ext ( libname );
2867  libname_ext += "." + fSoExt;
2868 
2869  TString lib_dirname = DirName( library );
2870  // For some probably good reason, DirName on Windows returns the 'name' of
2871  // the directory, omitting the drive letter (even if there was one). In
2872  // consequence the result is not useable as a 'root directory', we need to
2873  // add the drive letter if there was one..
2874  if (library.Length()>1 && isalpha(library[0]) && library[1]==':') {
2875  lib_dirname.Prepend(library(0,2));
2876  }
2877  // Strip potential, somewhat redundant '/.' from the pathname ...
2878  if ( strncmp( &(lib_dirname[lib_dirname.Length()-2]), "/.", 2) == 0 ) {
2879  lib_dirname.Remove(lib_dirname.Length()-2);
2880  }
2881  if ( strncmp( &(lib_dirname[lib_dirname.Length()-2]), "\\.", 2) == 0 ) {
2882  lib_dirname.Remove(lib_dirname.Length()-2);
2883  }
2884  TString lib_location( lib_dirname );
2885  Bool_t mkdirFailed = kFALSE;
2886 
2887  if (build_loc.Length()==0) {
2888  build_loc = lib_location;
2889  } else {
2890  // Removes an existing disk specification from the names
2891  TRegexp disk_finder ("[A-z]:");
2892  Int_t pos = library.Index( disk_finder );
2893  if (pos==0) library.Remove(pos,3);
2894  pos = lib_location.Index( disk_finder );
2895  if (pos==0) lib_location.Remove(pos,3);
2896 
2897  if (flatBuildDir) {
2898  AssignAndDelete( library, ConcatFileName( build_loc, libname_ext) );
2899  } else {
2900  AssignAndDelete( library, ConcatFileName( build_loc, library) );
2901  }
2902 
2903  Bool_t canWriteBuild_loc = !gSystem->AccessPathName(build_loc,kWritePermission);
2904  TString build_loc_store( build_loc );
2905  if (!flatBuildDir) {
2906  AssignAndDelete( build_loc, ConcatFileName( build_loc, lib_location) );
2907  }
2908 
2909  if (gSystem->AccessPathName(build_loc,kFileExists)) {
2910  mkdirFailed = (0 != mkdir(build_loc, true));
2911  if (mkdirFailed && !canWriteBuild_loc) {
2912  // The mkdir failed __and__ we can not write to the target directory,
2913  // let make sure the error message will be about the target directory
2914  build_loc = build_loc_store;
2915  mkdirFailed = kFALSE;
2916  } else if (!mkdirFailed && dirmode!=0) {
2917  Chmod(build_loc,dirmode);
2918  }
2919  }
2920  }
2921 
2922  // ======= Check if the library need to loaded or compiled
2923  if ( gInterpreter->IsLoaded(expFileName) &&
2924  !gInterpreter->IsLoaded(library) ) {
2925  // the script has already been loaded in interpreted mode
2926  // Let's warn the user and unload it.
2927 
2928  if (withInfo) {
2929  ::Info("ACLiC","script has already been loaded in interpreted mode");
2930  ::Info("ACLiC","unloading %s and compiling it", filename);
2931  }
2932 
2933  if ( gInterpreter->UnloadFile( expFileName ) != 0 ) {
2934  // We can not unload it.
2935  return kFALSE;
2936  }
2937  }
2938 
2939  // Calculate the -I lines
2940  TString includes = GetIncludePath();
2941  includes.Prepend(' ');
2942 
2943  {
2944  // I need to replace the -Isomerelativepath by -I../ (or -I..\ on NT)
2945  TRegexp rel_inc(" -I[^\"/\\$%-][^:-]+");
2946  Int_t len,pos;
2947  pos = rel_inc.Index(includes,&len);
2948  while( len != 0 ) {
2949  TString sub = includes(pos,len);
2950  sub.Remove(0,3); // Remove ' -I'
2952  sub.Prepend(" -I\"");
2953  sub.Append("\"");
2954  includes.Replace(pos,len,sub);
2955  pos = rel_inc.Index(includes,&len);
2956  }
2957  }
2958  {
2959  // I need to replace the -I"somerelativepath" by -I"$cwd/ (or -I"$cwd\ on NT)
2960  TRegexp rel_inc(" -I\"[^/\\$%-][^:-]+");
2961  Int_t len,pos;
2962  pos = rel_inc.Index(includes,&len);
2963  while( len != 0 ) {
2964  TString sub = includes(pos,len);
2965  sub.Remove(0,4); // Remove ' -I"'
2967  sub.Prepend(" -I\"");
2968  includes.Replace(pos,len,sub);
2969  pos = rel_inc.Index(includes,&len);
2970  }
2971  }
2972  //includes += " -I\"" + build_loc;
2973  //includes += "\" -I\"";
2974  //includes += WorkingDirectory();
2975 // if (includes[includes.Length()-1] == '\\') {
2976 // // The current directory is (most likely) the root of a windows drive and
2977 // // has a trailing \ which would espace the quote if left by itself.
2978 // includes += '\\';
2979 // }
2980 // includes += "\"";
2981  if (gEnv) {
2982  TString fromConfig = gEnv->GetValue("ACLiC.IncludePaths","");
2983  includes.Append(" ").Append(fromConfig).Append(" ");
2984  }
2985 
2986  // Extract the -D for the dependency generation.
2987  TString defines = " ";
2988  {
2989  TString cmd = GetMakeSharedLib();
2990  TRegexp rel_def("-D[^\\s\\t\\n\\r]*");
2991  Int_t len,pos;
2992  pos = rel_def.Index(cmd,&len);
2993  while( len != 0 ) {
2994  defines += cmd(pos,len);
2995  defines += " ";
2996  pos = rel_def.Index(cmd,&len,pos+1);
2997  }
2998 
2999  }
3000 
3001  TString emergency_loc;
3002  {
3003  UserGroup_t *ug = gSystem->GetUserInfo(gSystem->GetUid());
3004  if (ug) {
3005  AssignAndDelete( emergency_loc, ConcatFileName( TempDirectory(), ug->fUser ) );
3006  delete ug;
3007  } else {
3008  emergency_loc = TempDirectory();
3009  }
3010  }
3011 
3012  Bool_t canWrite = !gSystem->AccessPathName(build_loc,kWritePermission);
3013 
3014  Bool_t modified = kFALSE;
3015 
3016  // Generate the dependency filename
3017  TString depdir = build_loc;
3018  TString depfilename;
3019  AssignAndDelete( depfilename, ConcatFileName(depdir, BaseName(libname_noext)) );
3020  depfilename += "_" + extension + ".d";
3021 
3022  if ( !recompile ) {
3023 
3024  Long_t lib_time, file_time;
3025 
3026  if ((gSystem->GetPathInfo( library, 0, (Long_t*)0, 0, &lib_time ) != 0) ||
3027  (gSystem->GetPathInfo( expFileName, 0, (Long_t*)0, 0, &file_time ) == 0 &&
3028  (lib_time < file_time))) {
3029 
3030  // the library does not exist or is older than the script.
3031  recompile = kTRUE;
3032  modified = kTRUE;
3033 
3034  } else {
3035 
3036  if ( gSystem->GetPathInfo( depfilename, 0,(Long_t*) 0, 0, &file_time ) != 0 ) {
3037  if (!canWrite) {
3038  depdir = emergency_loc;
3039  AssignAndDelete( depfilename, ConcatFileName(depdir, BaseName(libname_noext)) );
3040  depfilename += "_" + extension + ".d";
3041  }
3042  R__WriteDependencyFile(build_loc, depfilename, filename_fullpath, library, libname, extension, version_var_prefix, includes, defines, incPath);
3043  }
3044  }
3045 
3046  if (!modified) {
3047 
3048  // We need to check the dependencies
3049  FILE * depfile = fopen(depfilename.Data(),"r");
3050  if (depfile==0) {
3051  // there is no accessible dependency file, let's assume the library has been
3052  // modified
3053  modified = kTRUE;
3054  recompile = kTRUE;
3055 
3056  } else {
3057 
3058  TString version_var = libname + version_var_prefix;
3059 
3060  Int_t sz = 256;
3061  char *line = new char[sz];
3062  line[0] = 0;
3063 
3064  int c;
3065  Int_t current = 0;
3066  Int_t nested = 0;
3067  Bool_t hasversion = false;
3068 
3069  while ((c = fgetc(depfile)) != EOF) {
3070  if (c=='#') {
3071  // skip comment
3072  while ((c = fgetc(depfile)) != EOF) {
3073  if (c=='\n') {
3074  break;
3075  }
3076  }
3077  continue;
3078  }
3079  if (current && line[current-1]=='=' && strncmp(version_var.Data(),line,current)==0) {
3080 
3081  // The next word will be the version number.
3082  hasversion = kTRUE;
3083  line[0] = 0;
3084  current = 0;
3085  } else if (isspace(c) && !nested) {
3086  if (current) {
3087  if (line[current-1]!=':') {
3088  // ignore target
3089  line[current] = 0;
3090 
3091  Long_t filetime;
3092  if (hasversion) {
3093  modified |= strcmp(ROOT_RELEASE,line)!=0;
3094  hasversion = kFALSE;
3095  } else if ( gSystem->GetPathInfo( line, 0, (Long_t*)0, 0, &filetime ) == 0 ) {
3096  modified |= ( lib_time <= filetime );
3097  }
3098  }
3099  }
3100  current = 0;
3101  line[0] = 0;
3102  } else {
3103  if (current==sz-1) {
3104  sz = 2*sz;
3105  char *newline = new char[sz];
3106  strcpy(newline,line);
3107  delete [] line;
3108  line = newline;
3109  }
3110  if (c=='"') nested = !nested;
3111  else {
3112  line[current] = c;
3113  current++;
3114  }
3115  }
3116  }
3117  delete [] line;
3118  fclose(depfile);
3119  recompile = modified;
3120 
3121  }
3122 
3123  }
3124  }
3125 
3126  if ( gInterpreter->IsLoaded(library)
3127  || strlen(GetLibraries(library,"D",kFALSE)) != 0 ) {
3128  // The library has already been built and loaded.
3129 
3130  Bool_t reload = kFALSE;
3131  TNamed *libinfo = (TNamed*)fCompiled->FindObject(library);
3132  if (libinfo) {
3133  Long_t load_time = libinfo->GetUniqueID();
3134  Long_t lib_time;
3135  if ( gSystem->GetPathInfo( library, 0, (Long_t*)0, 0, &lib_time ) == 0
3136  && (lib_time>load_time)) {
3137  reload = kTRUE;
3138  }
3139  }
3140 
3141  if ( !recompile && reload ) {
3142 
3143  if (withInfo) {
3144  ::Info("ACLiC","%s has been modified and will be reloaded",
3145  libname.Data());
3146  }
3147  if ( gInterpreter->UnloadFile( library.Data() ) != 0 ) {
3148  // The library is being used. We can not unload it.
3149  return kFALSE;
3150  }
3151  if (libinfo) {
3152  fCompiled->Remove(libinfo);
3153  delete libinfo;
3154  libinfo = 0;
3155  }
3156  TNamed *k = new TNamed(library,library);
3157  Long_t lib_time;
3158  gSystem->GetPathInfo( library, 0, (Long_t*)0, 0, &lib_time );
3159  k->SetUniqueID(lib_time);
3160  if (!keep) k->SetBit(kMustCleanup);
3161  fCompiled->Add(k);
3162 
3163  return !gSystem->Load(library);
3164  }
3165 
3166  if (withInfo) {
3167  ::Info("ACLiC","%s script has already been compiled and loaded",
3168  modified ? "modified" : "unmodified");
3169  }
3170 
3171  if ( !recompile ) {
3172  return kTRUE;
3173  } else {
3174  if (withInfo) {
3175  ::Info("ACLiC","it will be regenerated and reloaded!");
3176  }
3177  if ( gInterpreter->UnloadFile( library.Data() ) != 0 ) {
3178  // The library is being used. We can not unload it.
3179  return kFALSE;
3180  }
3181  if (libinfo) {
3182  fCompiled->Remove(libinfo);
3183  delete libinfo;
3184  libinfo = 0;
3185  }
3186  Unlink(library);
3187  }
3188 
3189  }
3190 
3191  TString libmapfilename;
3192  AssignAndDelete( libmapfilename, ConcatFileName( build_loc, libname ) );
3193  libmapfilename += ".rootmap";
3194 #if (defined(R__MACOSX) && !defined(MAC_OS_X_VERSION_10_5)) || defined(R__WIN32)
3195  Bool_t produceRootmap = kTRUE;
3196 #else
3197  Bool_t produceRootmap = kFALSE;
3198 #endif
3199  Bool_t linkDepLibraries = !produceRootmap;
3200  if (gEnv) {
3201 #if (defined(R__MACOSX) && !defined(MAC_OS_X_VERSION_10_5))
3202  Int_t linkLibs = gEnv->GetValue("ACLiC.LinkLibs",2);
3203 #elif defined(R__WIN32)
3204  Int_t linkLibs = gEnv->GetValue("ACLiC.LinkLibs",3);
3205 #else
3206  Int_t linkLibs = gEnv->GetValue("ACLiC.LinkLibs",1);
3207 #endif
3208  produceRootmap = linkLibs & 0x2;
3209  linkDepLibraries = linkLibs & 0x1;
3210  }
3211 
3212  if (!recompile) {
3213  // The library already exist, let's just load it.
3214  if (loadLib) {
3215  TNamed *k = new TNamed(library,library);
3216  Long_t lib_time;
3217  gSystem->GetPathInfo( library, 0, (Long_t*)0, 0, &lib_time );
3218  k->SetUniqueID(lib_time);
3219  if (!keep) k->SetBit(kMustCleanup);
3220  fCompiled->Add(k);
3221 
3222  if (gInterpreter->GetSharedLibDeps(libname) == 0) {
3223  gInterpreter->LoadLibraryMap(libmapfilename);
3224  }
3225 
3226  return !gSystem->Load(library);
3227  }
3228  else return kTRUE;
3229  }
3230 
3231  if (!canWrite && recompile) {
3232 
3233  if (mkdirFailed) {
3234  ::Warning("ACLiC","Could not create the directory: %s",
3235  build_loc.Data());
3236  } else {
3237  ::Warning("ACLiC","%s is not writable!",
3238  build_loc.Data());
3239  }
3240  if (emergency_loc == build_dir ) {
3241  ::Error("ACLiC","%s is the last resort location (i.e. temp location)",build_loc.Data());
3242  return kFALSE;
3243  }
3244  ::Warning("ACLiC","Output will be written to %s",
3245  emergency_loc.Data());
3246  return CompileMacro(expFileName, opt, library_specified, emergency_loc, dirmode);
3247  }
3248 
3249  if (withInfo) {
3250  Info("ACLiC","creating shared library %s",library.Data());
3251  }
3252 
3253  R__WriteDependencyFile(build_loc, depfilename, filename_fullpath, library, libname, extension, version_var_prefix, includes, defines, incPath);
3254 
3255  // ======= Select the dictionary name
3256  TString dict = libname + "_ACLiC_dict";
3257 
3258  // the file name end up in the file produced
3259  // by rootcint as a variable name so all character need to be valid!
3260  static const int maxforbidden = 27;
3261  static const char *forbidden_chars[maxforbidden] =
3262  { "+","-","*","/","&","%","|","^",">","<",
3263  "=","~",".","(",")","[","]","!",",","$",
3264  " ",":","'","#","@","\\","\"" };
3265  for( int ic = 0; ic < maxforbidden; ic++ ) {
3266  dict.ReplaceAll( forbidden_chars[ic],"_" );
3267  }
3268  if ( dict.Last('.')!=dict.Length()-1 ) dict.Append(".");
3269  AssignAndDelete( dict, ConcatFileName( build_loc, dict ) );
3270  TString dicth = dict;
3271  TString dictObj = dict;
3272  dict += "cxx"; //no need to keep the extension of the original file, any extension will do
3273  dicth += "h";
3274  dictObj += fObjExt;
3275 
3276  // ======= Generate a linkdef file
3277 
3278  TString linkdef;
3279  AssignAndDelete( linkdef, ConcatFileName( build_loc, libname ) );
3280  linkdef += "_ACLiC_linkdef.h";
3281  std::ofstream linkdefFile( linkdef, std::ios::out );
3282  linkdefFile << "// File Automatically generated by the ROOT Script Compiler "
3283  << std::endl;
3284  linkdefFile << std::endl;
3285  linkdefFile << "#ifdef __CINT__" << std::endl;
3286  linkdefFile << std::endl;
3287  linkdefFile << "#pragma link C++ nestedclasses;" << std::endl;
3288  linkdefFile << "#pragma link C++ nestedtypedefs;" << std::endl;
3289  linkdefFile << std::endl;
3290 
3291  // We want to look for a header file that has the same name as the macro
3292 
3293  const char * extensions[] = { ".h", ".hh", ".hpp", ".hxx", ".hPP", ".hXX" };
3294 
3295  int i;
3296  for (i = 0; i < 6; i++ ) {
3297  char * name;
3298  TString extra_linkdef = BaseName( libname_noext );
3299  extra_linkdef.Append(GetLinkdefSuffix());
3300  extra_linkdef.Append(extensions[i]);
3301  name = Which(incPath,extra_linkdef);
3302  if (name) {
3303  if (verboseLevel>4 && withInfo) {
3304  Info("ACLiC","including extra linkdef file: %s",name);
3305  }
3306  linkdefFile << "#include \"" << name << "\"" << std::endl;
3307  delete [] name;
3308  }
3309  }
3310 
3311  if (verboseLevel>5 && withInfo) {
3312  Info("ACLiC","looking for header in: %s",incPath.Data());
3313  }
3314  for (i = 0; i < 6; i++ ) {
3315  char * name;
3316  TString lookup = BaseName( libname_noext );
3317  lookup.Append(extensions[i]);
3318  name = Which(incPath,lookup);
3319  if (name) {
3320  linkdefFile << "#pragma link C++ defined_in "<<name<<";"<< std::endl;
3321  delete [] name;
3322  }
3323  }
3324  linkdefFile << "#pragma link C++ defined_in \""<<filename_fullpath << "\";" << std::endl;
3325  linkdefFile << std::endl;
3326  linkdefFile << "#endif" << std::endl;
3327  linkdefFile.close();
3328 
3329  // ======= Generate the list of rootmap files to be looked at
3330 
3331  TString mapfile;
3332  AssignAndDelete( mapfile, ConcatFileName( build_loc, libname ) );
3333  mapfile += "_ACLiC_map";
3334  TString mapfilein = mapfile + ".in";
3335  TString mapfileout = mapfile + ".out";
3336 
3337  Bool_t needLoadMap = kFALSE;
3338  if (gInterpreter->GetSharedLibDeps(libname) !=0 ) {
3339  gInterpreter->UnloadLibraryMap(libname);
3340  needLoadMap = kTRUE;
3341  }
3342 
3343  std::ofstream mapfileStream( mapfilein, std::ios::out );
3344  {
3345  TString name = ".rootmap";
3346  TString sname = "system.rootmap";
3347  TString file;
3348 #ifdef ROOTETCDIR
3349  AssignAndDelete(file, ConcatFileName(ROOTETCDIR, sname) );
3350 #else
3351  TString etc = gRootDir;
3352 #ifdef WIN32
3353  etc += "\\etc";
3354 #else
3355  etc += "/etc";
3356 #endif
3357  AssignAndDelete(file, ConcatFileName(etc, sname));
3358  if (gSystem->AccessPathName(file)) {
3359  // for backward compatibility check also $ROOTSYS/system<name> if
3360  // $ROOTSYS/etc/system<name> does not exist
3361  AssignAndDelete(file, ConcatFileName(gRootDir, sname));
3362  if (gSystem->AccessPathName(file)) {
3363  // for backward compatibility check also $ROOTSYS/<name> if
3364  // $ROOTSYS/system<name> does not exist
3365  AssignAndDelete(file, ConcatFileName(gRootDir, name));
3366  }
3367  }
3368 #endif
3369  mapfileStream << file << std::endl;
3370  AssignAndDelete(file, ConcatFileName(gSystem->HomeDirectory(), name) );
3371  mapfileStream << file << std::endl;
3372  mapfileStream << name << std::endl;
3373  if (gInterpreter->GetRootMapFiles()) {
3374  for (i = 0; i < gInterpreter->GetRootMapFiles()->GetEntriesFast(); i++) {
3375  mapfileStream << ((TNamed*)gInterpreter->GetRootMapFiles()->At(i))->GetTitle() << std::endl;
3376  }
3377  }
3378  }
3379  mapfileStream.close();
3380 
3381  // ======= Generate the rootcling command line
3382  TString rcling;
3383 #ifndef ROOTBINDIR
3384  rcling = gSystem->Getenv("ROOTSYS");
3385 #ifndef R__WIN32
3386  rcling += "/bin/";
3387 #else
3388  rcling += "\\bin\\";
3389 #endif
3390 #else
3391  rcling = ROOTBINDIR;
3392 #ifndef R__WIN32
3393  rcling += "/";
3394 #else
3395  rcling += "\\";
3396 #endif
3397 #endif
3398  rcling += "rootcling -v0 \"--lib-list-prefix=";
3399  rcling += mapfile;
3400  rcling += "\" -f \"";
3401  rcling.Append(dict).Append("\" -c -p ");
3402  if (produceRootmap) {
3403  rcling += " -rml " + libname + " -rmf \"" + libmapfilename + "\" ";
3404  }
3405  rcling.Append(GetIncludePath()).Append(" -D__ACLIC__ ");
3406  if (produceRootmap) {
3407  rcling.Append("-DR__ACLIC_ROOTMAP ");
3408  }
3409  if (gEnv) {
3410  TString fromConfig = gEnv->GetValue("ACLiC.IncludePaths","");
3411  rcling.Append(fromConfig).Append(" \"");
3412  }
3413  rcling.Append(filename_fullpath).Append("\" \"").Append(linkdef).Append("\"");;
3414 
3415  // ======= Run rootcint
3416  if (withInfo) {
3417  if (verboseLevel>3) {
3418  ::Info("ACLiC","creating the dictionary files");
3419  if (verboseLevel>4) ::Info("ACLiC", "%s", rcling.Data());
3420  }
3421  }
3422 
3423  Int_t dictResult = gSystem->Exec(rcling);
3424  if (dictResult) {
3425  if (dictResult==139) ::Error("ACLiC","Dictionary generation failed with a core dump!");
3426  else ::Error("ACLiC","Dictionary generation failed!");
3427  }
3428 
3429  Bool_t result = !dictResult;
3430  TString depLibraries;
3431 
3432  // ======= Load the library the script might depend on
3433  if (result) {
3434  TString linkedlibs = GetLibraries("", "S");
3435  TString libtoload;
3436  TString all_libtoload;
3437  std::ifstream liblist(mapfileout);
3438 
3439  while ( liblist >> libtoload ) {
3440  // Load the needed library except for the library we are currently building!
3441  if (libtoload == "#") {
3442  // The comment terminates the list of libraries.
3443  std::string toskipcomment;
3444  std::getline(liblist,toskipcomment);
3445  break;
3446  }
3447  if (libtoload != library && libtoload != libname && libtoload != libname_ext) {
3448  if (produceRootmap) {
3449  if (loadLib || linkDepLibraries /* For GetLibraries to Work */) {
3450  result = gROOT->LoadClass("", libtoload) >= 0;
3451  if (!result) {
3452  // We failed to load one of the dependency.
3453  break;
3454  }
3455  }
3456  if (!linkedlibs.Contains(libtoload)) {
3457  all_libtoload.Append(" ").Append(libtoload);
3458  depLibraries.Append(" ");
3459  depLibraries.Append(GetLibraries(libtoload,"DSL",kFALSE));
3460  depLibraries = depLibraries.Strip(); // Remove any trailing spaces.
3461  }
3462  } else {
3463  gROOT->LoadClass("", libtoload);
3464  }
3465  }
3466  unsigned char c = liblist.peek();
3467  if (c=='\n' || c=='\r') {
3468  // Consume the character
3469  liblist.get();
3470  break;
3471  }
3472  }
3473 
3474 // depLibraries = all_libtoload;
3475 // depLibraries.ReplaceAll(" lib"," -l");
3476 // depLibraries.ReplaceAll(TString::Format(".%s",fSoExt.Data()),"");
3477  }
3478 
3479  // ======= Calculate the libraries for linking:
3480  TString linkLibraries;
3481  /*
3482  this is intentionally disabled until it can become useful
3483  if (gEnv) {
3484  linkLibraries = gEnv->GetValue("ACLiC.Libraries","");
3485  linkLibraries.Prepend(" ");
3486  }
3487  */
3488  linkLibraries.Prepend(GetLibraries("","SDL"));
3489 
3490  // ======= Generate the build command lines
3491  TString cmd = fMakeSharedLib;
3492  // we do not add filename because it is already included via the dictionary(in dicth) !
3493  // dict.Append(" ").Append(filename);
3494  cmd.ReplaceAll("$SourceFiles","-D__ACLIC__ \"$SourceFiles\"");
3495  cmd.ReplaceAll("$SourceFiles",dict);
3496  cmd.ReplaceAll("$ObjectFiles","\"$ObjectFiles\"");
3497  cmd.ReplaceAll("$ObjectFiles",dictObj);
3498  cmd.ReplaceAll("$IncludePath",includes);
3499  cmd.ReplaceAll("$SharedLib","\"$SharedLib\"");
3500  cmd.ReplaceAll("$SharedLib",library);
3501  if (linkDepLibraries) {
3502  if (produceRootmap) {
3503  cmd.ReplaceAll("$DepLibs",depLibraries);
3504  } else {
3505  cmd.ReplaceAll("$DepLibs",linkLibraries);
3506  }
3507  }
3508  cmd.ReplaceAll("$LinkedLibs",linkLibraries);
3509  cmd.ReplaceAll("$LibName",libname);
3510  cmd.ReplaceAll("\"$BuildDir","$BuildDir");
3511  cmd.ReplaceAll("$BuildDir","\"$BuildDir\"");
3512  cmd.ReplaceAll("$BuildDir",build_loc);
3513  if (mode==kDebug) {
3514  cmd.ReplaceAll("$Opt",fFlagsDebug);
3515  } else {
3516  cmd.ReplaceAll("$Opt",fFlagsOpt);
3517  }
3518 #ifdef WIN32
3519  R__FixLink(cmd);
3520 #endif
3521 
3522  TString testcmd = fMakeExe;
3523  TString fakeMain;
3524  AssignAndDelete( fakeMain, ConcatFileName( build_loc, libname ) );
3525  fakeMain += "_ACLiC_main";
3526  fakeMain += extension;
3527  std::ofstream fakeMainFile( fakeMain, std::ios::out );
3528  fakeMainFile << "// File Automatically generated by the ROOT Script Compiler "
3529  << std::endl;
3530  fakeMainFile << "int main(char*argc,char**argvv) {};" << std::endl;
3531  fakeMainFile.close();
3532  // We could append this fake main routine to the compilation line.
3533  // But in this case compiler may output the name of the dictionary file
3534  // and of the fakeMain file while it compiles it. (this would be useless
3535  // confusing output).
3536  // We could also the fake main routine to the end of the dictionary file
3537  // however compilation would fail if a main is already there
3538  // (like stress.cxx)
3539  // dict.Append(" ").Append(fakeMain);
3540  TString exec;
3541  AssignAndDelete( exec, ConcatFileName( build_loc, libname ) );
3542  exec += "_ACLiC_exec";
3543  testcmd.ReplaceAll("$SourceFiles","-D__ACLIC__ \"$SourceFiles\"");
3544  testcmd.ReplaceAll("$SourceFiles",dict);
3545  testcmd.ReplaceAll("$ObjectFiles","\"$ObjectFiles\"");
3546  testcmd.ReplaceAll("$ObjectFiles",dictObj);
3547  testcmd.ReplaceAll("$IncludePath",includes);
3548  testcmd.ReplaceAll("$ExeName",exec);
3549  testcmd.ReplaceAll("$LinkedLibs",linkLibraries);
3550  testcmd.ReplaceAll("$BuildDir",build_loc);
3551  if (mode==kDebug)
3552  testcmd.ReplaceAll("$Opt",fFlagsDebug);
3553  else
3554  testcmd.ReplaceAll("$Opt",fFlagsOpt);
3555 
3556 #ifdef WIN32
3557  R__FixLink(testcmd);
3558 #endif
3559 
3560  // ======= Build the library
3561  if (result) {
3562  if (verboseLevel>3 && withInfo) {
3563  ::Info("ACLiC","compiling the dictionary and script files");
3564  if (verboseLevel>4) ::Info("ACLiC", "%s", cmd.Data());
3565  }
3566  Int_t compilationResult = gSystem->Exec( cmd );
3567  if (compilationResult) {
3568  if (compilationResult==139) ::Error("ACLiC","Compilation failed with a core dump!");
3569  else ::Error("ACLiC","Compilation failed!");
3570  if (produceRootmap) {
3571  gSystem->Unlink(libmapfilename);
3572  }
3573  }
3574  result = !compilationResult;
3575  }
3576 
3577  if ( result ) {
3578 
3579  TNamed *k = new TNamed(library,library);
3580  Long_t lib_time;
3581  gSystem->GetPathInfo( library, 0, (Long_t*)0, 0, &lib_time );
3582  k->SetUniqueID(lib_time);
3583  if (!keep) k->SetBit(kMustCleanup);
3584  fCompiled->Add(k);
3585 
3586  if (needLoadMap) {
3587  gInterpreter->LoadLibraryMap(libmapfilename);
3588  }
3589  if (verboseLevel>3 && withInfo) ::Info("ACLiC","loading the shared library");
3590  if (loadLib) result = !gSystem->Load(library);
3591  else result = kTRUE;
3592 
3593  if ( !result ) {
3594  if (verboseLevel>3 && withInfo) {
3595  ::Info("ACLiC","testing for missing symbols:");
3596  if (verboseLevel>4) ::Info("ACLiC", "%s", testcmd.Data());
3597  }
3598  gSystem->Exec(testcmd);
3599  gSystem->Unlink( exec );
3600  }
3601 
3602  };
3603 
3604  if (verboseLevel<=5 && !internalDebug) {
3605  gSystem->Unlink( dict );
3606  gSystem->Unlink( dicth );
3607  gSystem->Unlink( dictObj );
3608  gSystem->Unlink( linkdef );
3609  gSystem->Unlink( mapfilein );
3610  gSystem->Unlink( mapfileout );
3611  gSystem->Unlink( fakeMain );
3612  gSystem->Unlink( exec );
3613  }
3614  if (verboseLevel>6) {
3615  rcling.Prepend("echo ");
3616  cmd.Prepend("echo \" ").Append(" \" ");
3617  testcmd.Prepend("echo \" ").Append(" \" ");
3618  gSystem->Exec(rcling);
3619  gSystem->Exec( cmd );
3620  gSystem->Exec(testcmd);
3621  }
3622 
3623  return result;
3624 }
3625 
3626 ////////////////////////////////////////////////////////////////////////////////
3627 /// Return the ACLiC properties field. See EAclicProperties for details
3628 /// on the semantic of each bit.
3629 
3631 {
3632  return fAclicProperties;
3633 }
3634 
3635 ////////////////////////////////////////////////////////////////////////////////
3636 /// Return the build architecture.
3637 
3638 const char *TSystem::GetBuildArch() const
3639 {
3640  return fBuildArch;
3641 }
3642 
3643 ////////////////////////////////////////////////////////////////////////////////
3644 /// Return the build compiler
3645 
3646 const char *TSystem::GetBuildCompiler() const
3647 {
3648  return fBuildCompiler;
3649 }
3650 
3651 ////////////////////////////////////////////////////////////////////////////////
3652 /// Return the build compiler version
3653 
3655 {
3656  return fBuildCompilerVersion;
3657 }
3658 
3659 ////////////////////////////////////////////////////////////////////////////////
3660 /// Return the build node name.
3661 
3662 const char *TSystem::GetBuildNode() const
3663 {
3664  return fBuildNode;
3665 }
3666 
3667 ////////////////////////////////////////////////////////////////////////////////
3668 /// Return the path of the build directory.
3669 
3670 const char *TSystem::GetBuildDir() const
3671 {
3672  if (fBuildDir.Length()==0) {
3673  if (!gEnv) return "";
3674  const_cast<TSystem*>(this)->fBuildDir = gEnv->GetValue("ACLiC.BuildDir","");
3675  }
3676  return fBuildDir;
3677 }
3678 
3679 ////////////////////////////////////////////////////////////////////////////////
3680 /// Return the debug flags.
3681 
3682 const char *TSystem::GetFlagsDebug() const
3683 {
3684  return fFlagsDebug;
3685 }
3686 
3687 ////////////////////////////////////////////////////////////////////////////////
3688 /// Return the optimization flags.
3689 
3690 const char *TSystem::GetFlagsOpt() const
3691 {
3692  return fFlagsOpt;
3693 }
3694 
3695 ////////////////////////////////////////////////////////////////////////////////
3696 /// AclicMode indicates whether the library should be built in
3697 /// debug mode or optimized. The values are:
3698 /// - TSystem::kDefault : compile the same as the current ROOT
3699 /// - TSystem::kDebug : compiled in debug mode
3700 /// - TSystem::kOpt : optimized the library
3701 
3703 {
3704  return fAclicMode;
3705 }
3706 
3707 ////////////////////////////////////////////////////////////////////////////////
3708 /// Return the command line use to make a shared library.
3709 /// See TSystem::CompileMacro for more details.
3710 
3711 const char *TSystem::GetMakeSharedLib() const
3712 {
3713  return fMakeSharedLib;
3714 }
3715 
3716 ////////////////////////////////////////////////////////////////////////////////
3717 /// Return the command line use to make an executable.
3718 /// See TSystem::CompileMacro for more details.
3719 
3720 const char *TSystem::GetMakeExe() const
3721 {
3722  return fMakeExe;
3723 }
3724 
3725 ////////////////////////////////////////////////////////////////////////////////
3726 /// Get the list of include path.
3727 
3729 {
3731  fListPaths.Append(" ").Append(gInterpreter->GetIncludePath());
3732  return fListPaths;
3733 }
3734 
3735 ////////////////////////////////////////////////////////////////////////////////
3736 /// Return the list of library linked to this executable.
3737 /// See TSystem::CompileMacro for more details.
3738 
3739 const char *TSystem::GetLinkedLibs() const
3740 {
3741  return fLinkedLibs;
3742 }
3743 
3744 ////////////////////////////////////////////////////////////////////////////////
3745 /// Return the linkdef suffix chosen by the user for ACLiC.
3746 /// See TSystem::CompileMacro for more details.
3747 
3748 const char *TSystem::GetLinkdefSuffix() const
3749 {
3750  if (fLinkdefSuffix.Length()==0) {
3751  if (!gEnv) return "_linkdef";
3752  const_cast<TSystem*>(this)->fLinkdefSuffix = gEnv->GetValue("ACLiC.Linkdef","_linkdef");
3753  }
3754  return fLinkdefSuffix;
3755 }
3756 
3757 ////////////////////////////////////////////////////////////////////////////////
3758 /// Get the shared library extension.
3759 
3760 const char *TSystem::GetSoExt() const
3761 {
3762  return fSoExt;
3763 }
3764 
3765 ////////////////////////////////////////////////////////////////////////////////
3766 /// Get the object file extension.
3767 
3768 const char *TSystem::GetObjExt() const
3769 {
3770  return fObjExt;
3771 }
3772 
3773 ////////////////////////////////////////////////////////////////////////////////
3774 /// Set the location where ACLiC will create libraries and use as
3775 /// a scratch area.
3776 ///
3777 /// If isflast is flase, then the libraries are actually stored in
3778 /// sub-directories of 'build_dir' including the full pathname of the
3779 /// script. If the script is location at /full/path/name/macro.C
3780 /// the library will be located at 'build_dir+/full/path/name/macro_C.so'
3781 /// If 'isflat' is true, then no subdirectory is created and the library
3782 /// is created directly in the directory 'build_dir'. Note that in this
3783 /// mode there is a risk than 2 script of the same in different source
3784 /// directory will over-write each other.
3785 
3786 void TSystem::SetBuildDir(const char* build_dir, Bool_t isflat)
3787 {
3788  fBuildDir = build_dir;
3789  if (isflat) fAclicProperties |= (kFlatBuildDir & kBitMask);
3791 }
3792 
3793 ////////////////////////////////////////////////////////////////////////////////
3794 /// FlagsDebug should contain the options to pass to the C++ compiler
3795 /// in order to compile the library in debug mode.
3796 
3797 void TSystem::SetFlagsDebug(const char *flags)
3798 {
3799  fFlagsDebug = flags;
3800 }
3801 
3802 ////////////////////////////////////////////////////////////////////////////////
3803 /// FlagsOpt should contain the options to pass to the C++ compiler
3804 /// in order to compile the library in optimized mode.
3805 
3806 void TSystem::SetFlagsOpt(const char *flags)
3807 {
3808  fFlagsOpt = flags;
3809 }
3810 
3811 ////////////////////////////////////////////////////////////////////////////////
3812 /// AclicMode indicates whether the library should be built in
3813 /// debug mode or optimized. The values are:
3814 /// - TSystem::kDefault : compile the same as the current ROOT
3815 /// - TSystem::kDebug : compiled in debug mode
3816 /// - TSystem::kOpt : optimized the library
3817 
3819 {
3820  fAclicMode = mode;
3821 }
3822 
3823 ////////////////////////////////////////////////////////////////////////////////
3824 /// Directives has the same syntax as the argument of SetMakeSharedLib but is
3825 /// used to create an executable. This creation is used as a means to output
3826 /// a list of unresolved symbols, when loading a shared library has failed.
3827 /// The required variable is $ExeName rather than $SharedLib, e.g.:
3828 /// ~~~ {.cpp}
3829 /// gSystem->SetMakeExe(
3830 /// "g++ -Wall -fPIC $IncludePath $SourceFiles
3831 /// -o $ExeName $LinkedLibs -L/usr/X11R6/lib -lX11 -lm -ldl -rdynamic");
3832 /// ~~~
3833 
3834 void TSystem::SetMakeExe(const char *directives)
3835 {
3836  fMakeExe = directives;
3837  // NOTE: add verification that the directives has the required variables
3838 }
3839 
3840 ////////////////////////////////////////////////////////////////////////////////
3841 /// Directives should contain the description on how to compile and link a
3842 /// shared lib. This description can be any valid shell command, including
3843 /// the use of ';' to separate several instructions. However, shell specific
3844 /// construct should be avoided. In particular this description can contain
3845 /// environment variables, like $ROOTSYS (or %ROOTSYS% on windows).
3846 /// ~~~ {.cpp}
3847 /// Five special variables will be expanded before execution:
3848 /// Variable name Expands to
3849 /// ------------- ----------
3850 /// $SourceFiles Name of source files to be compiled
3851 /// $SharedLib Name of the shared library being created
3852 /// $LibName Name of shared library without extension
3853 /// $BuildDir Directory where the files will be created
3854 /// $IncludePath value of fIncludePath
3855 /// $LinkedLibs value of fLinkedLibs
3856 /// $DepLibs libraries on which this library depends on
3857 /// $ObjectFiles Name of source files to be compiler with
3858 /// their extension changed to .o or .obj
3859 /// $Opt location of the optimization/debug options
3860 /// set fFlagsDebug and fFlagsOpt
3861 /// ~~~
3862 /// e.g.:
3863 /// ~~~ {.cpp}
3864 /// gSystem->SetMakeSharedLib(
3865 /// "KCC -n32 --strict $IncludePath -K0 \$Opt $SourceFile
3866 /// --no_exceptions --signed_chars --display_error_number
3867 /// --diag_suppress 68 -o $SharedLib");
3868 ///
3869 /// gSystem->setMakeSharedLib(
3870 /// "Cxx $IncludePath -c $SourceFile;
3871 /// ld -L/usr/lib/cmplrs/cxx -rpath /usr/lib/cmplrs/cxx -expect_unresolved
3872 /// \$Opt -shared /usr/lib/cmplrs/cc/crt0.o /usr/lib/cmplrs/cxx/_main.o
3873 /// -o $SharedLib $ObjectFile -lcxxstd -lcxx -lexc -lots -lc"
3874 ///
3875 /// gSystem->SetMakeSharedLib(
3876 /// "$HOME/mygcc/bin/g++ \$Opt -Wall -fPIC $IncludePath $SourceFile
3877 /// -shared -o $SharedLib");
3878 ///
3879 /// gSystem->SetMakeSharedLib(
3880 /// "cl -DWIN32 -D_WIN32 -D_MT -D_DLL -MD /O2 /G5 /MD -DWIN32
3881 /// -D_WINDOWS $IncludePath $SourceFile
3882 /// /link -PDB:NONE /NODEFAULTLIB /INCREMENTAL:NO /RELEASE /NOLOGO
3883 /// $LinkedLibs -entry:_DllMainCRTStartup@12 -dll /out:$SharedLib")
3884 /// ~~~
3885 
3886 void TSystem::SetMakeSharedLib(const char *directives)
3887 {
3888  fMakeSharedLib = directives;
3889  // NOTE: add verification that the directives has the required variables
3890 }
3891 
3892 ////////////////////////////////////////////////////////////////////////////////
3893 /// Add includePath to the already set include path.
3894 
3895 void TSystem::AddIncludePath(const char *includePath)
3896 {
3897  if (includePath) {
3898  fIncludePath += " ";
3899  fIncludePath += includePath;
3900  }
3901 }
3902 
3903 ////////////////////////////////////////////////////////////////////////////////
3904 /// Add linkedLib to already set linked libs.
3905 
3906 void TSystem::AddLinkedLibs(const char *linkedLib)
3907 {
3908  if (linkedLib) {
3909  fLinkedLibs += " ";
3910  fLinkedLibs += linkedLib;
3911  }
3912 }
3913 
3914 ////////////////////////////////////////////////////////////////////////////////
3915 /// IncludePath should contain the list of compiler flags to indicate where
3916 /// to find user defined header files. It is used to expand $IncludePath in
3917 /// the directives given to SetMakeSharedLib() and SetMakeExe(), e.g.:
3918 /// ~~~ {.cpp}
3919 /// gSystem->SetInclude("-I$ROOTSYS/include -Imydirectory/include");
3920 /// ~~~
3921 /// the default value of IncludePath on Unix is:
3922 /// ~~~ {.cpp}
3923 /// "-I$ROOTSYS/include "
3924 /// ~~~
3925 /// and on Windows:
3926 /// ~~~ {.cpp}
3927 /// "/I%ROOTSYS%/include "
3928 /// ~~~
3929 
3930 void TSystem::SetIncludePath(const char *includePath)
3931 {
3932  fIncludePath = includePath;
3933 }
3934 
3935 ////////////////////////////////////////////////////////////////////////////////
3936 /// LinkedLibs should contain the library directory and list of libraries
3937 /// needed to recreate the current executable. It is used to expand $LinkedLibs
3938 /// in the directives given to SetMakeSharedLib() and SetMakeExe()
3939 /// The default value on Unix is: `root-config --glibs`
3940 
3941 void TSystem::SetLinkedLibs(const char *linkedLibs)
3942 {
3943  fLinkedLibs = linkedLibs;
3944 }
3945 
3946 ////////////////////////////////////////////////////////////////////////////////
3947 /// The 'suffix' will be appended to the name of a script loaded by ACLiC
3948 /// and used to locate any eventual additional linkdef information that
3949 /// ACLiC should used to produce the dictionary.
3950 ///
3951 /// So by default, when doing .L MyScript.cxx, ACLiC will look
3952 /// for a file name MyScript_linkdef and having one of the .h (.hpp,
3953 /// etc.) extensions. If such a file exist, it will be added to
3954 /// the end of the linkdef file used to created the ACLiC dictionary.
3955 /// This effectively enable the full customization of the creation
3956 /// of the dictionary. It should be noted that the file is intended
3957 /// as a linkdef `fragment`, so usually you would not list the
3958 /// typical:
3959 ///~~~ {.cpp}
3960 /// #pragma link off ....
3961 ///~~~
3962 
3963 void TSystem::SetLinkdefSuffix(const char *suffix)
3964 {
3965  fLinkdefSuffix = suffix;
3966 }
3967 
3968 
3969 ////////////////////////////////////////////////////////////////////////////////
3970 /// Set shared library extension, should be either .so, .sl, .a, .dll, etc.
3971 
3972 void TSystem::SetSoExt(const char *SoExt)
3973 {
3974  fSoExt = SoExt;
3975 }
3976 
3977 ////////////////////////////////////////////////////////////////////////////////
3978 /// Set object files extension, should be either .o, .obj, etc.
3979 
3980 void TSystem::SetObjExt(const char *ObjExt)
3981 {
3982  fObjExt = ObjExt;
3983 }
3984 
3985 ////////////////////////////////////////////////////////////////////////////////
3986 /// This method split a filename of the form:
3987 /// ~~~ {.cpp}
3988 /// [path/]macro.C[+|++[k|f|g|O|c|s|d|v|-]][(args)].
3989 /// ~~~
3990 /// It stores the ACliC mode [+|++[options]] in 'mode',
3991 /// the arguments (including parenthesis) in arg
3992 /// and the I/O indirection in io
3993 
3994 TString TSystem::SplitAclicMode(const char* filename, TString &aclicMode,
3995  TString &arguments, TString &io) const
3996 {
3997  char *fname = Strip(filename);
3998 
3999  char *arg = strchr(fname, '(');
4000  // special case for $(HOME)/aap.C(10)
4001  while (arg && *arg && (arg > fname && *(arg-1) == '$') && *(arg+1))
4002  arg = strchr(arg+1, '(');
4003  if (arg && arg > fname) {
4004  *arg = 0;
4005  char *t = arg-1;
4006  while (*t == ' ') {
4007  *t = 0; t--;
4008  }
4009  arg++;
4010  }
4011 
4012  // strip off I/O redirect tokens from filename
4013  {
4014  char *s2 = 0;
4015  char *s3;
4016  s2 = strstr(fname, ">>");
4017  if (!s2) s2 = strstr(fname, "2>");
4018  if (!s2) s2 = strchr(fname, '>');
4019  s3 = strchr(fname, '<');
4020  if (s2 && s3) s2 = s2<s3 ? s2 : s3;
4021  if (s3 && !s2) s2 = s3;
4022  if (s2==fname) {
4023  io = fname;
4024  aclicMode = "";
4025  arguments = "";
4026  delete []fname;
4027  return "";
4028  } else if (s2) {
4029  s2--;
4030  while (s2 && *s2 == ' ') s2--;
4031  s2++;
4032  io = s2; // ssave = *s2;
4033  *s2 = 0;
4034  } else
4035  io = "";
4036  }
4037 
4038  // remove the possible ACLiC + or ++ and g or O etc
4039  aclicMode.Clear();
4040  int len = strlen(fname);
4041  TString mode;
4042  while (len > 1) {
4043  if (strchr("kfgOcsdv-", fname[len - 1])) {
4044  mode += fname[len - 1];
4045  --len;
4046  } else {
4047  break;
4048  }
4049  }
4050  Bool_t compile = len && fname[len - 1] == '+';
4051  Bool_t remove = compile && len > 1 && fname[len - 2] == '+';
4052  if (compile) {
4053  if (mode.Length()) {
4054  fname[len] = 0;
4055  }
4056  if (remove) {
4057  fname[strlen(fname)-2] = 0;
4058  aclicMode = "++";
4059  } else {
4060  fname[strlen(fname)-1] = 0;
4061  aclicMode = "+";
4062  }
4063  if (mode.Length())
4064  aclicMode += mode;
4065  }
4066 
4067  TString resFilename = fname;
4068  arguments = "(";
4069  if (arg) arguments += arg;
4070  else arguments = "";
4071 
4072  delete []fname;
4073  return resFilename;
4074 }
4075 
4076 ////////////////////////////////////////////////////////////////////////////////
4077 /// Remove the shared libs produced by the CompileMacro() function.
4078 
4080 {
4081  TIter next(fCompiled);
4082  TNamed *lib;
4083  while ((lib = (TNamed*)next())) {
4084  if (lib->TestBit(kMustCleanup)) Unlink(lib->GetTitle());
4085  }
4086 }
4087 
4088 ////////////////////////////////////////////////////////////////////////////////
4089 /// Register version of plugin library.
4090 
4092 {
4093  if (versionCode != TROOT::RootVersionCode() && gLibraryVersion)
4094  gLibraryVersion[gLibraryVersionIdx] = versionCode;
4095 }
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 TObject * Remove(TObject *obj)=0
virtual void Add(TObject *obj)
ClassImp(TProcessEventTimer) TProcessEventTimer
Create async event processor timer. Delay is in milliseconds.
Definition: TSystem.cxx:65
TSeqCollection * fCompiled
Definition: TSystem.h:311
double read(const std::string &file_name)
reading
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition: TString.cxx:851
TString fBuildCompiler
Definition: TSystem.h:295
virtual Bool_t IsAbsoluteFileName(const char *dir)
Return true if dir is an absolute pathname.
Definition: TSystem.cxx:929
Bool_t fDone
Definition: TSystem.h:283
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:3994
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
const char * GetHostName() const
Definition: TInetAddress.h:75
virtual Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in 'path' 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 fSigcnt
Definition: TSystem.h:275
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 TObject * FindObject(const char *name) const
Find an object in this collection using its name.
virtual const char * GetBuildCompiler() const
Return the build compiler.
Definition: TSystem.cxx:3646
virtual void SigAlarmInterruptsSyscalls(Bool_t)
Definition: TSystem.h:320
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:3797
virtual void NotifyApplicationCreated()
Hook to tell TSystem that the TApplication object has been created.
Definition: TSystem.cxx:315
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
R__EXTERN TVirtualMutex * gSystemMutex
Definition: TSystem.h:236
Ssiz_t Length() const
Definition: TString.h:390
TLine * line
Collectable string class.
Definition: TObjString.h:32
Int_t fLevel
Definition: TSystem.h:284
return c
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:3748
const char * current
Definition: demos.C:12
virtual int Link(const char *from, const char *to)
Create a link from file1 to file2.
Definition: TSystem.cxx:1276
Int_t fBeepFreq
Definition: TSystem.h:279
virtual const char * GetBuildArch() const
Return the build architecture.
Definition: TSystem.cxx:3638
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:3806
virtual const char * GetLinkedLibraries()
Get list of shared libraries loaded at the start of the executable.
Definition: TSystem.cxx:2014
TSeqCollection * fOnExitList
Definition: TSystem.h:290
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
TString fBuildCompilerVersion
Definition: TSystem.h:296
void regexp()
Definition: regexp.C:34
static Int_t RootVersionCode()
Return ROOT version code as defined in RVersion.h.
Definition: TROOT.cxx:2552
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
TString fBuildNode
Definition: TSystem.h:297
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
tuple pname
Definition: tree.py:131
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's home directory.
Definition: TSystem.cxx:873
virtual void CloseConnection(int sock, Bool_t force=kFALSE)
Close socket connection.
Definition: TSystem.cxx:2292
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:4091
#define gROOT
Definition: TROOT.h:344
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:3834
Int_t LoadPlugin()
Load the plugin library for this handler.
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
TSeqCollection * fSignalHandler
Definition: TSystem.h:287
TString fBuildArch
Definition: TSystem.h:294
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:2458
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:73
#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:3886
virtual int AnnounceUdpService(int port, int backlog)
Announce UDP service.
Definition: TSystem.cxx:2256
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:2202
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:3702
virtual int GetProcInfo(ProcInfo_t *info) const
Returns cpu and memory used by this process into the ProcInfo_t structure.
Definition: TSystem.cxx:2391
virtual int SendRaw(int sock, const void *buffer, int length, int flag)
Send exactly length bytes from buffer.
Definition: TSystem.cxx:2311
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:2229
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
TSeqCollection * fStdExceptionHandler
Definition: TSystem.h:289
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 void Delete(Option_t *option="")=0
Delete this object.
virtual void * GetDirPtr() const
Definition: TSystem.h:405
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:436
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:2321
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
TString fBuildDir
Definition: TSystem.h:298
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
Int_t fMaxrfd
Definition: TSystem.h:273
TSeqCollection * fHelpers
Definition: TSystem.h:312
TString fListPaths
Definition: TSystem.h:301
virtual const char * GetLinkedLibs() const
Return the list of library linked to this executable.
Definition: TSystem.cxx:3739
TString fLinkedLibs
Definition: TSystem.h:303
Bool_t fTimeout
Definition: TTimer.h:62
UChar_t mod R__LOCKGUARD2(gSrvAuthenticateMutex)
TObject * Next()
Return next object in collection.
Int_t fNfd
Signals that were trapped.
Definition: TSystem.h:272
virtual const char * GetDynamicPath()
Return the dynamic path (used to find shared libraries).
Definition: TSystem.cxx:1705
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
void Clear()
Clear string without changing its capacity.
Definition: TString.cxx:1126
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:2736
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:1959
if(pyself &&pyself!=Py_None)
virtual const char * GetMakeSharedLib() const
Return the command line use to make a shared library.
Definition: TSystem.cxx:3711
void Info(const char *location, const char *msgfmt,...)
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:2301
virtual ~TSystem()
Delete the OS interface.
Definition: TSystem.cxx:142
virtual void Unload(const char *module)
Unload a shared library.
Definition: TSystem.cxx:1938
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 'path' or 'dirptr'.
Definition: TSystem.cxx:798
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
Definition: TSystem.cxx:2193
void Error(const char *location, const char *msgfmt,...)
char * out
Definition: TBase64.cxx:29
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:3682
TSeqCollection * fFileHandler
Definition: TSystem.h:288
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition: TObject.cxx:743
TString fLinkdefSuffix
Definition: TSystem.h:309
A doubly linked list.
Definition: TList.h:47
TString & GetLastErrorString()
Return the thread local storage for the custom last error message.
Definition: TSystem.cxx:1996
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:3760
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
TThread * t[5]
Definition: threadsh1.C:13
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
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:2472
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:2207
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:3662
SVector< double, 2 > v
Definition: Dict.h:5
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
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:2032
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:494
virtual int AcceptConnection(int sock)
Accept a connection.
Definition: TSystem.cxx:2283
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:2399
char * Strip(const char *str, char c= ' ')
Strip leading and trailing c (blanks by default) from a string.
Definition: TString.cxx:2464
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:2247
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:2533
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:3786
virtual int SendBuf(int sock, const void *buffer, int length)
Send a buffer headed by a length indicator.
Definition: TSystem.cxx:2329
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'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:3670
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
virtual void ListSymbols(const char *module, const char *re="")
List symbols in a shared library.
Definition: TSystem.cxx:1950
virtual const char * GetMakeExe() const
Return the command line use to make an executable.
Definition: TSystem.cxx:3720
TSubString Strip(EStripType s=kTrailing, char c= ' ') const
Return a substring of self stripped at beginning and/or end.
Definition: TString.cxx:1056
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.
TString fMakeExe
Definition: TSystem.h:308
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:3972
Bool_t IsNull() const
Definition: TString.h:387
virtual const char * GetBuildCompilerVersion() const
Return the build compiler version.
Definition: TSystem.cxx:3654
TString fListLibs
Definition: TSystem.h:292
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:2371
void Warning(const char *location, const char *msgfmt,...)
Long64_t entry
TString fName
Definition: TNamed.h:36
virtual void Unsetenv(const char *name)
Unset environment variable.
Definition: TSystem.cxx:1567
Int_t fAclicProperties
Definition: TSystem.h:310
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:2227
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:2500
virtual int OpenConnection(const char *server, int port, int tcpwindowsize=-1, const char *protocol="tcp")
Open a connection to another host.
Definition: TSystem.cxx:2238
virtual int SetSockOpt(int sock, int kind, int val)
Set socket option.
Definition: TSystem.cxx:2338
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
TEllipse dict(9, 20, 3, 1.5)
virtual const char * FindDynamicLibrary(TString &lib, Bool_t quiet=kFALSE)
Find a dynamic library using the system search paths.
Definition: TSystem.cxx:1920
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
EAclicMode fAclicMode
Definition: TSystem.h:306
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:3728
TH1F * s2
Definition: threadsh2.C:15
virtual const char * GetFlagsOpt() const
Return the optimization flags.
Definition: TSystem.cxx:3690
tuple file
Definition: fildir.py:20
virtual Func_t DynFindSymbol(const char *module, const char *entry)
Find specific entry point in specified library.
Definition: TSystem.cxx:1930
virtual const char * HostName()
Return the system'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:1906
ELogFacility
Definition: TSystem.h:77
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
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
void dir(char *path=0)
Definition: rootalias.C:30
TNamed()
Definition: TNamed.h:40
TString fObjExt
Definition: TSystem.h:305
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's id. If group = 0, returns current user'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:4079
virtual TInetAddress GetSockName(int sock)
Get Internet Protocol (IP) address of host and port #.
Definition: TSystem.cxx:2211
virtual Int_t GetUid(const char *user=0)
Returns the user's id. If user = 0, returns current user's id.
Definition: TSystem.cxx:1472
EAccessMode
Definition: TSystem.h:54
virtual void AddLinkedLibs(const char *linkedLib)
Add linkedLib to already set linked libs.
Definition: TSystem.cxx:3906
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:3818
#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:3980
virtual Bool_t IsFileInIncludePath(const char *name, char **fullpath=0)
Return true if 'name' 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:3630
Int_t fMaxwfd
Definition: TSystem.h:274
TSeqCollection * fTimers
Definition: TSystem.h:286
virtual int RecvBuf(int sock, void *buffer, int length)
Receive a buffer headed by a length indicator.
Definition: TSystem.cxx:2320
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:2220
virtual int AnnounceUnixService(int port, int backlog)
Announce unix domain service.
Definition: TSystem.cxx:2265
const Ssiz_t kNPOS
Definition: Rtypes.h:115
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 'h'...
Definition: TSystem.cxx:1635
Bool_t fInControl
Definition: TSystem.h:282
virtual void SetLinkedLibs(const char *linkedLibs)
LinkedLibs should contain the library directory and list of libraries needed to recreate the current ...
Definition: TSystem.cxx:3941
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:3768
#define ROOT_RELEASE
Definition: RVersion.h:17
TString fFlagsDebug
Definition: TSystem.h:299
Long_t fIno
Definition: TSystem.h:137
TString fFlagsOpt
Definition: TSystem.h:300
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:3895
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
double result[121]
void TurnOn()
Definition: TTimer.cxx:58
virtual int GetMemInfo(MemInfo_t *info) const
Returns ram and swap memory usage info into the MemInfo_t structure.
Definition: TSystem.cxx:2381
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1191
TString fMakeSharedLib
Definition: TSystem.h:307
Int_t fBeepDuration
Definition: TSystem.h:280
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
TString fSoExt
Definition: TSystem.h:304
virtual int GetSockOpt(int sock, int kind, int *val)
Get socket option.
Definition: TSystem.cxx:2347
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.
TObject * obj
virtual void SetLinkdefSuffix(const char *suffix)
The 'suffix' will be appended to the name of a script loaded by ACLiC and used to locate any eventual...
Definition: TSystem.cxx:3963
virtual Int_t GetFPEMask()
Return the bitmap of conditions that trigger a floating point exception.
Definition: TSystem.cxx:636
#define RETRY
Definition: TException.h:53
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
TString fIncludePath
Definition: TSystem.h:302
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:453
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:2360
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:372
Bool_t IsAsync() const
Definition: TTimer.h:87
virtual void DoBeep(Int_t=-1, Int_t=-1) const
Definition: TSystem.h:322
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:3930
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