Path_WIN32.cpp
Go to the documentation of this file.
00001 //
00002 // Path_WIN32.cpp
00003 //
00004 // $Id: //poco/1.3/Foundation/src/Path_WIN32.cpp#3 $
00005 //
00006 // Library: Foundation
00007 // Package: Filesystem
00008 // Module:  Path
00009 //
00010 // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
00011 // and Contributors.
00012 //
00013 // Permission is hereby granted, free of charge, to any person or organization
00014 // obtaining a copy of the software and accompanying documentation covered by
00015 // this license (the "Software") to use, reproduce, display, distribute,
00016 // execute, and transmit the Software, and to prepare derivative works of the
00017 // Software, and to permit third-parties to whom the Software is furnished to
00018 // do so, all subject to the following:
00019 // 
00020 // The copyright notices in the Software and this entire statement, including
00021 // the above license grant, this restriction and the following disclaimer,
00022 // must be included in all copies of the Software, in whole or in part, and
00023 // all derivative works of the Software, unless such copies or derivative
00024 // works are solely in the form of machine-executable object code generated by
00025 // a source language processor.
00026 // 
00027 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00028 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00029 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
00030 // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
00031 // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
00032 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00033 // DEALINGS IN THE SOFTWARE.
00034 //
00035 
00036 
00037 #include "Poco/Path_WIN32.h"
00038 #include "Poco/Environment_WIN32.h"
00039 #include "Poco/UnWindows.h"
00040 
00041 
00042 namespace Poco {
00043 
00044 
00045 std::string PathImpl::currentImpl()
00046 {
00047         char buffer[_MAX_PATH];
00048         DWORD n = GetCurrentDirectoryA(sizeof(buffer), buffer);
00049         if (n > 0 && n < sizeof(buffer))
00050         {
00051                 std::string result(buffer, n);
00052                 if (result[n - 1] != '\\')
00053                         result.append("\\");
00054                 return result;
00055         }
00056         else throw SystemException("Cannot get current directory");
00057 }
00058 
00059 
00060 std::string PathImpl::homeImpl()
00061 {
00062         std::string result = EnvironmentImpl::getImpl("HOMEDRIVE");
00063         result.append(EnvironmentImpl::getImpl("HOMEPATH"));
00064         std::string::size_type n = result.size();
00065         if (n > 0 && result[n - 1] != '\\')
00066                 result.append("\\");
00067         return result;
00068 }
00069 
00070 
00071 std::string PathImpl::tempImpl()
00072 {
00073         char buffer[_MAX_PATH];
00074         DWORD n = GetTempPathA(sizeof(buffer), buffer);
00075         if (n > 0 && n < sizeof(buffer))
00076         {
00077                 std::string result(buffer, n);
00078                 if (result[n - 1] != '\\')
00079                         result.append("\\");
00080                 return result;
00081         }
00082         else throw SystemException("Cannot get current directory");
00083 }
00084 
00085 
00086 std::string PathImpl::nullImpl()
00087 {
00088         return "NUL:";
00089 }
00090 
00091 
00092 std::string PathImpl::expandImpl(const std::string& path)
00093 {
00094         char buffer[_MAX_PATH];
00095         DWORD n = ExpandEnvironmentStringsA(path.c_str(), buffer, sizeof(buffer));
00096         if (n > 0 && n < sizeof(buffer))
00097                 return std::string(buffer, n - 1);
00098         else
00099                 return path;
00100 }
00101 
00102 
00103 void PathImpl::listRootsImpl(std::vector<std::string>& roots)
00104 {
00105         roots.clear();
00106         char buffer[128];
00107         DWORD n = GetLogicalDriveStrings(sizeof(buffer) - 1, buffer);
00108         char* it = buffer;
00109         char* end = buffer + (n > sizeof(buffer) ? sizeof(buffer) : n);
00110         while (it < end)
00111         {
00112                 std::string dev;
00113                 while (it < end && *it) dev += *it++;
00114                 roots.push_back(dev);
00115                 ++it;
00116         }
00117 }
00118 
00119 
00120 } // namespace Poco


pluginlib
Author(s): Tully Foote and Eitan Marder-Eppstein
autogenerated on Sat Dec 28 2013 17:20:19