diff options
author | Evan Martin <martine@danga.com> | 2012-01-09 21:40:06 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2012-01-09 21:40:06 (GMT) |
commit | a5a97d2983c2e13b31acf8147a4cfbd634deda39 (patch) | |
tree | f898fad6b2016878746810492508548c774cae71 /src | |
parent | 5aa69297e47109bd5d2cc8db6907af56ff100d6d (diff) | |
download | Ninja-a5a97d2983c2e13b31acf8147a4cfbd634deda39.zip Ninja-a5a97d2983c2e13b31acf8147a4cfbd634deda39.tar.gz Ninja-a5a97d2983c2e13b31acf8147a4cfbd634deda39.tar.bz2 |
split canonicalize
Diffstat (limited to 'src')
-rw-r--r-- | src/util.cc | 17 | ||||
-rw-r--r-- | src/util.h | 2 |
2 files changed, 14 insertions, 5 deletions
diff --git a/src/util.cc b/src/util.cc index c5712e0..22bb81f 100644 --- a/src/util.cc +++ b/src/util.cc @@ -77,11 +77,18 @@ void Error(const char* msg, ...) { } bool CanonicalizePath(string* path, string* err) { + int len = path->size(); + if (!CanonicalizePath(&(*path)[0], &len, err)) + return false; + path->resize(len); + return true; +} + +bool CanonicalizePath(char* path, int* len, string* err) { // WARNING: this function is performance-critical; please benchmark // any changes you make to it. METRIC_RECORD("canonicalize path"); - - if (path->empty()) { + if (*len == 0) { *err = "empty path"; return false; } @@ -90,10 +97,10 @@ bool CanonicalizePath(string* path, string* err) { char* components[kMaxPathComponents]; int component_count = 0; - char* start = &(*path)[0]; + char* start = path; char* dst = start; const char* src = start; - const char* end = start + path->size(); + const char* end = start + *len; if (*src == '/') { ++src; @@ -137,7 +144,7 @@ bool CanonicalizePath(string* path, string* err) { src = sep + 1; } - path->resize(dst - path->c_str() - 1); + *len = dst - start - 1; return true; } @@ -40,6 +40,8 @@ void Error(const char* msg, ...); /// Canonicalize a path like "foo/../bar.h" into just "bar.h". bool CanonicalizePath(string* path, string* err); +bool CanonicalizePath(char* path, int* len, string* err); + /// Create a directory (mode 0777 on Unix). /// Portability abstraction. int MakeDir(const string& path); |