diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2008-06-06 12:46:58 -0230 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2008-06-06 17:54:49 +0200 |
commit | a9169f12e8417b91a7dcfea3b678d09ed2697b62 (patch) | |
tree | 2e072cc1d8319a7ce213590e9e15c719f5b29ab9 /cpp/src/IceUtil/FileUtil.cpp | |
parent | - Fixed bug 3242 (diff) | |
download | ice-a9169f12e8417b91a7dcfea3b678d09ed2697b62.tar.bz2 ice-a9169f12e8417b91a7dcfea3b678d09ed2697b62.tar.xz ice-a9169f12e8417b91a7dcfea3b678d09ed2697b62.zip |
Bug 3014 - isAbsolute incorrect
Diffstat (limited to 'cpp/src/IceUtil/FileUtil.cpp')
-rw-r--r-- | cpp/src/IceUtil/FileUtil.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/cpp/src/IceUtil/FileUtil.cpp b/cpp/src/IceUtil/FileUtil.cpp new file mode 100644 index 00000000000..c387115fee1 --- /dev/null +++ b/cpp/src/IceUtil/FileUtil.cpp @@ -0,0 +1,53 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <IceUtil/FileUtil.h> + +using namespace std; + +// +// Detemine if path is an absolute path +// +bool +IceUtilInternal::isAbsolutePath(const string& path) +{ + size_t i = 0; + size_t size = path.size(); + + // Skip whitespace + while(i < size && isspace(path[i])) + { + ++i; + } + +#ifdef _WIN32 + // We need at least 3 non whitespace character to have + // and absolute path + if(i + 3 > size) + { + return false; + } + + // Check for X:\ path ('\' may have been converted to '/') + if((path[i] >= 'A' && path[i] <= 'Z') || (path[i] >= 'a' && path[i] <= 'z')) + { + return path[i + 1] == ':' && (path[i + 2] == '\\' || path[i + 2] == '/'); + } + + // Check for UNC path + return (path[i] == '\\' && path[i + 1] == '\\') || path[i] == '/'; +#else + if(i >= size) + { + return false; + } + + return path[i] == '/'; +#endif +} |