-// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// File : Basics_DirUtils.cxx
return file_path;
}
+ std::string GetDirName( const std::string& file_path )
+ {
+ int pos = file_path.rfind( _separator_ );
+ if ( pos >= 0 )
+ return pos < (int)file_path.size()-1 ? file_path.substr(0, pos ) : "";
+ return std::string(".");
+ }
+
std::string GetTmpDirByEnv( const std::string& tmp_path_env )
{
- std::string dir;
char* val = getenv( tmp_path_env.c_str() );
- val ? dir = std::string( val ) : "";
+ std::string dir = val ? val : "";
return GetTmpDirByPath( dir );
}
return true;
}
+ //============================================================================
+ // function : IsWritable
+ // purpose : Returns True(False) if the path is (not) writable
+ //============================================================================
+ bool IsWritable(const std::string& thePath)
+ {
+#ifdef WIN32
+ if ( GetFileAttributes ( thePath.c_str() ) == 0xFFFFFFFF ) {
+ if ( GetLastError () == FILE_ATTRIBUTE_READONLY ) {
+ return false;
+ }
+ }
+#else
+ int status = access(thePath.c_str(),W_OK);
+ if (status != 0) return false;
+#endif
+ return true;
+ }
+
+
//============================================================================
// function : GetDirByPath
// purpose : Returns directory by path and converts it to native system format