summaryrefslogtreecommitdiff
path: root/cpp/src/IceUtil/FileUtil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/IceUtil/FileUtil.cpp')
-rw-r--r--cpp/src/IceUtil/FileUtil.cpp53
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
+}