diff options
author | Mark Spruiell <mes@zeroc.com> | 2006-04-19 23:52:09 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2006-04-19 23:52:09 +0000 |
commit | 6130cbddb8d92c3becd578e8be26da7cd8e76891 (patch) | |
tree | c2c6451987ce4d251d948bf4d0e7e6cd96674a7a /cpp/src/IceSSL/Util.cpp | |
parent | minor fix (diff) | |
download | ice-6130cbddb8d92c3becd578e8be26da7cd8e76891.tar.bz2 ice-6130cbddb8d92c3becd578e8be26da7cd8e76891.tar.xz ice-6130cbddb8d92c3becd578e8be26da7cd8e76891.zip |
moving checkPath so that PluginI can use it for IceSSL.Random
Diffstat (limited to 'cpp/src/IceSSL/Util.cpp')
-rw-r--r-- | cpp/src/IceSSL/Util.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/cpp/src/IceSSL/Util.cpp b/cpp/src/IceSSL/Util.cpp index 854481dbd3d..73f6c2c6bdc 100644 --- a/cpp/src/IceSSL/Util.cpp +++ b/cpp/src/IceSSL/Util.cpp @@ -10,6 +10,16 @@ #include <Util.h> #include <Ice/LocalException.h> +#ifdef _WIN32 +# include <direct.h> +# include <sys/types.h> +# include <sys/stat.h> +# define S_ISDIR(mode) ((mode) & _S_IFDIR) +# define S_ISREG(mode) ((mode) & _S_IFREG) +#else +# include <sys/stat.h> +#endif + #include <IceUtil/DisableWarnings.h> using namespace std; @@ -377,3 +387,43 @@ IceSSL::splitString(const string& str, const string& delim, bool handleQuotes, v return true; } + +bool +IceSSL::checkPath(string& path, const string& defaultDir, bool dir) +{ + // + // Check if file exists. If not, try prepending the default + // directory and check again. If the file is found, the + // string argument is modified and true is returned. Otherwise + // false is returned. + // +#ifdef _WIN32 + struct _stat st; + int err = ::_stat(path.c_str(), &st); +#else + struct stat st; + int err = ::stat(path.c_str(), &st); +#endif + if(err == 0) + { + return dir ? S_ISDIR(st.st_mode) != 0 : S_ISREG(st.st_mode) != 0; + } + + if(!defaultDir.empty()) + { +#ifdef _WIN32 + string s = defaultDir + "\\" + path; + err = ::_stat(s.c_str(), &st); +#else + string s = defaultDir + "/" + path; + err = ::stat(s.c_str(), &st); +#endif + if(err == 0 && ((!dir && S_ISREG(st.st_mode)) || (dir && S_ISDIR(st.st_mode)))) + { + path = s; + return true; + } + } + + return false; +} |