Salome HOME
[bos #40650][CEA 33012] Beta Law distribution: added a new type of distribution for...
[modules/smesh.git] / src / SMESHUtils / SMESH_File.cxx
index e4431ac9a3e92ee71cdebfb00bf6fc1b164696ea..3048b69c4de0b149a420570d78d9af3cd45f2c4d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -81,12 +81,12 @@ bool SMESH_File::open()
   if ( !_map && length > 0 )
   {
 #ifdef WIN32
-#ifdef UNICODE
-         std::wstring aName = Kernel_Utils::utf8_decode_s(_name);
-         const wchar_t* name = aName.c_str();
-#else
-         char* name = name.data();
-#endif
+#  ifdef UNICODE
+    std::wstring  aName = Kernel_Utils::utf8_decode_s(_name);
+    const wchar_t* name = aName.c_str();
+#  else
+    char* name = _name.data();
+#  endif
     _file = CreateFile(name, GENERIC_READ, FILE_SHARE_READ,
                        NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
     bool ok = ( _file != INVALID_HANDLE_VALUE );
@@ -319,14 +319,16 @@ bool SMESH_File::getInts(std::vector<int>& ints)
 
 bool SMESH_File::openForWriting()
 {
+  close();
+
 #ifdef WIN32
 #ifdef UNICODE
-       std::wstring aName = Kernel_Utils::utf8_decode_s(_name);
-       const wchar_t* name = aName.c_str();
+  std::wstring  aName = Kernel_Utils::utf8_decode_s(_name);
+  const wchar_t* name = aName.c_str();
 #else
-       char* name = name.data();
+  char* name = _name.data();
 #endif
-  _file = CreateFile( name,          // name of the write
+  _file = CreateFile( name,                   // name of the write
                       GENERIC_WRITE,          // open for writing
                       0,                      // do not share
                       NULL,                   // default security