// ********************************************************************** // // Copyright (c) 2003-2009 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 #include 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(static_cast(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 } // // Detemine if a directory exists. // bool IceUtilInternal::directoryExists(const string& path) { IceUtilInternal::structstat st; if(IceUtilInternal::stat(path, &st) != 0 || !S_ISDIR(st.st_mode)) { return false; } return true; } // // Determine if a regular file exists. // bool IceUtilInternal::fileExists(const string& path) { IceUtilInternal::structstat st; if(IceUtilInternal::stat(path, &st) != 0 || !S_ISREG(st.st_mode)) { return false; } return true; } // // Stat // int IceUtilInternal::stat(const string& path, structstat* buffer) { #ifdef _WIN32 return _wstat(IceUtil::stringToWstring(path).c_str(), buffer); #else return stat(path.c_str(), buffer); #endif }