diff --git a/copying.md b/copying.md index ec1ddd2a46..61153fb9cf 100644 --- a/copying.md +++ b/copying.md @@ -156,6 +156,7 @@ _the openage authors_ are: | Nikhil Ghosh | NikhilGhosh75 | nghosh606 à gmail dawt com | | Edvin Lindholm | EdvinLndh | edvinlndh à gmail dawt com | | Jeremiah Morgan | jere8184 | jeremiahmorgan dawt bham à outlook dawt com | +| Tobias Alam | alamt22 | tobiasal à umich dawt edu | If you're a first-time committer, add yourself to the above list. This is not just for legal reasons, but also to keep an overview of all those nicknames. diff --git a/libopenage/util/file.cpp b/libopenage/util/file.cpp index 5aa630d4cc..3d0d4032ac 100644 --- a/libopenage/util/file.cpp +++ b/libopenage/util/file.cpp @@ -16,6 +16,7 @@ #include "util/filelike/python.h" #include "util/path.h" #include "util/strings.h" +#include "util/fslike/directory.h" namespace openage::util { @@ -121,5 +122,14 @@ std::ostream &operator<<(std::ostream &stream, const File &file) { return stream; } +static File get_temp_file() { + fslike::Directory temp_dir = fslike::Directory::get_temp_directory(); + std::string file_name = std::tmpnam(nullptr); + std::ostringstream dir_path; + temp_dir.repr(dir_path); + mode_t mode = 0777; + File file_wrapper = File(dir_path.str() + file_name, mode); + return file_wrapper; +} } // namespace openage::util diff --git a/libopenage/util/file.h b/libopenage/util/file.h index 6724b5f795..44d24b027a 100644 --- a/libopenage/util/file.h +++ b/libopenage/util/file.h @@ -98,9 +98,10 @@ class OAAPI File { void flush(); ssize_t size(); std::vector get_lines(); - std::shared_ptr get_fileobj() const; + static File get_temp_file(); + protected: std::shared_ptr filelike; diff --git a/libopenage/util/fslike/directory.cpp b/libopenage/util/fslike/directory.cpp index 420757f3a6..5695b3fc13 100644 --- a/libopenage/util/fslike/directory.cpp +++ b/libopenage/util/fslike/directory.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -292,4 +293,11 @@ std::ostream &Directory::repr(std::ostream &stream) { return stream; } +static Directory get_temp_directory() { + std::string temp_dir_path = std::filesystem::temp_directory_path() / std::tmpnam(nullptr); + bool create = true; + Directory directory = Directory(temp_dir_path, create); + return directory; +} + } // namespace openage::util::fslike diff --git a/libopenage/util/fslike/directory.h b/libopenage/util/fslike/directory.h index 2872b9554b..9f72d49766 100644 --- a/libopenage/util/fslike/directory.h +++ b/libopenage/util/fslike/directory.h @@ -48,6 +48,8 @@ class Directory : public FSLike { std::ostream &repr(std::ostream &) override; + static Directory get_temp_directory(); + protected: /** * resolve the path to an actually usable one. @@ -59,7 +61,6 @@ class Directory : public FSLike { std::string basepath; }; - } // namespace fslike } // namespace util } // namespace openage diff --git a/libopenage/util/path.cpp b/libopenage/util/path.cpp index ff23253533..e521a4ed9e 100644 --- a/libopenage/util/path.cpp +++ b/libopenage/util/path.cpp @@ -1,4 +1,4 @@ -// Copyright 2015-2023 the openage authors. See copying.md for legal info. +// Copyright 2015-2024 the openage authors. See copying.md for legal info. #include "path.h" diff --git a/libopenage/util/path.h b/libopenage/util/path.h index d16e1734c6..5d4e079812 100644 --- a/libopenage/util/path.h +++ b/libopenage/util/path.h @@ -1,4 +1,4 @@ -// Copyright 2015-2023 the openage authors. See copying.md for legal info. +// Copyright 2015-2024 the openage authors. See copying.md for legal info. #pragma once