(file) Return to FileSystem.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/FileSystem.cpp between version 1.24 and 1.38

version 1.24, 2001/05/24 00:48:36 version 1.38, 2002/08/29 00:27:52
Line 1 
Line 1 
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM  // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
   // The Open Group, Tivoli Systems
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a  // Permission is hereby granted, free of charge, to any person obtaining a copy
 // copy of this software and associated documentation files (the "Software"),  // of this software and associated documentation files (the "Software"), to
 // to deal in the Software without restriction, including without limitation  // deal in the Software without restriction, including without limitation the
 // the rights to use, copy, modify, merge, publish, distribute, sublicense,  // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 // and/or sell copies of the Software, and to permit persons to whom the  // sell copies of the Software, and to permit persons to whom the Software is
 // Software is furnished to do so, subject to the following conditions:  // furnished to do so, subject to the following conditions:
 //  //
 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL  // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER  // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 // DEALINGS IN THE SOFTWARE.  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
   // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Mike Brasher (mbrasher@bmc.com) // Author: Mike Brasher (mbrasher@bmc.com)
 // //
 // Modified By: // Modified By:
   //         Ramnath Ravindran(Ramnath.Ravindran@compaq.com)
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
Line 38 
Line 41 
  
 // Clone the path as a C String but discard trailing slash if any: // Clone the path as a C String but discard trailing slash if any:
  
 static char* _clonePath(const String& path)  static CString _clonePath(const String& path)
 { {
     char* p = path.allocateCString();      String clone = path;
  
     if (!*p)      if (clone.size() && clone[clone.size()-1] == '/')
         return p;          clone.remove(clone.size()-1);
  
     char* last = p + path.size() - 1;      return clone.getCString();
   
     if (*last == '/')  
         *last = '\0';  
   
     return p;  
 } }
  
 Boolean FileSystem::exists(const String& path) Boolean FileSystem::exists(const String& path)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      return System::exists(_clonePath(path));
     return System::exists(p.getPointer());  
 } }
  
 Boolean FileSystem::getCurrentDirectory(String& path) Boolean FileSystem::getCurrentDirectory(String& path)
Line 74 
Line 71 
 Boolean FileSystem::existsNoCase(const String& path, String& realPath) Boolean FileSystem::existsNoCase(const String& path, String& realPath)
 { {
     realPath.clear();     realPath.clear();
     ArrayDestroyer<char> destroyer(_clonePath(path));      CString cpath = _clonePath(path);
     char* p = destroyer.getPointer();      const char* p = cpath;
  
     const char* dirPath;     const char* dirPath;
     char* fileName;      const char* fileName;
     char* slash = strrchr(p, '/');     char* slash = strrchr(p, '/');
  
     if (slash)     if (slash)
Line 106 
Line 103 
             else             else
             {             {
                 realPath = dirPath;                 realPath = dirPath;
                 realPath += '/';                  realPath.append('/');
                 realPath += dir.getName();                  realPath.append(dir.getName());
             }             }
             return true;             return true;
         }         }
Line 118 
Line 115 
  
 Boolean FileSystem::canRead(const String& path) Boolean FileSystem::canRead(const String& path)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      return System::canRead(_clonePath(path));
     return System::canRead(p.getPointer());  
 } }
  
 Boolean FileSystem::canWrite(const String& path) Boolean FileSystem::canWrite(const String& path)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      return System::canWrite(_clonePath(path));
     return System::canWrite(p.getPointer());  
 } }
  
 Boolean FileSystem::getFileSize(const String& path, Uint32& size) Boolean FileSystem::getFileSize(const String& path, Uint32& size)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      return System::getFileSize(_clonePath(path), size);
     return System::getFileSize(p.getPointer(), size);  
 } }
  
 Boolean FileSystem::removeFile(const String& path) Boolean FileSystem::removeFile(const String& path)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      return System::removeFile(_clonePath(path));
     return System::removeFile(p.getPointer());  
 } }
  
 void FileSystem::loadFileToMemory( void FileSystem::loadFileToMemory(
Line 149 
Line 142 
     if (!getFileSize(fileName, fileSize))     if (!getFileSize(fileName, fileSize))
         throw CannotOpenFile(fileName);         throw CannotOpenFile(fileName);
  
     char* tmp = fileName.allocateCString();      FILE* fp = fopen(fileName.getCString(), "rb");
     FILE* fp = fopen(tmp, "rb");  
     delete [] tmp;  
  
     if (fp == NULL)     if (fp == NULL)
         throw CannotOpenFile(fileName);         throw CannotOpenFile(fileName);
  
     array.reserve(fileSize);      array.reserveCapacity(fileSize);
     char buffer[4096];     char buffer[4096];
     size_t n;     size_t n;
  
Line 183 
Line 174 
     if (fileSize1 != fileSize2)     if (fileSize1 != fileSize2)
         return false;         return false;
  
     char* tmp1 = path1.allocateCString();      FILE* fp1 = fopen(path1.getCString(), "rb");
     FILE* fp1 = fopen(tmp1, "rb");  
     delete [] tmp1;  
  
     if (fp1 == NULL)     if (fp1 == NULL)
         throw CannotOpenFile(path1);         throw CannotOpenFile(path1);
  
     char* tmp2 = path2.allocateCString();      FILE* fp2 = fopen(path2.getCString(), "rb");
     FILE* fp2 = fopen(tmp2, "rb");  
     delete [] tmp2;  
  
     if (fp2 == NULL)     if (fp2 == NULL)
     {     {
Line 222 
Line 209 
     const String& oldPath,     const String& oldPath,
     const String& newPath)     const String& newPath)
 { {
     ArrayDestroyer<char> p(oldPath.allocateCString());      return System::renameFile(oldPath.getCString(), newPath.getCString());
     ArrayDestroyer<char> q(newPath.allocateCString());  }
     return System::renameFile(p.getPointer(), q.getPointer());  
   Boolean FileSystem::copyFile(
       const String& fromPath,
       const String& toPath)
   {
       return System::copyFile(fromPath.getCString(), toPath.getCString());
 } }
  
 Boolean FileSystem::openNoCase(PEGASUS_STD(ifstream)& is, const String& path) Boolean FileSystem::openNoCase(PEGASUS_STD(ifstream)& is, const String& path)
Line 234 
Line 226 
     if (!existsNoCase(path, realPath))     if (!existsNoCase(path, realPath))
         return false;         return false;
  
     ArrayDestroyer<char> p(_clonePath(path));      is.open(_clonePath(realPath) PEGASUS_IOS_BINARY);
       return !!is;
   }
   
   Boolean FileSystem::openNoCase(
       PEGASUS_STD(fstream)& fs,
       const String& path,
       int mode)
   {
       String realPath;
  
     is.open(p.getPointer() PEGASUS_IOS_BINARY);      if (!existsNoCase(path, realPath))
     return is != 0;          return false;
   
       fs.open(_clonePath(realPath), mode);
       return !!fs;
 } }
  
 Boolean FileSystem::isDirectory(const String& path) Boolean FileSystem::isDirectory(const String& path)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      return System::isDirectory(_clonePath(path));
     return System::isDirectory(p.getPointer());  
 } }
  
 Boolean FileSystem::changeDirectory(const String& path) Boolean FileSystem::changeDirectory(const String& path)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      return System::changeDirectory(_clonePath(path));
     return System::changeDirectory(p.getPointer());  
 } }
  
 Boolean FileSystem::makeDirectory(const String& path) Boolean FileSystem::makeDirectory(const String& path)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      return System::makeDirectory(_clonePath(path));
     return System::makeDirectory(p.getPointer());  
 } }
  
 Boolean FileSystem::removeDirectory(const String& path) Boolean FileSystem::removeDirectory(const String& path)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      return System::removeDirectory(_clonePath(path));
     return System::removeDirectory(p.getPointer());  
 } }
  
 Boolean FileSystem::removeDirectoryHier(const String& path) Boolean FileSystem::removeDirectoryHier(const String& path)
Line 351 
Line 351 
  
 void FileSystem::translateSlashes(String& path) void FileSystem::translateSlashes(String& path)
 { {
     for (Char16* p = (Char16*)path.getData(); *p; p++)      for (Uint32 i = 0; i < path.size(); i++)
     {     {
         if (*p == '\\')          if (path[i] == '\\')
             *p = '/';              path[i] = '/';
       }
     }     }
   
   Boolean GetLine(PEGASUS_STD(istream)& is, String& line)
   {
       line.clear();
   
       Boolean gotChar = false;
       char c;
   
       while (is.get(c))
       {
           gotChar = true;
   
           if (c == '\n')
               break;
   
           line.append(c);
       }
   
       return gotChar;
 } }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.24  
changed lines
  Added in v.1.38

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2