]> SALOME platform Git repositories - modules/yacs.git/blobdiff - src/runtime/XMLNode.cxx
Salome HOME
Some tests are modified to work in session less mode.
[modules/yacs.git] / src / runtime / XMLNode.cxx
index 9e18f4c8403c90a1513d239665a57ae98848044a..656f172ed8a74648f4cbea455dfb89f72ededd60 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2006-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2021  CEA/DEN, EDF R&D
 //
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -21,6 +21,7 @@
 #include "XMLPorts.hxx"
 #include "Mutex.hxx"
 #include "TypeCode.hxx"
+#include "AutoLocker.hxx"
 
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#ifdef WNT
+#ifdef WIN32
 #include <windows.h>
 #include <io.h>
 #define chmod _chmod
 #endif
+#ifdef __APPLE__
+#include <unistd.h> // for mkdtemp
+#endif
 
 //#define _DEVDEBUG_
 #include "YacsTrace.hxx"
@@ -91,21 +95,26 @@ void XmlNode::execute()
   DEBTRACE("execute");
   char dir[]="yacsXXXXXX";
   // add a lock around mkdtemp (seems not thread safe)
-  MUTEX.lock();
-#ifdef WNT
-  char mdir [512+1];
-  GetTempPath(MAX_PATH+1, mdir);
-  CreateDirectory(mdir, NULL);
+  {
+    YACS::BASES::AutoLocker<YACS::BASES::Mutex> alck(&MUTEX);
+#ifdef WIN32
+#ifdef UNICODE
+wchar_t mdir[512 + 1];
 #else
-  char* mdir=mkdtemp(dir);
+       char mdir[512 + 1];
 #endif
-  MUTEX.unlock();
-  if(mdir==NULL)
-    {
-      perror("mkdtemp failed");
-      std::cerr << "Problem in mkdtemp " << dir << " " << mdir << std::endl;
-      throw Exception("Execution problem in mkdtemp");
-    }
+    GetTempPath(MAX_PATH+1, mdir);
+    CreateDirectory(mdir, NULL);
+#else
+    char* mdir=mkdtemp(dir);
+#endif
+    if(mdir==NULL)
+      {
+        perror("mkdtemp failed");
+        std::cerr << "Problem in mkdtemp " << dir << " " << mdir << std::endl;
+        throw Exception("Execution problem in mkdtemp");
+      }
+  }
   std::string sdir(dir);
   std::string input=sdir+"/input";
   std::ofstream f(input.c_str());