From: Arnaud Giersch Date: Wed, 18 Nov 2020 09:53:13 +0000 (+0100) Subject: Define simgrid::xbt::Path::get_tmpdir(). X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/1b0c79654be70819eb6fb89c05d03cf93d644376?hp=993909b72707e2fc73723a3a8d5f308ef0b21fd5 Define simgrid::xbt::Path::get_tmpdir(). --- diff --git a/include/xbt/file.hpp b/include/xbt/file.hpp index afb262290b..fd29ff0eb8 100644 --- a/include/xbt/file.hpp +++ b/include/xbt/file.hpp @@ -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_; }; diff --git a/src/xbt/xbt_os_file.cpp b/src/xbt/xbt_os_file.cpp index 32c7004e05..34caff56c0 100644 --- a/src/xbt/xbt_os_file.cpp +++ b/src/xbt/xbt_os_file.cpp @@ -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"); +}