Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define simgrid::xbt::Path::get_tmpdir().
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 18 Nov 2020 09:53:13 +0000 (10:53 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 27 Nov 2023 08:45:06 +0000 (09:45 +0100)
include/xbt/file.hpp
src/xbt/xbt_os_file.cpp

index afb2622..fd29ff0 100644 (file)
@@ -34,6 +34,9 @@ public:
   /** @brief Returns the file component of a path (reimplementation of POSIX basename) */
   std::string get_base_name() const;
 
+  /** @brief Returns the name of a directory suitable for creating temporary files (e.g. "/tmp") */
+  static Path get_tmpdir();
+
 private:
   std::string path_;
 };
index 32c7004..34caff5 100644 (file)
@@ -93,3 +93,13 @@ std::string simgrid::xbt::Path::get_base_name() const
   std::string p(path_);
   return basename(&p[0]);
 }
+
+simgrid::xbt::Path simgrid::xbt::Path::get_tmpdir()
+{
+  for (const char* name : {"TMPDIR", "TMP", "TEMP", "TEMPDIR"}) {
+    char* val = getenv(name);
+    if (val != nullptr)
+      return Path(val);
+  }
+  return Path("/tmp");
+}