summaryrefslogtreecommitdiff
path: root/lib/System
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2005-07-08 06:53:26 +0000
committerReid Spencer <rspencer@reidspencer.com>2005-07-08 06:53:26 +0000
commit6371ccbd8d3838bdc7ca4f2cc9c807e84ecc93a8 (patch)
treed835682bf63762b5db55d2a2c91baa1446fbf995 /lib/System
parent4c47e3a1c598a2d9c4f0a52c611379fcd08cc6ab (diff)
downloadllvm-6371ccbd8d3838bdc7ca4f2cc9c807e84ecc93a8.tar.gz
llvm-6371ccbd8d3838bdc7ca4f2cc9c807e84ecc93a8.tar.bz2
llvm-6371ccbd8d3838bdc7ca4f2cc9c807e84ecc93a8.tar.xz
Two changes:
1. Use isValid() to check validity of the resulting path name in the eraseSuffix even though we can't think of a case where eraseSuffix could possibly cause an invalid path name. 2. Rewrite isValid() to not use the deprecated realpath function any more. It now just uses isascii to make sure all the characters are legit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22359 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System')
-rw-r--r--lib/System/Unix/Path.inc18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc
index 400318b0eb..ffa1d174fd 100644
--- a/lib/System/Unix/Path.inc
+++ b/lib/System/Unix/Path.inc
@@ -68,17 +68,18 @@ Path::Path(const std::string& unverified_path) : path(unverified_path) {
bool
Path::isValid() const {
+ // Check some obvious things
if (path.empty())
return false;
else if (path.length() >= MAXPATHLEN)
return false;
-#if defined(HAVE_REALPATH)
- char pathname[MAXPATHLEN];
- if (0 == realpath(path.c_str(), pathname))
- if (errno != EACCES && errno != EIO && errno != ENOENT && errno != ENOTDIR)
- return false;
-#endif
- return true;
+
+ // Check that the characters are ascii chars
+ size_t len = path.length();
+ unsigned i = 0;
+ while (i < len && isascii(path[i]))
+ ++i;
+ return i >= len;
}
Path
@@ -504,6 +505,7 @@ Path::appendSuffix(const std::string& suffix) {
bool
Path::eraseSuffix() {
+ std::string save = path;
size_t dotpos = path.rfind('.',path.size());
size_t slashpos = path.rfind('/',path.size());
if (dotpos != std::string::npos) {
@@ -512,6 +514,8 @@ Path::eraseSuffix() {
return true;
}
}
+ if (!isValid())
+ path = save;
return false;
}