mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-13 01:15:32 +00:00
Ensure that functions like isDirectory don't fail if the file doesn't
exist but just return false instead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22361 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
8f1ac1c631
commit
8b2d1aa37b
@ -231,6 +231,8 @@ Path::GetUserHomeDirectory() {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
Path::isFile() const {
|
Path::isFile() const {
|
||||||
|
if (!exists())
|
||||||
|
return false;
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
if (0 != stat(path.c_str(), &buf)) {
|
if (0 != stat(path.c_str(), &buf)) {
|
||||||
ThrowErrno(path + ": can't determine type of path object: ");
|
ThrowErrno(path + ": can't determine type of path object: ");
|
||||||
@ -240,6 +242,8 @@ Path::isFile() const {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
Path::isDirectory() const {
|
Path::isDirectory() const {
|
||||||
|
if (!exists())
|
||||||
|
return false;
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
if (0 != stat(path.c_str(), &buf)) {
|
if (0 != stat(path.c_str(), &buf)) {
|
||||||
ThrowErrno(path + ": can't determine type of path object: ");
|
ThrowErrno(path + ": can't determine type of path object: ");
|
||||||
@ -249,6 +253,8 @@ Path::isDirectory() const {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
Path::isHidden() const {
|
Path::isHidden() const {
|
||||||
|
if (!exists())
|
||||||
|
return false;
|
||||||
size_t slash = path.rfind('/');
|
size_t slash = path.rfind('/');
|
||||||
return (slash != std::string::npos &&
|
return (slash != std::string::npos &&
|
||||||
slash < path.length()-1 &&
|
slash < path.length()-1 &&
|
||||||
@ -269,6 +275,8 @@ Path::getBasename() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Path::hasMagicNumber(const std::string &Magic) const {
|
bool Path::hasMagicNumber(const std::string &Magic) const {
|
||||||
|
if (!isFile())
|
||||||
|
return false;
|
||||||
size_t len = Magic.size();
|
size_t len = Magic.size();
|
||||||
assert(len < 1024 && "Request for magic string too long");
|
assert(len < 1024 && "Request for magic string too long");
|
||||||
char* buf = (char*) alloca(1 + len);
|
char* buf = (char*) alloca(1 + len);
|
||||||
@ -303,6 +311,8 @@ bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
Path::isBytecodeFile() const {
|
Path::isBytecodeFile() const {
|
||||||
|
if (!isFile())
|
||||||
|
return false;
|
||||||
char buffer[ 4];
|
char buffer[ 4];
|
||||||
buffer[0] = 0;
|
buffer[0] = 0;
|
||||||
int fd = ::open(path.c_str(),O_RDONLY);
|
int fd = ::open(path.c_str(),O_RDONLY);
|
||||||
@ -334,11 +344,13 @@ Path::canWrite() const {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
Path::canExecute() const {
|
Path::canExecute() const {
|
||||||
|
if (0 != access(path.c_str(), R_OK | X_OK ))
|
||||||
|
return false;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int r = stat(path.c_str(), &st);
|
int r = stat(path.c_str(), &st);
|
||||||
if (r != 0 || !S_ISREG(st.st_mode))
|
if (r != 0 || !S_ISREG(st.st_mode))
|
||||||
return false;
|
return false;
|
||||||
return 0 == access(path.c_str(), R_OK | X_OK );
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
|
@ -213,6 +213,8 @@ Path::isFile() const {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
Path::isDirectory() const {
|
Path::isDirectory() const {
|
||||||
|
if (!exists())
|
||||||
|
return false;
|
||||||
WIN32_FILE_ATTRIBUTE_DATA fi;
|
WIN32_FILE_ATTRIBUTE_DATA fi;
|
||||||
if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi))
|
if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi))
|
||||||
ThrowError(std::string(path) + ": Can't get status: ");
|
ThrowError(std::string(path) + ": Can't get status: ");
|
||||||
@ -221,6 +223,8 @@ Path::isDirectory() const {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
Path::isHidden() const {
|
Path::isHidden() const {
|
||||||
|
if (!exists())
|
||||||
|
return false;
|
||||||
WIN32_FILE_ATTRIBUTE_DATA fi;
|
WIN32_FILE_ATTRIBUTE_DATA fi;
|
||||||
if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi))
|
if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi))
|
||||||
ThrowError(std::string(path) + ": Can't get status: ");
|
ThrowError(std::string(path) + ": Can't get status: ");
|
||||||
@ -248,6 +252,8 @@ bool Path::hasMagicNumber(const std::string &Magic) const {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
Path::isBytecodeFile() const {
|
Path::isBytecodeFile() const {
|
||||||
|
if (!isFile())
|
||||||
|
return false;
|
||||||
std::string actualMagic;
|
std::string actualMagic;
|
||||||
if (!getMagicNumber(actualMagic, 4))
|
if (!getMagicNumber(actualMagic, 4))
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user