diff --git a/alien/inc/TAlienSystem.h b/alien/inc/TAlienSystem.h index d3c56e66149367f719e743108c958ba4bc312f9a..c664de1e5b9e71d5ba2d9782b4e68fb37d901919 100644 --- a/alien/inc/TAlienSystem.h +++ b/alien/inc/TAlienSystem.h @@ -1,4 +1,4 @@ -// @(#)root/base:$Name: $:$Id: TSystem.h,v 1.55 2006/03/29 09:21:01 rdm Exp $ +// @(#)root/base:$Name: $:$Id: TAlienSystem.h,v 1.1 2006/05/26 16:55:04 rdm Exp $ // Author: Andreas Peters 15/05/2006 /************************************************************************* @@ -71,7 +71,7 @@ public: virtual int Chmod(const char *file, UInt_t mode); virtual int Umask(Int_t mask); virtual int Utime(const char *file, Long_t modtime, Long_t actime); - virtual char *Which(const char *search, const char *file, EAccessMode mode = kFileExists); + virtual const char *FindFile(const char *search, TString& file, EAccessMode mode = kFileExists); //---- Users & Groups virtual Int_t GetUid(const char *user = 0); diff --git a/alien/src/TAlienSystem.cxx b/alien/src/TAlienSystem.cxx index 2aa42abc6f1f6c818a6838fe96f5a84efff4640e..db2462edf53989985ac49f86c3ec9cbb23ff79d2 100644 --- a/alien/src/TAlienSystem.cxx +++ b/alien/src/TAlienSystem.cxx @@ -1,4 +1,4 @@ -// @(#)root/base:$Name: $:$Id: TAlienSystem.cxx,v 1.2 2006/05/30 15:34:17 rdm Exp $ +// @(#)root/base:$Name: $:$Id: TAlienSystem.cxx,v 1.3 2006/06/01 14:46:49 rdm Exp $ // Author: Andreas Peters 15/05/2006 /************************************************************************* @@ -376,9 +376,9 @@ int TAlienSystem::Utime(const char *, Long_t, Long_t) } //______________________________________________________________________________ -char *TAlienSystem::Which(const char *, const char *, EAccessMode) +const char *TAlienSystem::FindFile(const char *, TString&, EAccessMode) { - // Find location of file in a search path. User must delete returned string. + // Find location of file in a search path. // Returns 0 in case file is not found. AbstractMethod("Which"); diff --git a/base/inc/TSystem.h b/base/inc/TSystem.h index 57181bec3fc8c36b75ffa66491d491a21d4506de..cb644aea71d410258a4d94d136e276b5ecb16959 100644 --- a/base/inc/TSystem.h +++ b/base/inc/TSystem.h @@ -1,4 +1,4 @@ -// @(#)root/base:$Name: v5-11-02 $:$Id: TSystem.h,v 1.55 2006/03/29 09:21:01 rdm Exp $ +// @(#)root/base:$Name: $:$Id: TSystem.h,v 1.56 2006/05/23 04:47:35 brun Exp $ // Author: Fons Rademakers 15/09/95 /************************************************************************* @@ -326,6 +326,7 @@ public: virtual char *ConcatFileName(const char *dir, const char *name); virtual Bool_t IsAbsoluteFileName(const char *dir); virtual Bool_t IsFileInIncludePath(const char *name, char **fullpath = 0); + virtual const char *PrependPathName(const char *dir, TString& name); virtual Bool_t ExpandPathName(TString &path); virtual char *ExpandPathName(const char *path); virtual Bool_t AccessPathName(const char *path, EAccessMode mode = kFileExists); @@ -342,6 +343,7 @@ public: virtual int Umask(Int_t mask); virtual int Utime(const char *file, Long_t modtime, Long_t actime); virtual const char *UnixPathName(const char *unixpathname); + virtual const char *FindFile(const char *search, TString& file, EAccessMode mode = kFileExists); virtual char *Which(const char *search, const char *file, EAccessMode mode = kFileExists); //---- Users & Groups diff --git a/base/src/TSystem.cxx b/base/src/TSystem.cxx index d0bc056acaf895af3eaa4c43bbd755a712ba410b..3eec1979650c5b3cba83966c5287a14883532a30 100644 --- a/base/src/TSystem.cxx +++ b/base/src/TSystem.cxx @@ -1,4 +1,4 @@ -// @(#)root/base:$Name: $:$Id: TSystem.cxx,v 1.140 2006/05/23 04:47:35 brun Exp $ +// @(#)root/base:$Name: $:$Id: TSystem.cxx,v 1.141 2006/05/26 09:01:58 brun Exp $ // Author: Fons Rademakers 15/09/95 /************************************************************************* @@ -952,7 +952,17 @@ const char *TSystem::UnixPathName(const char *name) } //______________________________________________________________________________ -char *TSystem::ConcatFileName(const char *, const char *) +char *TSystem::ConcatFileName(const char *dir, const char *name) +{ + // Concatenate a directory and a file name. User must delete returned string. + + TString nameString(name); + PrependPathName(dir, nameString); + return StrDup(nameString.Data()); +} + +//______________________________________________________________________________ +const char *TSystem::PrependPathName(const char *, TString&) { // Concatenate a directory and a file name. @@ -1299,15 +1309,28 @@ int TSystem::Utime(const char *, Long_t, Long_t) } //______________________________________________________________________________ -char *TSystem::Which(const char *, const char *, EAccessMode) +const char *TSystem::FindFile(const char *, TString&, EAccessMode) { - // Find location of file in a search path. User must delete returned string. + // Find location of file in a search path. Return value points to TString for + // compatibility with Which(const char *, const char *, EAccessMode). // Returns 0 in case file is not found. - AbstractMethod("Which"); + AbstractMethod("FindFile"); return 0; } +//______________________________________________________________________________ +char *TSystem::Which(const char *search, const char *wfil, EAccessMode mode) +{ + // Find location of file in a search path. User must delete returned string. + // Returns 0 in case file is not found. + + TString wfilString(wfil); + FindFile(search, wfilString, mode); + if (wfilString.IsNull()) return 0; + return StrDup(wfilString.Data()); +} + //---- Users & Groups ---------------------------------------------------------- //______________________________________________________________________________ diff --git a/unix/inc/TUnixSystem.h b/unix/inc/TUnixSystem.h index 69cc037892d81fa3c279295087681af7b5978efc..8058898fc44f4e6116d712044414e991c1bf2db6 100644 --- a/unix/inc/TUnixSystem.h +++ b/unix/inc/TUnixSystem.h @@ -1,4 +1,4 @@ -// @(#)root/unix:$Name: $:$Id: TUnixSystem.h,v 1.24 2005/09/13 10:20:30 rdm Exp $ +// @(#)root/unix:$Name: $:$Id: TUnixSystem.h,v 1.25 2005/09/24 11:57:36 rdm Exp $ // Author: Fons Rademakers 15/09/95 /************************************************************************* @@ -139,7 +139,7 @@ public: FILE *TempFileName(TString &base, const char *dir = 0); //---- Paths & Files ---------------------------------------- - char *ConcatFileName(const char *dir, const char *name); + const char *PrependPathName(const char *dir, TString& name); Bool_t ExpandPathName(TString &patbuf); char *ExpandPathName(const char *path); Bool_t AccessPathName(const char *path, EAccessMode mode = kFileExists); @@ -154,7 +154,7 @@ public: int Chmod(const char *file, UInt_t mode); int Umask(Int_t mask); int Utime(const char *file, Long_t modtime, Long_t actime); - char *Which(const char *search, const char *file, EAccessMode mode = kFileExists); + const char *FindFile(const char *search, TString& file, EAccessMode mode = kFileExists); //---- Users & Groups --------------------------------------- Int_t GetUid(const char *user = 0); diff --git a/unix/src/TUnixSystem.cxx b/unix/src/TUnixSystem.cxx index 7f70e9c38799537118d3030460a58c5ba958a974..29d1307ddb219f41900d673a7aa8411ec86d2607 100644 --- a/unix/src/TUnixSystem.cxx +++ b/unix/src/TUnixSystem.cxx @@ -1,4 +1,4 @@ -// @(#)root/unix:$Name: $:$Id: TUnixSystem.cxx,v 1.152 2006/05/19 07:03:36 brun Exp $ +// @(#)root/unix:$Name: $:$Id: TUnixSystem.cxx,v 1.153 2006/05/26 17:11:28 rdm Exp $ // Author: Fons Rademakers 15/09/95 /************************************************************************* @@ -1189,29 +1189,25 @@ FILE *TUnixSystem::TempFileName(TString &base, const char *dir) } //______________________________________________________________________________ -char *TUnixSystem::ConcatFileName(const char *dir, const char *name) +const char *TUnixSystem::PrependPathName(const char *dir, TString& name) { - // Concatenate a directory and a file name. Returned string must be - // deleted by user. + // Concatenate a directory and a file name. - if (name == 0 || strlen(name) <= 0 || strcmp(name, ".") == 0) - return StrDup(dir); - - TString buf; - if (dir && (strcmp(dir, "/") != 0)) { - buf = dir; - if (dir[strlen(dir)-1] == '/') - buf += name; - else { - buf += "/"; - buf += name; - }; - } else { - buf = "/"; - buf +=name; // sprintf(buf, "/%s", name); + if (name.IsNull() || name == ".") { + if (dir) { + name = dir; + if (dir[strlen(dir) - 1] != '/') + name += '/'; + } else name = ""; + return name.Data(); } - return StrDup(buf.Data()); + if (!dir || !dir[0]) dir = "/"; + else if (dir[strlen(dir) - 1] != '/') + name.Prepend('/'); + name.Prepend(dir); + + return name.Data(); } //---- Paths & Files ----------------------------------------------------------- @@ -1524,72 +1520,68 @@ int TUnixSystem::Utime(const char *file, Long_t modtime, Long_t actime) } //______________________________________________________________________________ -char *TUnixSystem::Which(const char *search, const char *wfil, EAccessMode mode) +const char *TUnixSystem::FindFile(const char *search, TString& wfil, EAccessMode mode) { // Find location of file "wfil" in a search path. // The search path is specified as a : separated list of directories. - // User must delete returned string. Returns 0 in case file is not found. + // Return value is pointing to wfile for compatibility with + // Which(const char*,const char*,EAccessMode) version - char name[kMAXPATHLEN], file[kMAXPATHLEN]; - const char *ptr; - char *next, *exname; - struct stat finfo; + if (gEnv->GetValue("Root.ShowPath", 0)) + printf("Which: %s = ", wfil.Data()); - exname = gSystem->ExpandPathName(wfil); - if (exname) - strcpy(file, exname); - else - file[0] = 0; - delete [] exname; + gSystem->ExpandPathName(wfil); - if (file[0] == '/') { - exname = StrDup(file); - if (exname && access(exname, mode) == 0 && - stat(exname, &finfo) == 0 && S_ISREG(finfo.st_mode)) { + if (wfil[0] == '/') { + struct stat finfo; + if (access(wfil.Data(), mode) == 0 && + stat(wfil.Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) { if (gEnv->GetValue("Root.ShowPath", 0)) - Printf("Which: %s = %s", wfil, exname); - return exname; + printf("%s", wfil.Data()); + return wfil.Data(); } - delete [] exname; if (gEnv->GetValue("Root.ShowPath", 0)) - Printf("Which: %s = <not found>", wfil); + printf("<not found>"); + wfil = ""; return 0; } if (search == 0) search = "."; - for (ptr = search; *ptr;) { - for (next = name; *ptr && *ptr != ':'; ) - *next++ = *ptr++; - *next = '\0'; - - if (name[0] != '/' && name[0] != '$' && name[0] != '~') { - char tmp[kMAXPATHLEN]; - strcpy(tmp, name); - strcpy(name, gSystem->WorkingDirectory()); - strcat(name, "/"); - strcat(name, tmp); + TString pwd(gSystem->WorkingDirectory()); + pwd += "/"; + for (const char* ptr = search; *ptr;) { + TString name; + if (*ptr != '/' && *ptr !='$' && *ptr != '~') + name = pwd; + const char* posEndOfPart = strchr(ptr, ':'); + if (posEndOfPart) { + name.Append(ptr, posEndOfPart - ptr); + ptr = posEndOfPart + 1; // skip ':' + } else { + name.Append(ptr); + ptr += strlen(ptr); } - if (*(name + strlen(name) - 1) != '/') - strcat(name, "/"); - strcat(name, file); + if (!name.EndsWith("/")) + name += '/'; + name += wfil; - exname = gSystem->ExpandPathName(name); - if (exname && access(exname, mode) == 0 && - stat(exname, &finfo) == 0 && S_ISREG(finfo.st_mode)) { + gSystem->ExpandPathName(name); + struct stat finfo; + if (access(name.Data(), mode) == 0 && + stat(name.Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) { if (gEnv->GetValue("Root.ShowPath", 0)) - Printf("Which: %s = %s", wfil, exname); - return exname; + printf("%s", name.Data()); + wfil = name; + return wfil.Data(); } - delete [] exname; - if (*ptr) - ptr++; } if (gEnv->GetValue("Root.ShowPath", 0)) - Printf("Which: %s = <not found>", wfil); + printf("<not found>"); + wfil = ""; return 0; } diff --git a/vms/inc/TVmsSystem.h b/vms/inc/TVmsSystem.h index a6caba4f622d122736c0317f697f05e8655c1ade..db4a1a2ae9c803b1bf1e6d5a3bb700107631183c 100644 --- a/vms/inc/TVmsSystem.h +++ b/vms/inc/TVmsSystem.h @@ -1,4 +1,4 @@ -// @(#)root/vms:$Name: $:$Id: TVmsSystem.h,v 1.4 2001/01/23 19:01:55 rdm Exp $ +// @(#)root/vms:$Name: $:$Id: TVmsSystem.h,v 1.5 2001/02/03 14:46:42 rdm Exp $ // Author: Fons Rademakers 15/09/95 /************************************************************************* @@ -126,7 +126,7 @@ public: const char *HomeDirectory(); //---- Paths & Files ---------------------------------------- - char *ConcatFileName(const char *dir, const char *name); + const char *PrependPathName(const char *dir, TString& name); Bool_t ExpandPathName(TString &patbuf); char *ExpandPathName(const char *path); Bool_t AccessPathName(const char *path, EAccessMode mode = kFileExists); @@ -137,7 +137,7 @@ public: int GetPathInfo(const char *path, unsigned short *id,Long_t *size, Long_t *flags, Long_t *modtime); int Umask(Int_t mask); - char *Which(const char *search, const char *file, EAccessMode mode = kFileExists); + const char *FindFile(const char *search, TString& file, EAccessMode mode = kFileExists); //---- System Logging --------------------------------------- void Openlog(const char *name, Int_t options, ELogFacility facility); diff --git a/vms/src/TVmsSystem.cxx b/vms/src/TVmsSystem.cxx index 0b22eecfb52b21ce4936bbaae64949817922929e..3e2d0f0a246bcc6aea25617ca0dae0ea20d9c0c4 100644 --- a/vms/src/TVmsSystem.cxx +++ b/vms/src/TVmsSystem.cxx @@ -1,4 +1,4 @@ -// @(#)root/vms:$Name: $:$Id: TVmsSystem.cxx,v 1.10 2001/11/26 15:37:46 rdm Exp $ +// @(#)root/vms:$Name: $:$Id: TVmsSystem.cxx,v 1.11 2002/11/18 23:02:19 rdm Exp $ // Author: Fons Rademakers 15/09/95 /************************************************************************* @@ -534,24 +534,20 @@ const char *TVmsSystem::HomeDirectory() } //______________________________________________________________________________ -char *TVmsSystem::ConcatFileName(const char *dir, const char *name) +const char *TVmsSystem::PrependPathName(const char *dir, TString& name) { - // Concatenate a directory and a file name. Returned string must be - // deleted by user. + // Concatenate a directory and a file name. - if (name == 0 || strlen(name) <= 0 || strcmp(name, ".") == 0) - return StrDup(dir); + if (name.IsNull() || name == ".") { + if (dir) name = dir; + else name = ""; + return name.Data(); - char buf[kMAXPATHLEN]; - if (dir && (strcmp(dir, "/") != 0)) { - if (dir[strlen(dir)-1] == '/') - sprintf(buf, "%s%s", dir, name); - else - sprintf(buf, "%s/%s", dir, name); - } else - sprintf(buf, "/%s", name); + if (dir && dir[0] && dir[strlen(dir) - 1] != '/') + name.Prepend("/"); + name.Prepend(dir); - return StrDup(buf); + return name.Data(); } //---- Paths & Files ----------------------------------------------------------- @@ -750,7 +746,7 @@ int TVmsSystem::Umask(Int_t mask) } //______________________________________________________________________________ -char *TVmsSystem::Which(const char *search, const char *file, EAccessMode mode) +const char *TVmsSystem::FindFile(const char *search, TString& file, EAccessMode mode) { // Find location of file in a search path. // User must delete returned string. @@ -759,35 +755,39 @@ char *TVmsSystem::Which(const char *search, const char *file, EAccessMode mode) const char *ptr; char *next, *exname, *ffile; char s2[]=":"; + Ssiz_t posCol = 0; + + if (gEnv->GetValue("Root.ShowPath",0)) + printf("Which: %s = ", file.Data()); + + if (search != 0){ + if (strchr(file(),']')) { + if (gEnv->GetValue("Root.ShowPath",0)) + printf("%s\n", file.Data()); + return file.Data(); + } else if ((posCol = file.First(':')) != kNPOS) { + file.Remove(0, posCol + 1); + if (gEnv->GetValue("Root.ShowPath",0)) + printf("%s\n", file.Data()); + return file.Data(); + } else { + if (file.IsNull()) { + file = search; + if (gEnv->GetValue("Root.ShowPath",0)) + printf("%s\n", file.Data()); + return file.Data(); + } + file.Prepend(search); + if (access(file(),mode) == 0) { + if (gEnv->GetValue("Root.ShowPath",0)) + printf("%s\n", file.Data()); + return file.Data(); + } + } + } -ffile = StrDup(file); - -if (search != 0){ - if (strchr(file,']')){ - exname = StrDup(file); - return exname; - } - else if(strrchr(file,':')){ - exname = StrDup(strtok(ffile,s2)); - return exname; - } - else { - if (file == 0){ - exname = StrDup(search); - return exname; - } - strcpy(temp,search); - strcat(temp,file); - exname = StrDup(temp); - if (exname && access(exname,mode) == 0) { - if (gEnv->GetValue("Root.ShowPath",0)) - Printf("Which: %s = %s", file,exname); - return exname; - } - delete [] exname; + file = ""; return 0; - } -} #if 0 if (strchr(file, '/')) { diff --git a/winnt/inc/TWinNTSystem.h b/winnt/inc/TWinNTSystem.h index e88d7302d46baf9e9c749cd2fc26af2af5e607c9..3cbfb2afb8ec8128c2e0c92a2e4f03663aa76468 100644 --- a/winnt/inc/TWinNTSystem.h +++ b/winnt/inc/TWinNTSystem.h @@ -1,4 +1,4 @@ -// @(#)root/winnt:$Name: $:$Id: TWinNTSystem.h,v 1.39 2006/03/28 16:35:00 brun Exp $ +// @(#)root/winnt:$Name: $:$Id: TWinNTSystem.h,v 1.40 2006/05/15 16:30:10 brun Exp $ // Author: Fons Rademakers 15/09/95 /************************************************************************* @@ -165,7 +165,6 @@ public: const char *WorkingDirectory(char driveletter); const char *WorkingDirectory(); const char *HomeDirectory(const char *userName=0); - char *ConcatFileName(const char *dir, const char *name); const char *TempDirectory() const; FILE *TempFileName(TString &base, const char *dir = 0); @@ -181,6 +180,7 @@ public: //---- Paths & Files ---------------------------------------- const char DriveName(const char *pathname="/"); + const char *PrependPathName(const char *dir, TString& name); Bool_t ExpandPathName(TString &patbuf); char *ExpandPathName(const char *path); Bool_t AccessPathName(const char *path, EAccessMode mode = kFileExists); @@ -197,7 +197,7 @@ public: int Umask(Int_t mask); int Utime(const char *file, Long_t modtime, Long_t actime); const char *UnixPathName(const char *unixpathname); - char *Which(const char *search, const char *file, EAccessMode mode = kFileExists); + const char *FindFile(const char *search, TString& file, EAccessMode mode = kFileExists); //---- Standard Output redirection -------------------------- Int_t RedirectOutput(const char *name, const char *mode = "a"); diff --git a/winnt/src/TWinNTSystem.cxx b/winnt/src/TWinNTSystem.cxx index 7dbb5a231fac5f59f9b7fdabf4eff4d23564663e..93e90f26af185fab7dd264300da89fe50e3f88e5 100644 --- a/winnt/src/TWinNTSystem.cxx +++ b/winnt/src/TWinNTSystem.cxx @@ -1,4 +1,4 @@ -// @(#)root/winnt:$Name: $:$Id: TWinNTSystem.cxx,v 1.141 2006/05/18 10:46:26 brun Exp $ +// @(#)root/winnt:$Name: $:$Id: TWinNTSystem.cxx,v 1.142 2006/05/21 18:17:24 brun Exp $ // Author: Fons Rademakers 15/09/95 /************************************************************************* @@ -2078,30 +2078,20 @@ Bool_t TWinNTSystem::AccessPathName(const char *path, EAccessMode mode) } //______________________________________________________________________________ -char *TWinNTSystem::ConcatFileName(const char *dir, const char *name) +const char *TWinNTSystem::PrependPathName(const char *dir, TString& name) { - // Concatenate a directory and a file name. Returned string must be - // deleted by user. + // Concatenate a directory and a file name. - Int_t ldir = dir ? strlen(dir) : 0; - Int_t lname = name ? strlen(name) : 0; - - if (!lname) return StrDup(dir); - - char *buf = new char[ldir+lname+2]; - - if (ldir) { + if (name == ".") name = ""; + if (dir && dir[0]) { // Test whether the last symbol of the directory is a separator - char last = dir[ldir-1]; - if (last == '/' || last == '\\' || last == ':') { - sprintf(buf, "%s%s", dir, name); - } else { - sprintf(buf, "%s\\%s", dir, name); + char last = dir[strlen(dir) - 1]; + if (last != '/' && last == '\\') { + name.Prepend('\\'); } - } else { - sprintf(buf, "\\%s", name); + name.Prepend(dir); } - return buf; + return name.Data(); } //______________________________________________________________________________ @@ -2422,59 +2412,56 @@ int TWinNTSystem::Utime(const char *file, Long_t modtime, Long_t actime) } //______________________________________________________________________________ -char *TWinNTSystem::Which(const char *search, const char *infile, EAccessMode mode) +const char *TWinNTSystem::FindFile(const char *search, TString& infile, EAccessMode mode) { // Find location of file in a search path. // User must delete returned string. Returns 0 in case file is not found. - static char name[kMAXPATHLEN]; - char *lpFilePart = 0; - char *found = 0; - // Windows cannot check on execution mode - all we can do is kReadPermission if (mode==kExecutePermission) mode=kReadPermission; // Expand parameters - char *exinfile = gSystem->ExpandPathName(infile); + gSystem->ExpandPathName(infile); // Check whether this infile has the absolute path first - if (IsAbsoluteFileName(exinfile) ) { - found = exinfile; - } else { - char *tmp = gSystem->ExpandPathName(search); - TString exsearch(tmp); - delete [] tmp; - - // Need to use Windows delimiters - Int_t lastDelim = -1; - for(int i=0; i<exsearch.Length(); ++i) { - switch( exsearch[i] ) { - case ':': if (i-lastDelim!=2) exsearch[i] = ';'; // Replace the ':' unless there are after a disk suffix (aka ;c:\mydirec...) - lastDelim = i; - break; - case ';': lastDelim = i; break; - } - } - - // Check access - struct stat finfo; - if (::SearchPath(exsearch, exinfile, NULL, kMAXPATHLEN, name, &lpFilePart) && - ::access(name, mode) == 0 && stat(name, &finfo) == 0 && - finfo.st_mode & S_IFREG) { - if (gEnv->GetValue("Root.ShowPath", 0)) { - Printf("Which: %s = %s", infile, name); - } - found = StrDup(name); + if (IsAbsoluteFileName(infile.Data()) ) { + if (!AccessPathName(infile.Data(), mode)) + return infile.Data(); + infile = ""; + return 0; + } + TString exsearch(search); + gSystem->ExpandPathName(exsearch); + + // Need to use Windows delimiters + Int_t lastDelim = -1; + for(int i=0; exsearch[i]; ++i) { + switch( exsearch[i] ) { + case ':': + // Replace the ':' unless there are after a disk suffix (aka ;c:\mydirec...) + if (i-lastDelim!=2) exsearch[i] = ';'; + lastDelim = i; + break; + case ';': lastDelim = i; break; } - delete [] exinfile; } - if (found && AccessPathName(found, mode)) { - delete [] found; - found = 0; + // Check access + struct stat finfo; + char name[kMAXPATHLEN]; + char *lpFilePart = 0; + if (::SearchPath(exsearch.Data(), infile.Data(), NULL, kMAXPATHLEN, name, &lpFilePart) && + ::access(name, mode) == 0 && stat(name, &finfo) == 0 && + finfo.st_mode & S_IFREG) { + if (gEnv->GetValue("Root.ShowPath", 0)) { + Printf("Which: %s = %s", infile, name); + } + infile = name; + return infile.Data(); } - return found; + infile = ""; + return 0; } //---- Users & Groups ----------------------------------------------------------