[llvm-commits] CVS: llvm/lib/System/Unix/Path.inc
Reid Spencer
reid at x10sys.com
Thu Jul 28 09:26:08 PDT 2005
Changes in directory llvm/lib/System/Unix:
Path.inc updated: 1.43 -> 1.44
---
Log message:
Fix a problem in getDirectoryContents where sub-directory names were
appended to a path string that didn't end in a slash, yielding invalid
path names.
Path contribute by Nicholas Riley.
---
Diffs of the changes: (+14 -6)
Path.inc | 20 ++++++++++++++------
1 files changed, 14 insertions(+), 6 deletions(-)
Index: llvm/lib/System/Unix/Path.inc
diff -u llvm/lib/System/Unix/Path.inc:1.43 llvm/lib/System/Unix/Path.inc:1.44
--- llvm/lib/System/Unix/Path.inc:1.43 Sat Jul 9 13:42:02 2005
+++ llvm/lib/System/Unix/Path.inc Thu Jul 28 11:25:57 2005
@@ -53,6 +53,13 @@
# undef HAVE_MKDTEMP
#endif
+namespace {
+inline bool lastIsSlash(const std::string& path) {
+ return !path.empty() && path[path.length() - 1] == '/';
+}
+
+}
+
namespace llvm {
using namespace sys;
@@ -437,11 +444,15 @@
if (direntries == 0)
ThrowErrno(path + ": can't open directory");
+ std::string dirPath = path;
+ if (!lastIsSlash(dirPath))
+ dirPath += '/';
+
result.clear();
struct dirent* de = ::readdir(direntries);
for ( ; de != 0; de = ::readdir(direntries)) {
if (de->d_name[0] != '.') {
- Path aPath(path + (const char*)de->d_name);
+ Path aPath(dirPath + (const char*)de->d_name);
struct stat buf;
if (0 != stat(aPath.path.c_str(), &buf)) {
int stat_errno = errno;
@@ -477,11 +488,8 @@
if (name.empty())
return false;
std::string save(path);
- if (!path.empty()) {
- size_t last = path.size() - 1;
- if (path[last] != '/')
- path += '/';
- }
+ if (!lastIsSlash(path))
+ path += '/';
path += name;
if (!isValid()) {
path = save;
More information about the llvm-commits
mailing list