diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-03-29 16:43:20 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-03-29 16:43:20 +0000 |
commit | 69cce815e7414ad9a186920c78890c852986d6bf (patch) | |
tree | 1e40f9377343d63797382c56cda19544249b599f /lib/System/Unix | |
parent | 585e0882c38516b52e67eb0b22c91c72c10ce9a4 (diff) | |
download | external_llvm-69cce815e7414ad9a186920c78890c852986d6bf.zip external_llvm-69cce815e7414ad9a186920c78890c852986d6bf.tar.gz external_llvm-69cce815e7414ad9a186920c78890c852986d6bf.tar.bz2 |
For PR789:
* Add a method: bool isAbsolute() const, which determines if the path name
is absolute or not.
* Implement caching of file status information in the Path object. Allow it
to be updated forcefully or lazily re-fetched from the cached value.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35456 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Unix')
-rw-r--r-- | lib/System/Unix/Path.inc | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc index 9802b7e..b155213 100644 --- a/lib/System/Unix/Path.inc +++ b/lib/System/Unix/Path.inc @@ -79,6 +79,12 @@ Path::isValid() const { return i >= len; } +bool +Path::isAbsolute() const { + if (path.empty()) + return false; + return path[0] == '/'; +} Path Path::GetRootDirectory() { Path result; @@ -357,18 +363,22 @@ Path::getLast() const { } bool -Path::getFileStatus(FileStatus &info, std::string *ErrStr) const { - struct stat buf; - if (0 != stat(path.c_str(), &buf)) - return MakeErrMsg(ErrStr, - path + ": can't get status of file '" + path + "'"); - info.fileSize = buf.st_size; - info.modTime.fromEpochTime(buf.st_mtime); - info.mode = buf.st_mode; - info.user = buf.st_uid; - info.group = buf.st_gid; - info.isDir = S_ISDIR(buf.st_mode); - info.isFile = S_ISREG(buf.st_mode); +Path::getFileStatus(FileStatus &info, bool update, std::string *ErrStr) const { + if (status == 0 || update) { + struct stat buf; + if (0 != stat(path.c_str(), &buf)) + return MakeErrMsg(ErrStr, path + ": can't get status of file"); + if (status == 0) + status = new FileStatus; + status->fileSize = buf.st_size; + status->modTime.fromEpochTime(buf.st_mtime); + status->mode = buf.st_mode; + status->user = buf.st_uid; + status->group = buf.st_gid; + status->isDir = S_ISDIR(buf.st_mode); + status->isFile = S_ISREG(buf.st_mode); + } + info = *status; return false; } |