/// @brief Determines if the path name references a directory.
bool isDirectory() const;
+ /// This function determines if the path refers to a hidden file. The
+ /// notion of hidden files is defined by the underlying system. The
+ /// system may not support hidden files in which case this function always
+ /// returns false on such systems. Hidden files have the "hidden"
+ /// attribute set on Win32. On Unix, hidden files start with a period.
+ /// @brief Determines if the path name references a hidden file.
+ bool isHidden() const;
+
/// This function determines if the path name in this object references
/// the root (top level directory) of the file system. The details of what
/// is considered the "root" may vary from system to system so this method
/// @returns true if the pathname references a readable file.
/// @brief Determines if the path is a readable file or directory
/// in the file system.
- bool readable() const;
+ bool canRead() const;
/// This function determines if the path name references a writable file
/// or directory in the file system. Unlike isFile and isDirectory, this
/// @returns true if the pathname references a writable file.
/// @brief Determines if the path is a writable file or directory
/// in the file system.
- bool writable() const;
+ bool canWrite() const;
/// This function determines if the path name references an executable
/// file in the file system. Unlike isFile and isDirectory, this
/// @returns true if the pathname references an executable file.
/// @brief Determines if the path is an executable file in the file
/// system.
- bool executable() const;
+ bool canExecute() const;
/// This function returns the current contents of the path as a
/// std::string. This allows the underlying path string to be manipulated
if (!Directory.empty())
tmpPath.setDirectory(Directory);
tmpPath.appendFile(BaseName);
- if (tmpPath.readable())
+ if (tmpPath.canRead())
SourceText = new SourceFile(tmpPath.toString(), Descriptor);
else
SourceText = new SourceFile(BaseName, Descriptor);
///
bool Linker::LinkInFile(const sys::Path &File) {
// Make sure we can at least read the file
- if (!File.readable())
+ if (!File.canRead())
return error("Cannot find linker input '" + File.toString() + "'");
// A user may specify an ar archive without -l, perhaps because it
{
// Determine if the pathname can be found as it stands.
sys::Path FilePath(Filename);
- if (FilePath.readable() &&
+ if (FilePath.canRead() &&
(FilePath.isArchive() || FilePath.isDynamicLibrary()))
return FilePath;
Result.elideFile();
if (!Result.isEmpty()) {
Result.appendFile(ExeName);
- if (Result.executable())
+ if (Result.canExecute())
return Result;
}
bool
Path::isArchive() const {
- if (readable())
+ if (canRead())
return hasMagicNumber("!<arch>\012");
return false;
}
bool
Path::isDynamicLibrary() const {
- if (readable())
+ if (canRead())
return hasMagicNumber("\177ELF");
return false;
}
while( delim != 0 ) {
std::string tmp(at, size_t(delim-at));
if (tmpPath.setDirectory(tmp))
- if (tmpPath.readable())
+ if (tmpPath.canRead())
Paths.push_back(tmpPath);
at = delim + 1;
delim = strchr(at, ':');
}
if (*at != 0)
if (tmpPath.setDirectory(std::string(at)))
- if (tmpPath.readable())
+ if (tmpPath.canRead())
Paths.push_back(tmpPath);
}
{
Path tmpPath;
if (tmpPath.setDirectory(LLVM_LIBDIR))
- if (tmpPath.readable())
+ if (tmpPath.canRead())
Paths.push_back(tmpPath);
}
#endif
}
bool
-Path::readable() const {
+Path::canRead() const {
return 0 == access(path.c_str(), F_OK | R_OK );
}
bool
-Path::writable() const {
+Path::canWrite() const {
return 0 == access(path.c_str(), F_OK | W_OK );
}
bool
-Path::executable() const {
+Path::canExecute() const {
struct stat st;
int r = stat(path.c_str(), &st);
if (r != 0 || !S_ISREG(st.st_mode))
return Path();
// FIXME: have to check for absolute filename - we cannot assume anything
// about "." being in $PATH
- if (temp.executable()) // already executable as is
+ if (temp.canExecute()) // already executable as is
return temp;
// At this point, the file name is valid and its not executable
Path FilePath;
if (FilePath.setDirectory(std::string(PathStr,Colon))) {
FilePath.appendFile(progName);
- if (FilePath.executable())
+ if (FilePath.canExecute())
return FilePath; // Found the executable!
}
const Path** redirects,
unsigned secondsToWait
) {
- if (!path.executable())
+ if (!path.canExecute())
throw path.toString() + " is not executable";
#ifdef HAVE_SYS_WAIT_H
while( delim != 0 ) {
std::string tmp(at, size_t(delim-at));
if (tmpPath.setDirectory(tmp))
- if (tmpPath.readable())
+ if (tmpPath.canRead())
Paths.push_back(tmpPath);
at = delim + 1;
delim = strchr(at, ';');
}
if (*at != 0)
if (tmpPath.setDirectory(std::string(at)))
- if (tmpPath.readable())
+ if (tmpPath.canRead())
Paths.push_back(tmpPath);
}
{
Path tmpPath;
if (tmpPath.setDirectory(LLVM_LIBDIR))
- if (tmpPath.readable())
+ if (tmpPath.canRead())
Paths.push_back(tmpPath);
}
#endif
}
bool
-Path::readable() const {
+Path::canRead() const {
// FIXME: take security attributes into account.
DWORD attr = GetFileAttributes(path.c_str());
return attr != INVALID_FILE_ATTRIBUTES;
}
bool
-Path::writable() const {
+Path::canWrite() const {
// FIXME: take security attributes into account.
DWORD attr = GetFileAttributes(path.c_str());
return (attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_READONLY);
}
bool
-Path::executable() const {
+Path::canExecute() const {
// FIXME: take security attributes into account.
DWORD attr = GetFileAttributes(path.c_str());
return attr != INVALID_FILE_ATTRIBUTES;
void DumpSymbolNamesFromFile (std::string &Filename) {
std::string ErrorMessage;
sys::Path aPath(Filename);
- if (Filename != "-" && !aPath.readable()) {
+ if (Filename != "-" && !aPath.canRead()) {
std::cerr << ToolName << ": " << Filename << ": " << strerror (errno)
<< "\n";
return;
void cleanup() {
if (!isSet(KEEP_TEMPS_FLAG)) {
- if (TempDir.isDirectory() && TempDir.writable())
+ if (TempDir.isDirectory() && TempDir.canWrite())
TempDir.destroyDirectory(/*remove_contents=*/true);
} else {
std::cout << "Temporary files are in " << TempDir << "\n";
if (progpath.isEmpty())
throw std::string("Can't find program '" +
action->program.toString()+"'");
- else if (progpath.executable())
+ else if (progpath.canExecute())
action->program = progpath;
else
throw std::string("Program '"+action->program.toString()+
bool native = false) {
sys::Path fullpath;
fullpath.setFile(link_item);
- if (fullpath.readable())
+ if (fullpath.canRead())
return fullpath;
for (PathVector::iterator PI = LibraryPaths.begin(),
PE = LibraryPaths.end(); PI != PE; ++PI) {
fullpath.setDirectory(PI->toString());
fullpath.appendFile(link_item);
- if (fullpath.readable())
+ if (fullpath.canRead())
return fullpath;
if (native) {
fullpath.appendSuffix("a");
} else {
fullpath.appendSuffix("bc");
- if (fullpath.readable())
+ if (fullpath.canRead())
return fullpath;
fullpath.elideSuffix();
fullpath.appendSuffix("o");
- if (fullpath.readable())
+ if (fullpath.canRead())
return fullpath;
fullpath = *PI;
fullpath.appendFile(std::string("lib") + link_item);
fullpath.appendSuffix("a");
- if (fullpath.readable())
+ if (fullpath.canRead())
return fullpath;
fullpath.elideSuffix();
fullpath.appendSuffix("so");
- if (fullpath.readable())
+ if (fullpath.canRead())
return fullpath;
}
}
// First, see if the unadorned file name is not readable. If so,
// we must track down the file in the lib search path.
sys::Path fullpath;
- if (!link_item.readable()) {
+ if (!link_item.canRead()) {
// look for the library using the -L arguments specified
// on the command line.
fullpath = GetPathForLinkageItem(link_item.toString());
if (conf) {
confFile.setDirectory(conf);
confFile.appendFile(ftype);
- if (!confFile.readable())
+ if (!confFile.canRead())
throw std::string("Configuration file for '") + ftype +
"' is not available.";
} else {
confFile.appendDirectory(".llvm");
confFile.appendDirectory("etc");
confFile.appendFile(ftype);
- if (!confFile.readable())
+ if (!confFile.canRead())
confFile.clear();
}
if (confFile.isEmpty()) {
// Okay, try the LLVM installation directory
confFile = sys::Path::GetLLVMConfigDir();
confFile.appendFile(ftype);
- if (!confFile.readable()) {
+ if (!confFile.canRead()) {
// Okay, try the "standard" place
confFile = sys::Path::GetLLVMDefaultConfigDir();
confFile.appendFile(ftype);
- if (!confFile.readable()) {
+ if (!confFile.canRead()) {
throw std::string("Configuration file for '") + ftype +
"' is not available.";
}
} else {
confFile = configDir;
confFile.appendFile(ftype);
- if (!confFile.readable())
+ if (!confFile.canRead())
throw std::string("Configuration file for '") + ftype +
"' is not available.";
}