diff options
author | Roman Divacky <rdivacky@FreeBSD.org> | 2009-12-01 11:07:05 +0000 |
---|---|---|
committer | Roman Divacky <rdivacky@FreeBSD.org> | 2009-12-01 11:07:05 +0000 |
commit | 06f9d4012fb8acea3e9861d5722b5965dbb724d9 (patch) | |
tree | ffe0478472eaa0686f11cb02c6df7d257b8719b0 /lib/System/Unix/Path.inc | |
parent | 76e2e0ebfdd3d91b07a75822865ea3e9121a99ce (diff) |
Notes
Diffstat (limited to 'lib/System/Unix/Path.inc')
-rw-r--r-- | lib/System/Unix/Path.inc | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc index 89285b48132f9..ff1497a5c6df9 100644 --- a/lib/System/Unix/Path.inc +++ b/lib/System/Unix/Path.inc @@ -335,7 +335,7 @@ getprogpath(char ret[PATH_MAX], const char *bin) free(pv); return (NULL); } -#endif +#endif // __FreeBSD__ /// GetMainExecutable - Return the path to the main executable, given the /// value of argv[0] from program startup. @@ -348,7 +348,8 @@ Path Path::GetMainExecutable(const char *argv0, void *MainAddr) { uint32_t size = sizeof(exe_path); if (_NSGetExecutablePath(exe_path, &size) == 0) { char link_path[MAXPATHLEN]; - return Path(std::string(realpath(exe_path, link_path))); + if (realpath(exe_path, link_path)) + return Path(std::string(link_path)); } #elif defined(__FreeBSD__) char exe_path[PATH_MAX]; @@ -370,7 +371,8 @@ Path Path::GetMainExecutable(const char *argv0, void *MainAddr) { // If the filename is a symlink, we need to resolve and return the location of // the actual executable. char link_path[MAXPATHLEN]; - return Path(std::string(realpath(DLInfo.dli_fname, link_path))); + if (realpath(DLInfo.dli_fname, link_path)) + return Path(std::string(link_path)); #endif return Path(); } @@ -454,6 +456,20 @@ Path::canWrite() const { } bool +Path::isRegularFile() const { + // Get the status so we can determine if its a file or directory + struct stat buf; + + if (0 != stat(path.c_str(), &buf)) + return false; + + if (S_ISREG(buf.st_mode)) + return true; + + return false; +} + +bool Path::canExecute() const { if (0 != access(path.c_str(), R_OK | X_OK )) return false; @@ -723,7 +739,7 @@ Path::createTemporaryFileOnDisk(bool reuse_current, std::string* ErrMsg) { bool Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const { - // Get the status so we can determin if its a file or directory + // Get the status so we can determine if its a file or directory struct stat buf; if (0 != stat(path.c_str(), &buf)) { MakeErrMsg(ErrStr, path + ": can't get status of file"); |