]> www.ginac.de Git - ginac.git/blobdiff - ginac/excompiler.cpp
Happy New Year!
[ginac.git] / ginac / excompiler.cpp
index 68e4a302a70420216411fedf61ad5f25b468e4a6..c54c4659c297d0f242b816c328315134ba1e68ab 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 /*
- *  GiNaC Copyright (C) 1999-2016 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2019 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
 #include "symbol.h"
 
 #ifdef HAVE_LIBDL
-#include <dlfcn.h>
+# include <dlfcn.h>
 #endif // def HAVE_LIBDL
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#else
+# ifdef _MSC_VER
+#  include <io.h>  // for close(3)
+# endif // def _MSC_VER
+#endif // def HAVE_UNISTD_H
+#include <cstdlib>
 #include <fstream>
 #include <ios>
 #include <sstream>
@@ -48,7 +56,7 @@
 namespace GiNaC {
 
 #ifdef HAVE_LIBDL
-       
+
 /**
  * Small class that manages modules opened by libdl. It is used by compile_ex
  * and link_ex in order to have a clean-up of opened modules and their
@@ -112,12 +120,14 @@ public:
                        const char* filename_pattern = "./GiNaCXXXXXX";
                        char* new_filename = new char[strlen(filename_pattern)+1];
                        strcpy(new_filename, filename_pattern);
-                       if (!mktemp(new_filename)) {
+                       int fd = mkstemp(new_filename);
+                       if (fd == -1) {
                                delete[] new_filename;
-                               throw std::runtime_error("mktemp failed");
+                               throw std::runtime_error("mkstemp failed");
                        }
                        filename = std::string(new_filename);
                        ofs.open(new_filename, std::ios::out);
+                       close(fd);
                        delete[] new_filename;
                } else {
                        // use parameter as filename
@@ -155,7 +165,7 @@ public:
        {
                void* module = nullptr;
                module = dlopen(filename.c_str(), RTLD_NOW);
-               if (module == nullptr)  {
+               if (module == nullptr) {
                        throw std::runtime_error("excompiler::link_so_file: could not open compiled module!");
                }